Class: Cursor
- Inherits:
-
Object
- Object
- Cursor
- Defined in:
- lib/cursor.rb
Instance Attribute Summary collapse
-
#freeroam ⇒ Object
Returns the value of attribute freeroam.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #draw ⇒ Object
-
#info ⇒ Object
Find some info about unit in current tile.
-
#initialize(x, y, map, infopane) ⇒ Cursor
constructor
A new instance of Cursor.
-
#switch_freeroam ⇒ Object
Switch between being attached to unit and being able to freeroam.
- #update(key) ⇒ Object
-
#warp(x, y) ⇒ Object
Move to given coordinates.
Constructor Details
#initialize(x, y, map, infopane) ⇒ Cursor
Returns a new instance of Cursor.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cursor.rb', line 4 def initialize(x, y, map, infopane) dir_path = File.dirname(__FILE__) @x = x @y = y @map = map @infopane = infopane @image = Gosu::Image.new(dir_path + '/media/cursor.png') @freeroam = false end |
Instance Attribute Details
#freeroam ⇒ Object
Returns the value of attribute freeroam.
2 3 4 |
# File 'lib/cursor.rb', line 2 def freeroam @freeroam end |
#x ⇒ Object
Returns the value of attribute x.
2 3 4 |
# File 'lib/cursor.rb', line 2 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
2 3 4 |
# File 'lib/cursor.rb', line 2 def y @y end |
Instance Method Details
#draw ⇒ Object
66 67 68 |
# File 'lib/cursor.rb', line 66 def draw @image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZCURSOR) end |
#info ⇒ Object
Find some info about unit in current tile
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cursor.rb', line 89 def info uu = @map.get_unit(@x, @y) if uu @infopane.text = uu.info puts uu.info else @infopane.text = '' puts 'nothing here' end end |
#switch_freeroam ⇒ Object
Switch between being attached to unit and being able to freeroam
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cursor.rb', line 77 def switch_freeroam if freeroam == true @infopane.text = 'freeroam disabled' puts 'freeroam disabled' else @infopane.text = 'freeroam enabled' puts 'freeroam enabled' end @freeroam = !@freeroam end |
#update(key) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cursor.rb', line 16 def update(key) case key # Cardinal directions when Gosu::KbLeft, Gosu::KbA then @x -= 1 unless @x <= 0 when Gosu::KbRight, Gosu::KbD then @x += 1 unless @x >= MAPX when Gosu::KbUp, Gosu::KbW then @y -= 1 unless @y <= 0 when Gosu::KbDown, Gosu::KbX then @y += 1 unless @y >= MAPY # Intercardinal directions when Gosu::KbQ then unless @x <= 0 || @y <= 0 @x -= 1 @y -= 1 end when Gosu::KbE then unless @x >= MAPX || @y <= 0 @x += 1 @y -= 1 end when Gosu::KbZ then unless @x <= 0 || @y >= MAPY @x -= 1 @y += 1 end when Gosu::KbC then unless @x >= MAPX || @y >= MAPY @x += 1 @y += 1 end # Functions when Gosu::KbS then uu = @map.get_unit(@x, @y) if uu then uu.set_function(FUNCSENTRY) end when Gosu::KbB then uu = @map.get_unit(@x, @y) if uu then uu.set_function(FUNCBUILD) end when Gosu::KbN then uu = @map.get_unit(@x, @y) if uu then uu.set_function(FUNCNONE) end when Gosu::KbReturn then info end end |
#warp(x, y) ⇒ Object
Move to given coordinates
71 72 73 74 |
# File 'lib/cursor.rb', line 71 def warp(x, y) @x = x @y = y end |