class Entity::Ghost

Constants

MOVES_FOR_KEY_HELD

Public Class Methods

new(player_name = "<unknown>") click to toggle source
Calls superclass method Entity::new
# File lib/game_2d/entity/ghost.rb, line 27
def initialize(player_name = "<unknown>")
  super
  initialize_player
  @player_name = player_name
  @score = 0
end

Public Instance Methods

all_state() click to toggle source
Calls superclass method Entity#all_state
# File lib/game_2d/entity/ghost.rb, line 98
def all_state
  # Player name goes first, so we can sort on that
  super.unshift(player_name).push(score, @complex_move)
end
as_json() click to toggle source
Calls superclass method Entity#as_json
# File lib/game_2d/entity/ghost.rb, line 103
def as_json
  super.merge!(
    :player_name => player_name,
    :score => score,
    :complex_move => @complex_move.as_json
  )
end
down() click to toggle source
# File lib/game_2d/entity/ghost.rb, line 63
def down; accelerate(0, 1); end
draw_image(anim) click to toggle source
# File lib/game_2d/entity/ghost.rb, line 120
def draw_image(anim)
  # Usually frame 0, occasionally frame 1
  anim[((Gosu::milliseconds / 100) % 63) / 62]
end
generate_move_from_click(x, y) click to toggle source

Called by GameWindow Should return the move to be sent via ClientConnection (or nil)

# File lib/game_2d/entity/ghost.rb, line 94
def generate_move_from_click(x, y)
  [:spawn, {:x => x, :y => y}]
end
image_filename() click to toggle source
# File lib/game_2d/entity/ghost.rb, line 118
def image_filename; "ghost.png"; end
left() click to toggle source
# File lib/game_2d/entity/ghost.rb, line 60
def left; accelerate(-1, 0); end
move_for_keypress(keypress) click to toggle source

Called by GameWindow Should return the move to be sent via ClientConnection (or nil) This is for queued keypresses, i.e. those that happen on key-down only (just once for a press), not continuously for as long as held down

# File lib/game_2d/entity/ghost.rb, line 89
def move_for_keypress(keypress); nil; end
moves_for_key_held() click to toggle source

Called by GameWindow Should return a map where the keys are… keys, and the values are the corresponding moves to be sent via ClientConnection This is for non-queued keypresses, i.e. those that happen continuously for as long as held down

# File lib/game_2d/entity/ghost.rb, line 79
def moves_for_key_held
  MOVES_FOR_KEY_HELD
end
right() click to toggle source
# File lib/game_2d/entity/ghost.rb, line 61
def right; accelerate(1, 0); end
should_fall?() click to toggle source
# File lib/game_2d/entity/ghost.rb, line 36
def should_fall?; false; end
sleep_now?() click to toggle source
# File lib/game_2d/entity/ghost.rb, line 34
def sleep_now?; false; end
spawn(x, y) click to toggle source
# File lib/game_2d/entity/ghost.rb, line 65
def spawn(x, y)
  if base = @space.available_base_near(x, y)
    warn "#{self} spawning at #{base.x}, #{base.y}"
    self.complex_move = Move::Spawn.new
    self.complex_move.target_id = base.registry_id
  end
end
teleportable?() click to toggle source
# File lib/game_2d/entity/ghost.rb, line 38
def teleportable?; false; end
up() click to toggle source
# File lib/game_2d/entity/ghost.rb, line 62
def up; accelerate(0, -1); end
update() click to toggle source
Calls superclass method Entity#update
# File lib/game_2d/entity/ghost.rb, line 40
def update
  fail "No space set for #{self}" unless @space

  return if perform_complex_move

  if args = next_move
    case (current_move = args.delete(:move).to_sym)
      when :left, :right, :up, :down
        send current_move
      when :spawn
        spawn args[:x], args[:y]
      else
        puts "Invalid move for #{self}: #{current_move}, #{args.inspect}"
    end
  else
    slow_by 1
  end
  super
end
update_from_json(json) click to toggle source
Calls superclass method Entity#update_from_json
# File lib/game_2d/entity/ghost.rb, line 111
def update_from_json(json)
  @player_name = json[:player_name] if json[:player_name]
  @score = json[:score] if json[:score]
  @complex_move = Serializable.from_json(json[:complex_move]) if json[:complex_move]
  super
end