module Player
The base module representing what all Players have in common Moves can be enqueued by calling add_move
The server instantiates classes that mix in this module, to represent each connected player
Attributes
complex_move[RW]
player_name[RW]
score[RW]
Public Instance Methods
add_move(new_move)
click to toggle source
Accepts a hash, with a key :move => move_type
# File lib/game_2d/player.rb, line 33 def add_move(new_move) return unless new_move @moves << new_move end
die()
click to toggle source
# File lib/game_2d/player.rb, line 49 def die ghost = Entity::Ghost.new(player_name) ghost.x, ghost.y, ghost.a, ghost.x_vel, ghost.y_vel, ghost.score = x, y, 0, x_vel, y_vel, score return unless space << ghost # coast to coast replace_player_entity ghost end
draw(window)
click to toggle source
Calls superclass method
# File lib/game_2d/player.rb, line 60 def draw(window) super window.font.draw_rel(player_name, pixel_x + CELL_WIDTH_IN_PIXELS / 2, pixel_y, ZOrder::Text, 0.5, 1.0, # Centered X; above Y 1.0, 1.0, Gosu::Color::YELLOW) end
draw_zorder()
click to toggle source
# File lib/game_2d/player.rb, line 58 def draw_zorder; ZOrder::Player end
initialize_player()
click to toggle source
# File lib/game_2d/player.rb, line 14 def initialize_player @moves = [] @complex_move = nil end
next_move()
click to toggle source
# File lib/game_2d/player.rb, line 38 def next_move; @moves.shift; end
perform_complex_move()
click to toggle source
Returns true if a complex move is in process, and took some action Returns nil if the complex move completed, or there isn’t one
# File lib/game_2d/player.rb, line 22 def perform_complex_move return unless @complex_move # returns true if more work to do return true if @complex_move.update(self) @complex_move.on_completion(self) @complex_move = nil end
replace_player_entity(new_entity)
click to toggle source
# File lib/game_2d/player.rb, line 40 def replace_player_entity(new_entity) if (game = space.game).is_a? GameClient game.player_id = new_entity.registry_id if game.player_id == registry_id else game.replace_player_entity(player_name, new_entity.registry_id) end space.doom(self) end
to_s()
click to toggle source
# File lib/game_2d/player.rb, line 68 def to_s "#{player_name} (#{self.class.name} #{registry_id_safe}) at #{x}x#{y}" end