Game Development Reference
In-Depth Information
This is it, we are ready to deal damage. But we want to see if we actually killed somebody,
so TankGraphics should be aware of health and should draw different set of sprites
when tank is dead. Here is what we need to change in our current TankGraphics to achieve
the result:
class TankGraphics < Component
# ...
def initialize (game_object)
super (game_object)
@body_normal = units . frame( 'tank1_body.png' )
@shadow_normal = units . frame( 'tank1_body_shadow.png' )
@gun_normal = units . frame( 'tank1_dualgun.png' )
@body_dead = units . frame( 'tank1_body_destroyed.png' )
@shadow_dead = units . frame( 'tank1_body_destroyed_shadow.png' )
@gun_dead = nil
end
def update
if object . health . dead?
@body = @body_dead
@gun = @gun_dead
@shadow = @shadow_dead
else
@body = @body_normal
@gun = @gun_normal
@shadow = @shadow_normal
end
end
def draw (viewport)
@shadow . draw_rot(x - 1 , y - 1 , 0 , object . direction)
@body . draw_rot(x, y, 1 , object . direction)
@gun . draw_rot(x, y, 2 , object . gun_angle) if @gun
end
# ...
end
Now we can blow them up and enjoy the view:
Search WWH ::




Custom Search