Game Development Reference
In-Depth Information
How to do it...
We will start by making some updates to the GameCharacterControl class. For the
GameCharacterControl class, we introduce two new variables, cooldownTime
and cooldown :
1. The first is the time between shots.
2. The second is the current countdown until the character can fire again. We need to
add a getter for cooldown and the value itself is set in the following onFire
method:
public void onFire(){
cooldown = cooldownTime;
}
3. Lastly, in the update method, we need to subtract cooldown by tpf if it's more
than zero.
In InputAppState , we also have to make some changes:
1. We begin by introducing a List<Geometry> called targets . This is the list
of things the fired rays will check for collisions against. In the addInputMap-
ping method, add another mapping for Fire . A suitable button is the left mouse
button. This is implemented as follows:
inputManager.addMapping(InputMapping.Fire.name(), new
MouseButtonTrigger(MouseInput.BUTTON_LEFT));
2. In the onAction method, change the logic slightly. We add a new check for the
fire action and we put the existing logic inside the else clause. We're telling
character to handle all actions, except when we fire. This is implemented as
follows:
if (name.equals("Fire")) {
if (isPressed && character.getCooldown() == 0f){
fire();
}
} else {
Search WWH ::




Custom Search