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

2022/5/9

l need help

track-hunt79 track-hunt79

2022/5/9

#
I need help with a code so that when a character picks up a coin it has a stund effect on enemies specifically zombies I would really like help
danpost danpost

2022/5/9

#
track-hunt79 wrote...
I need help with a code so that when a character picks up a coin it has a stund effect on enemies specifically zombies I would really like help
Add a method to zombie class to give them the capability (behaviour) of being stunned. An int field will be needed to time the effect. It would look like this:
public int stunTimer = 0;

public void act()
{
    if (stunTimer > 0 && --stunTimer > 0) return;
    // current code in act method here
}
As player picks up coin, do the following:
for (Object obj : getWorld().getObjects(Zombie.class))
{
    ((Zombie)obj).stunTimer = 300; // 5-seconds of stun time (approx. 60 acts per second)
}
Please note that any zombies added to the world during stun session will not be stunned.
track-hunt79 track-hunt79

2022/5/9

#
THANKS but what do you mean that the zombies will not be stunned during the session?
danpost danpost

2022/5/9

#
track-hunt79 wrote...
THANKS but what do you mean that the zombies will not be stunned during the session?
Only zombies currently in the world when the coin is picked up will be stunned. While zombies are stunned, if a new zombie is added to the world, it will not be.
track-hunt79 track-hunt79

2022/5/9

#
oh I understand and excuse me again but I'm new to programming and the code you sent me is placed in the obj class?
danpost danpost

2022/5/9

#
track-hunt79 wrote...
oh I understand and excuse me again but I'm new to programming and the code you sent me is placed in the obj class?
No. First part in class of zombie and second part in class of character that picks up coin. "obj" is just a dummy variable name to hold a zombie object.
You need to login to post a reply.