This site requires JavaScript, please enable it in your browser!
Greenfoot back
apcandre
apcandre wrote ...

2016/9/1

Invincibility for 5 seconds

apcandre apcandre

2016/9/1

#
What codes do I use to make my car invincible for 5 seconds if my car grabbed another object in other words it's a powerup. Thank you in advance for your help :)
Super_Hippo Super_Hippo

2016/9/1

#
private int t_invincible = 0;

//in act method
if (t_invincible > 0) t_invincible--;

//getting the powerup
if (isTouching(PowerUp.class))
{
    removeTouching(PowerUp.class);
    t_invincible = 280;
}

//when checking for a crash
if (t_invincible==0 && isTouching(/*whatever*/.class))
{
    //action when crash is detected
}
You need to login to post a reply.