Random Speed + Ypos at random times
im trying to make a game where your in a tower and enemies come from the right of the screen.
but i dont know how to make them have a speed of 4-6, y pos of maybe 250-400, and spawn at random times like 1 - 3 seconds.
if there is anyway to do this, please reply :D
Re: Random Speed + Ypos at random times
OK so there are 50 frames per second if your FPS is set to 50. Constantly add to a counter 0.02 and when it equals random(4) then create an enemy at -16,-16 or whatever the size of your enemy sprite is. In the same event that the enemy is created, set its Y position to Y Top Frame + 250 + random(151) (you can leave out Y Top Frame if you don't want it to spawn based on the Y position of the screen) and set its speed to 4 + random(3). Also set its X position to whatever the x position is you want.
Re: Random Speed + Ypos at random times
If you want any random time from 1-3 seconds (including 1 second, 2.35 seconds, and 3 seconds), do what Corlen suggested but instead constantly add 20 to a counter. Then, create another counter (I call this RandomCounter) that will be used to hold the random number. Your events should look like this:
Always:
--- Add 20 to TimeCounter
Start of Frame:
--- Set RandomCounter to Random(2001)+1000
value(TimeCounter) is greater than or equal to value(RandomCounter):
--- [Spawn Enemy]
--- Set TimeCounter to 0
--- Set RandomCounter to Random(2001)+1000
Not entirely sure that's correct, but it should work. The reason you need the extra counter is that the "Random" expression will change every frame loop. This means that either enemies would never be spawned, or it would be very rare for them to spawn after 3 seconds (a lot would spawn after 1 second or so).
Hope that helps. :)