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

2022/5/13

i need help i new progamming

sares97 sares97

2022/5/13

#
I need a code so that when a policeman collides with a coin he can create a temporary stun effect on enemies. I'm new to programming and thanks in advance.
danpost danpost

2022/5/13

#
sares97 wrote...
I need a code so that when a policeman collides with a coin he can create a temporary stun effect on enemies. I'm new to programming and thanks in advance.
Try the following field in your MyWorld class (or your game world class):
public static int stunTimer = 0;
with the following line in your MyWorld constructor block:
stunTimer = 0;
and the following in your MyWorld act method:
if (stunTimer > 0) stunTimer--;
Then when policeman collides with coin, set the field to some positive value -- 60 units per second of stun:
MyWorld.stunTimer = 180: // for 3 seconds of stun time
Finally, start the act method of enemy with the following line:
if (MyWorld.stunTimer > 0) return
You need to login to post a reply.