Game Development Reference
In-Depth Information
35 changed
36 end
37
38 def damage_dealt
39 @damage_dealt . round
40 end
41
42 def to_s
43
"[kills: #{ @kills } , " \
"deaths: #{ @deaths } , " \
44
"shots: #{ @shots } , " \
45
"damage: #{ damage } , " \
46
"damage_dealt: #{ damage_dealt } ]"
47
48 end
49
50
private
51
52 def changed
53 @changed_at = Gosu . milliseconds
54 end
55 end
While building the HUD , we established that Stats should belong to Tank#input ,
because it defines who is controlling the tank. So, every instance of PlayerInput and
AiInput has to have it's own Stats :
# 12-stats/entities/components/player_input.rb
class PlayerInput < Component
# ...
attr_reader :stats
def initialize ( name , camera, object_pool)
# ...
@stats = Stats . new( name )
end
# ...
def on_damage (amount)
@stats . add_damage(amount)
end
# ...
end
# 12-stats/entities/components/ai_input.rb
class AiInput < Component
# ...
Search WWH ::




Custom Search