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

2017/12/17

Need help with enemy self-stunning (like getting tired)

1
2
danpost danpost

2017/12/26

#
Things I immediately spot are (1) you decremnent 'stunTimer' in both lines 4 and in line 5; and (2) the random time in line 5 will actually be averaging about 10 seconds. It might be easier to just set a random time to begin with, rather than choosing a random moment. What I mean is that instead of continuously asking if a random value is zero to start the stun state, just set a random amount of time that the not stunned state is to last. Since there are two states, not stunned and stunned, the value of 'stunTimer' being positive or negative will suffice:
  public void act() 
{
    if (--stunTimer == -5*55) stunTimer = 10*55+Greenfoot.getRandomNumber(10*55);
    if (stunTimer > 0) move();
    Actor tezeu = getOneIntersectingObject(Tezeu.class);
    if (tezeu != null)  getWorld().removeObject( stunTimer<0 ? this : tezeu);
}
Super_Hippo Super_Hippo

2017/12/28

#
Also change
stunTimer<0 ? this : tezeu
to
stunTImer>0 ? tezeu : this
or it will be wrong at 0. I messed this up last time.
iminblue iminblue

2017/12/29

#
It still doesn't work guys ...
danpost danpost

2017/12/29

#
iminblue wrote...
It still doesn't work guys ...
It might help if you show what you tried instead of just saying it does not work.
xbLank xbLank

2017/12/29

#
danpost wrote...
iminblue wrote...
It still doesn't work guys ...
It might help if you show what you tried instead of just saying it does not work.
^
iminblue iminblue

2018/1/2

#
danpost wrote...
It might help if you show what you tried instead of just saying it does not work.
Actually is does work but the level starts with the Minotaur being stunned . Can I initialize the stunTimer with the GreenfootRandomNumber-thing before public void act?
iminblue iminblue

2018/1/2

#
iminblue wrote...
Actually is does work but the level starts with the Minotaur being stunned . Can I initialize the stunTimer with the GreenfootRandomNumber-thing before public void act?
Oh nevermind I made it work. Thank you very much guys for helping me with this one I appreciate it . Have a good day !
You need to login to post a reply.
1
2