Class: Player

Inherits:
Tile
  • Object
show all
Defined in:
lib/ruby-ai/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Tile

#[], #inspect

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

#movedObject

Returns the value of attribute moved.



7
8
9
# File 'lib/ruby-ai/player.rb', line 7

def moved
  @moved
end

#pauseObject

Returns the value of attribute pause.



6
7
8
# File 'lib/ruby-ai/player.rb', line 6

def pause
  @pause
end

#stopObject

Returns the value of attribute stop.



6
7
8
# File 'lib/ruby-ai/player.rb', line 6

def stop
  @stop
end

#xObject (readonly)

Returns the value of attribute x.



7
8
9
# File 'lib/ruby-ai/player.rb', line 7

def x
  @x
end

#yObject (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