Game Development Reference
In-Depth Information
Implementing Health And Damage
I know you have been waiting for this. We will be implementing health system and most
importantly, damage. Soo we will be ready to blow things up.
To implement this, we need to:
1.
Add
TankHealth
component. Start with 100 health.
2.
Render tank health next to tank itself.
3.
Inflict damage to tank when it is in explosion zone
4.
Render different sprite for dead tank.
5.
Cut off player input when tank is dead.
Adding Health Component
If we didn't have
Component
system in place, it would be way more difficult. Now we just
kick in a new class:
07-damage/entities/components/tank_health.rb
1
class
TankHealth
<
Component
2
attr_accessor
:health
3
4
def
initialize
(object, object_pool)
5
super
(object)
6
@object_pool
=
object_pool
7
@health
= 100
8
@health_updated
=
true
9
@last_damage
=
Gosu
.
milliseconds
10
end
11
12
def
update
13
update_image
14
end
15
16
def
update_image
17
if
@health_updated
18
if
dead?
19
text
=
'
✝
'
font_size
= 25
20