Class: Move::Spawn
Overview
Constant Summary
collapse
- SPAWN_TRAVEL_SPEED =
80
EntityConstants::CELL_WIDTH_IN_PIXELS, EntityConstants::MAX_VELOCITY, EntityConstants::PIXEL_WIDTH, EntityConstants::WIDTH
Instance Attribute Summary collapse
Attributes inherited from ComplexMove
#actor_id
Instance Method Summary
collapse
Methods inherited from ComplexMove
#initialize
#<=>, #==, as_json, #eql?, from_json, #hash, #to_json
Constructor Details
This class inherits a constructor from ComplexMove
Instance Attribute Details
#target_id ⇒ Object
target_id is registry_id of selected base
15
16
17
|
# File 'lib/game_2d/move/spawn.rb', line 15
def target_id
@target_id
end
|
Instance Method Details
#all_state ⇒ Object
52
53
54
|
# File 'lib/game_2d/move/spawn.rb', line 52
def all_state
super.push @target_id
end
|
#as_json ⇒ Object
55
56
57
|
# File 'lib/game_2d/move/spawn.rb', line 55
def as_json
super.merge! :target => @target_id
end
|
#on_completion(actor) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
|
# 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 ⇒ Object
62
63
64
|
# File 'lib/game_2d/move/spawn.rb', line 62
def to_s
"Spawn[#{target_id}]"
end
|
#update(actor) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/game_2d/move/spawn.rb', line 30
def update(actor)
actor.instance_exec(self) do |cm|
target = space[cm.target_id]
return false unless target && target.available?
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
return move
end
end
|
#update_from_json(json) ⇒ Object
58
59
60
61
|
# 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
|