Game Development Reference
In-Depth Information
11
end
12
end
This time we have to implement
Health#increase
, but it is pretty simple:
class
Health
<
Component
# ...
def
increase
(amount)
@health
= [
@health
+ 25
,
@initial_health
* 2].
min
@health_updated
=
true
end
# ...
end
Since
Tank
has
@initial_health
equal to 100, increasing health won't go over 200,
which is exactly what we want.
Implementing Fire Rate Boost
How about boosting tank's fire rate?
11-powerups/entities/powerups/fire_rate_powerup.rb
1
class
FireRatePowerup
<
Powerup
2
def
pickup
(object)
3
if
object
.
class
==
Tank
4
if
object
.
fire_rate_modifier
< 2
5
object
.
fire_rate_modifier
+= 0.25
6
end
7
true
8
end
9
end
10
11
def
graphics
12
:straight_gun
13
end
14
end
We need to introduce
@fire_rate_modifier
in
Tank
class and use it when calling
Tank#can_shoot?
:
class
Tank
<
GameObject
# ...