class Move::Spawn
A move for ghosts.
Constants
- SPAWN_TRAVEL_SPEED
Attributes
target_id[RW]
target_id
is registry_id of selected base
Public Instance Methods
all_state()
click to toggle source
Calls superclass method
ComplexMove#all_state
# File lib/game_2d/move/spawn.rb, line 52 def all_state super.push @target_id end
as_json()
click to toggle source
Calls superclass method
ComplexMove#as_json
# File lib/game_2d/move/spawn.rb, line 55 def as_json super.merge! :target => @target_id end
on_completion(actor)
click to toggle source
# File lib/game_2d/move/spawn.rb, line 17 def on_completion(actor) space = actor.space target = space[target_id] return unless target && target.available? gecko = Entity::Gecko.new(actor.player_name) gecko.score = actor.score gecko.x, gecko.y, gecko.a = target.x, target.y, target.a return unless space << gecko actor.replace_player_entity(gecko) end
to_s()
click to toggle source
# File lib/game_2d/move/spawn.rb, line 62 def to_s "Spawn[#{target_id}]" end
update(actor)
click to toggle source
# File lib/game_2d/move/spawn.rb, line 30 def update(actor) # It's convenient to set 'self' to the Player # object, here actor.instance_exec(self) do |cm| # Abort if the target gets destroyed, or becomes # occupied target = space[cm.target_id] return false unless target && target.available? # We're done if x == target.x && y == target.y @x_vel = @y_vel = 0 return false end @x_vel = [[target.x - x, -SPAWN_TRAVEL_SPEED].max, SPAWN_TRAVEL_SPEED].min @y_vel = [[target.y - y, -SPAWN_TRAVEL_SPEED].max, SPAWN_TRAVEL_SPEED].min # move returns false: it failed somehow return move end end
update_from_json(json)
click to toggle source
Calls superclass method
ComplexMove#update_from_json
# File lib/game_2d/move/spawn.rb, line 58 def update_from_json(json) self.target_id = json[:target].to_sym if json[:target] super end