Hi, Im trying to make an "EnergyDrink" to my game which adds speed to the Person, when the Person drinks the EnergyDrink, I want the speed added to the Person temporary only, or just for only 15 seconds, I tried to create a timer, but Im not really good with timers so I need help how to set the speed added for only 15 seconds, here's my initial code :
public class Person extends MainActors
{
public int speed = 2;
private int timer;
public void act()
{
drink();
}
public void drink()
{
Actor energydrink = getOneIntersectingObject(EnergyDrink.class);
if (energydrink!= null)
{
speed++;
World myWorld = getWorld();
MyWorld myworld = (MyWorld)myWorld;
HealthBar healthbar = myworld.getHealthBar();
healthbar.gainHealth();
myWorld.removeObject(energydrink);
}
if (timer>0)
{
timer--;
if(timer == 0) speed--;
}
}
}
