Class: Move::RiseUp
Constant Summary
EntityConstants::CELL_WIDTH_IN_PIXELS, EntityConstants::MAX_VELOCITY, EntityConstants::PIXEL_WIDTH, EntityConstants::WIDTH
Instance Attribute Summary collapse
-
#distance ⇒ Object
Valid stages: :center, :rise, :reset Distance is how much further we need to go (in pixels) in stage :rise.
-
#stage ⇒ Object
Valid stages: :center, :rise, :reset Distance is how much further we need to go (in pixels) in stage :rise.
Attributes inherited from ComplexMove
#actor_id
Instance Method Summary
collapse
#<=>, #==, as_json, #eql?, from_json, #hash, #to_json
Constructor Details
#initialize(actor = nil) ⇒ RiseUp
Returns a new instance of RiseUp.
13
14
15
16
|
# File 'lib/game_2d/move/rise_up.rb', line 13
def initialize(actor=nil)
super
@stage = :center
end
|
Instance Attribute Details
#distance ⇒ Object
Valid stages: :center, :rise, :reset Distance is how much further we need to go (in pixels) in stage :rise
12
13
14
|
# File 'lib/game_2d/move/rise_up.rb', line 12
def distance
@distance
end
|
#stage ⇒ Object
Valid stages: :center, :rise, :reset Distance is how much further we need to go (in pixels) in stage :rise
12
13
14
|
# File 'lib/game_2d/move/rise_up.rb', line 12
def stage
@stage
end
|
Instance Method Details
#all_state ⇒ Object
59
60
61
|
# File 'lib/game_2d/move/rise_up.rb', line 59
def all_state
super.push @stage, @distance
end
|
#as_json ⇒ Object
62
63
64
65
|
# File 'lib/game_2d/move/rise_up.rb', line 62
def as_json
super.merge! :stage => @stage,
:distance => @distance
end
|
#on_completion(actor) ⇒ Object
18
19
20
|
# 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 ⇒ Object
71
72
73
|
# File 'lib/game_2d/move/rise_up.rb', line 71
def to_s
"RiseUp[#{stage}, #{distance} to go]"
end
|
#update(actor) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/game_2d/move/rise_up.rb', line 22
def update(actor)
actor.instance_exec(self) do |cm|
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
return false if cm.stage == :reset
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
return move
when :rise
return false if cm.distance.zero?
cm.distance -= 1
move || (cm.stage = :reset)
return true
end
end
end
|
#update_from_json(json) ⇒ Object
66
67
68
69
70
|
# File 'lib/game_2d/move/rise_up.rb', line 66
def update_from_json(json)
self.stage = json[:stage].to_sym
self.distance = json[:distance]
super
end
|