class RubyMan::Player
player (RubyMan
) object
Public Instance Methods
change_direction(direction)
click to toggle source
Calls superclass method
RubyMan::MovingObject#change_direction
# File lib/ruby_man/GameObjects/player.rb, line 81 def change_direction(direction) dir_x = @grid_x + direction.rel_x dir_y = @grid_y + direction.rel_y @game.objects_at(dir_x, dir_y).each do |obj| return if obj.solid || obj.is_a?(Door) end super end
collision(obj)
click to toggle source
# File lib/ruby_man/GameObjects/player.rb, line 48 def collision(obj) return unless obj.is_a?(Ghost) return unless distance_to(obj) <= 16 if obj.scared? obj.die else die end end
created()
click to toggle source
# File lib/ruby_man/GameObjects/player.rb, line 10 def created self.sprite = Sprite['rubyman'] @image_speed = 3 @next_direction = Direction.none @speed = 3 @is_dead = false @game.player = self end
dead()
click to toggle source
# File lib/ruby_man/GameObjects/player.rb, line 64 def dead if @game.lives > 0 @game.lives -= 1 @game.restart else @game.game_over end end
die()
click to toggle source
# File lib/ruby_man/GameObjects/player.rb, line 58 def die ResourceManager['sfx_death'].play @game.pause(2000) @is_dead = true end
direction_free(direction)
click to toggle source
# File lib/ruby_man/GameObjects/player.rb, line 39 def direction_free(direction) x = @grid_x + direction.rel_x y = @grid_y + direction.rel_y @game.objects_at(x, y).each do |obj| return false if obj.solid || obj.is_a?(Door) end true end
eat_food()
click to toggle source
# File lib/ruby_man/GameObjects/player.rb, line 73 def eat_food @game.objects_at(@grid_x, @grid_y).each do |obj| next unless obj.is_a?(Food) obj.destroy @game.score += 10 end end
grid_step()
click to toggle source
# File lib/ruby_man/GameObjects/player.rb, line 33 def grid_step eat_food change_direction(@next_direction) @direction = Direction.none unless direction_free(@direction) end
update(delta)
click to toggle source
Calls superclass method
RubyMan::MovingObject#update
# File lib/ruby_man/GameObjects/player.rb, line 28 def update(delta) dead if @is_dead super end