Class: Player
Instance Attribute Summary collapse
-
#moved ⇒ Object
readonly
Returns the value of attribute moved.
-
#pause ⇒ Object
Returns the value of attribute pause.
-
#stop ⇒ Object
Returns the value of attribute stop.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(window, coords) ⇒ Player
constructor
A new instance of Player.
- #look(dir = nil, num = 1) ⇒ Object
- #move(dir) ⇒ Object
Methods inherited from Tile
Constructor Details
#initialize(window, coords) ⇒ Player
Returns a new instance of Player.
9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby-ai/player.rb', line 9 def initialize(window, coords) @image = Gosu::Image.new(window, "#{LIB}/ruby-ai/media/tiny-orange.png", false) @tiles = window.tiles @x = coords[:x] @y = coords[:y] @moved = false @pause = true @stop = false end |
Instance Attribute Details
#moved ⇒ Object
Returns the value of attribute moved.
7 8 9 |
# File 'lib/ruby-ai/player.rb', line 7 def moved @moved end |
#pause ⇒ Object
Returns the value of attribute pause.
6 7 8 |
# File 'lib/ruby-ai/player.rb', line 6 def pause @pause end |
#stop ⇒ Object
Returns the value of attribute stop.
6 7 8 |
# File 'lib/ruby-ai/player.rb', line 6 def stop @stop end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
7 8 9 |
# File 'lib/ruby-ai/player.rb', line 7 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
7 8 9 |
# File 'lib/ruby-ai/player.rb', line 7 def y @y end |
Instance Method Details
#look(dir = nil, num = 1) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/ruby-ai/player.rb', line 19 def look(dir=nil, num=1) return @tiles.find {|t| t.x == x && t.y == y} unless dir at = send(dir, num) tile = @tiles.find do |tile| tile.x == at[:x] && tile.y == at[:y] end tile end |
#move(dir) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby-ai/player.rb', line 28 def move(dir) if moved? || hit_wall?(dir) @stop = true return end to = send(dir) @x = to[:x] @y = to[:y] myputs "Moved #{dir}." end |