class Move::RiseUp
Attributes
distance[RW]
Valid stages: :center, :rise, :reset Distance is how much further we need to go (in pixels) in stage :rise
stage[RW]
Valid stages: :center, :rise, :reset Distance is how much further we need to go (in pixels) in stage :rise
Public Class Methods
new(actor=nil)
click to toggle source
Calls superclass method
ComplexMove::new
# File lib/game_2d/move/rise_up.rb, line 13 def initialize(actor=nil) super @stage = :center end
Public Instance Methods
all_state()
click to toggle source
Calls superclass method
ComplexMove#all_state
# File lib/game_2d/move/rise_up.rb, line 59 def all_state super.push @stage, @distance end
as_json()
click to toggle source
Calls superclass method
ComplexMove#as_json
# File lib/game_2d/move/rise_up.rb, line 62 def as_json super.merge! :stage => @stage, :distance => @distance end
on_completion(actor)
click to toggle source
# File lib/game_2d/move/rise_up.rb, line 18 def on_completion(actor) actor.instance_exec { @x_vel = @y_vel = 0 } end
to_s()
click to toggle source
# File lib/game_2d/move/rise_up.rb, line 71 def to_s "RiseUp[#{stage}, #{distance} to go]" end
update(actor)
click to toggle source
# File lib/game_2d/move/rise_up.rb, line 22 def update(actor) # It's convenient to set 'self' to the Player # object, here actor.instance_exec(self) do |cm| # Abort if the build_block gets destroyed blok = build_block return false unless blok start_x, start_y = blok.x, blok.y case cm.stage when :center, :reset if x == start_x && y == start_y # If we're in reset, we're all done return false if cm.stage == :reset # Establish our velocity for :rise cm.stage = :rise @x_vel, @y_vel = angle_to_vector(a, PIXEL_WIDTH) cm.distance = CELL_WIDTH_IN_PIXELS return cm.update(self) end @x_vel = [[start_x - x, -PIXEL_WIDTH].max, PIXEL_WIDTH].min @y_vel = [[start_y - y, -PIXEL_WIDTH].max, PIXEL_WIDTH].min # move returns false: it failed somehow return move when :rise # Success return false if cm.distance.zero? cm.distance -= 1 # move fails? Go to :reset move || (cm.stage = :reset) return true end end end
update_from_json(json)
click to toggle source
Calls superclass method
ComplexMove#update_from_json
# File lib/game_2d/move/rise_up.rb, line 66 def update_from_json(json) self.stage = json[:stage].to_sym if json[:stage] self.distance = json[:distance] if json[:distance] super end