Computer Science Canada

Space invaders - speed of enemies

Author:  chipanpriest [ Thu Dec 29, 2011 1:59 pm ]
Post subject:  Space invaders - speed of enemies

Hey I was wondering if there is a way to make the enemies move down slower without having a delay in the game Smile thanks

Author:  Aange10 [ Thu Dec 29, 2011 2:05 pm ]
Post subject:  RE:Space invaders - speed of enemies

A: You can lower their velocity.
B: You can setup a timer.
C: You could delay it but that'd be stupid. (However in this case, you should delay it to at least 60FPS ... Time.DelaySinceLast (17)

Author:  chipanpriest [ Thu Dec 29, 2011 5:04 pm ]
Post subject:  RE:Space invaders - speed of enemies

So Time.DelaySinceLast is just a better version of delay?? cause ive always used delay before

Author:  Aange10 [ Thu Dec 29, 2011 5:43 pm ]
Post subject:  RE:Space invaders - speed of enemies

Yes, read up on this post: http://compsci.ca/v3/viewtopic.php?t=30297

Author:  Dreadnought [ Thu Dec 29, 2011 7:57 pm ]
Post subject:  Re: Space invaders - speed of enemies

Time.DelaySinceLast is really useful in the common situation where you would like to regulate the frequency of a loop's repetition. But it shouldn't be a direct substitute for delay, since it does not really do what delay does. Take this example:
Turing:
put "Hello"
Time.DelaySinceLast(2000) % First delay
cls
for i:1..100000
    locate (1,1)
    put i
end for
put "Done!"
Time.DelaySinceLast(2000) % Second delay
cls
put "Have a nice day!"

The "second delay" is almost non-existent. So the word "Done!" might not be seen by the user. However, using Time.Delay (2000) would have made a 2 second delay each time. The functionality is not identical.

I doubt you would actually use this procedure in such a way, but I just wanted to clarify that although it is often more useful than delay, it should not be seen as a direct substitute.

As a side note, you could actually implement it yourself if you wanted to. This is the code for Time.DelaySinceLast taken directly from the code for the Time module:
Turing:
var timeOfLastCall := 0
procedure DelaySinceLast (delayTime : int)
    if Time.Elapsed < timeOfLastCall + delayTime then
        Time.Delay (timeOfLastCall + delayTime - Time.Elapsed)
    end if
    timeOfLastCall := Time.Elapsed
end DelaySinceLast

Author:  chipanpriest [ Fri Dec 30, 2011 10:52 am ]
Post subject:  Re: Space invaders - speed of enemies

This is another, kind of separate question but based on the same idea. Could i not do something like:
Turing:
var t : int := Time.Elapsed
if t = 5000 then
Ey -= 20 %first row of enemies moving down
Ey2 -= 20 %second row of enemies moving down
end if


Would this work? And if so, could I somehow make it so it would move down every 5000 milliseconds without doing the code above multiple times?

Author:  Aange10 [ Fri Dec 30, 2011 12:03 pm ]
Post subject:  Re: Space invaders - speed of enemies

Indeed, here is an example of a timer.

Author:  chipanpriest [ Fri Dec 30, 2011 4:24 pm ]
Post subject:  Re: Space invaders - speed of enemies

But what I'm trying to say is, is there a way to make something happen in intervals with only one set of code?

For example, It would be a pain to do this:
Turing:
if Time.Elapsed() = 5000 then
Ey -= 1
elsif Time.Elapsed() = 10000 then
Ey -= 1
elsif Time.Elapsed() = 15000 then
Ey -= 1
%etc
%etc


Would there be a way to make it so the y value decreases every 5000 milliseconds in just one set of code instead of doing that^?

Author:  Aange10 [ Fri Dec 30, 2011 5:08 pm ]
Post subject:  RE:Space invaders - speed of enemies

Mhm.....

Turing:

var timer : int := 0
loop
 if Time.Elapsed () - timer >= 5000 then
   Ey -= 1
   timer := Time.Elapsed ()
end if
end loop


Now ever 5 seconds it moves down... Just like the code in the thing I uploaded. You could hard code it all if you wanted, but whats the point?

Author:  chipanpriest [ Fri Dec 30, 2011 5:09 pm ]
Post subject:  RE:Space invaders - speed of enemies

yea i got it thanks Very Happy Ima upload it soon


: