This site requires JavaScript, please enable it in your browser!
Greenfoot_back
Back to discussions
User_thumb
Mindlezs wrote ...

2013/1/18

Repeating missile shot, delayed.

User Mindlezs

2013/1/18

I want to the missile to be added to the world every 2000 milliseconds. I wrote this to do it:
I know its already simple, but is there a way to simplify it further?
User_thumb Mindlezs

2013/1/18

shoot is obviously a boolean set to true from start. timer is set to the currenttimemillis
Fractal_r3800c0s800f10000t0z80x0y0 danpost

2013/1/18

In this case, I believe it would be better to use game time instead of real time for the delay between shots. The coding is also fairly straight-forward. Where you are using two 'int's and one 'boolean' for real-time coding, it only uses one 'int' for game-time coding.
Notice in line 7, we are creating a new missle about every 2 seconds (as long as the 'space' key is pressed).
User Mindlezs

2013/1/18

That 120 being abou two seconds is depending on the act speed, right? Thats not an issue, I'm just curious since I'm weighing which of the two counters i should use.
Fractal_r3800c0s800f10000t0z80x0y0 danpost

2013/1/18

That is correct. However, no matter the speed that the scenario is set, if you get the delay to a suitable value, then changing the speed of the scenario should not alter the suitability of the rate because we would be using game-time.
User_thumb Mindlezs

2013/1/18

Great, i get it. Thanks :D
You need to login to post a reply