Game Development Reference
In-Depth Information
@names . random, @object_pool ))
end
end
# ...
end
When tank dies, we want it to stay dead for 5 seconds and then respawn in one of our
predefined spawn points. We will achieve that by adding respawn method and calling it
in PlayerInput#update and AiInput#update if tank is dead.
# 09-polishing/entities/components/player_input.rb
class PlayerInput < Component
# ...
def update
return respawn if object . health . dead?
# ...
end
# ...
private
def respawn
if object . health . should_respawn?
object . health . restore
object . x, object . y = @object_pool . map . spawn_point
@camera . x, @camera . y = x, y
PlayerSounds . respawn(object, @camera )
end
end
# ...
end
# 09-polishing/entities/components/ai_input.rb
class AiInput < Component
# ...
def update
return respawn if object . health . dead?
# ...
end
# ...
private
def respawn
if object . health . should_respawn?
object . health . restore
object . x, object . y = @object_pool . map . spawn_point
Search WWH ::




Custom Search