Game Development Reference
In-Depth Information
14
end
15
end
Implementing Repair Damage Powerup
Repairing broken tank is probably the most important powerup of them all, so let's
implement it first:
11-powerups/entities/powerups/repair_powerup.rb
1
class
RepairPowerup
<
Powerup
2
def
pickup
(object)
3
if
object
.
class
==
Tank
4
if
object
.
health
.
health
< 100
5
object
.
health
.
restore
6
end
7
true
8
end
9
end
10
11
def
graphics
12
:repair
13
end
14
end
This was incredibly simple.
Health#restore
already existed since we had to respawn
our tanks. We can only hope other powerups are as simple to implement as this one.
Implementing Health Boost
Repairing damage is great, but how about boosting some extra health for upcoming battles?
Health boost to the rescue:
11-powerups/entities/powerups/health_powerup.rb
1
class
HealthPowerup
<
Powerup
2
def
pickup
(object)
3
if
object
.
class
==
Tank
4
object
.
health
.
increase(
25
)
5
true
6
end
7
end
8
9
def
graphics
10
:life_up