Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Space invaders - speed of enemies
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chipanpriest




PostPosted: 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


Space Invaders.t
 Description:

Download
 Filename:  Space Invaders.t
 Filesize:  2.33 KB
 Downloaded:  128 Time(s)


Space Invaders.t
 Description:

Download
 Filename:  Space Invaders.t
 Filesize:  2.33 KB
 Downloaded:  87 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: 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)
chipanpriest




PostPosted: 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
Aange10




PostPosted: 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
Dreadnought




PostPosted: 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
chipanpriest




PostPosted: 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?
Aange10




PostPosted: Fri Dec 30, 2011 12:03 pm   Post subject: Re: Space invaders - speed of enemies

Indeed, here is an example of a timer.


Reseting Time.T
 Description:

Download
 Filename:  Reseting Time.T
 Filesize:  495 Bytes
 Downloaded:  65 Time(s)

chipanpriest




PostPosted: 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^?
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: 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?
chipanpriest




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: