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

2013/5/7

Firing

1
2
Hawx_ Hawx_

2013/5/7

#
How do I code it so that an AI can only fire once every 10 seconds? I just need the bit which means that it can only fire once every so often. Thanks
JetLennit JetLennit

2013/5/7

#
What is the speed of the scenario?
Hawx_ Hawx_

2013/5/7

#
what do you mean?
JetLennit JetLennit

2013/5/7

#
There is a little thing at the bottom of the window with the game, where is the little speed pointer on the speed bar
JetLennit JetLennit

2013/5/7

#
Is it for this?
Hawx_ Hawx_

2013/5/7

#
yeah
Hawx_ Hawx_

2013/5/7

#
standard , normal setting , in the middle
Hawx_ Hawx_

2013/5/7

#
any ideas?
danpost danpost

2013/5/7

#
You just need an instance delay-timer field in the class that fires the projectile. In the constructor of that class set the value of the delay-timer to some random number between 0 and 600 (600 frames is about 10 seconds at normal scenario speed). Adding a random value here, will make the instances of this class fire at different times with respect to each other. Each act cycle, decrement the value of the delay-timer; and, if the value is zero, fire and set the value of the delay-timer to 600.
JetLennit JetLennit

2013/5/7

#
or if you would rather it does it randomly (which is a bit more dynamic)
if(Greenfoot.getRandomNumber(300) + 400) 
{ 
gunWepon gun = new gunWepon; //change gunWepon to the gun class
getWorld().addObject(gun, getX(), getY());
}
Hawx_ Hawx_

2013/5/7

#
Thanks guys ! :D
JetLennit JetLennit

2013/5/7

#
Which one are you using? (out of curiosity)
Hawx_ Hawx_

2013/5/8

#
yours , it's easier to understand because I'm still learning basic Greenfoot at the moment
Hawx_ Hawx_

2013/5/8

#
Jet , it comes up with incompatible types one line 1 of your code.
JetLennit JetLennit

2013/5/8

#
Sorry, I wrote that in my browser, try this
if(Greenfoot.getRandomNumber(300) + 400 < 10)   
There are more replies on the next page.
1
2