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

Username:   Password: 
 RegisterRegister   
 Delay Function and Window
Index -> General Discussion
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Omster




PostPosted: Fri Jun 09, 2017 1:41 pm   Post subject: Delay Function and Window

Hello,
How would you set speeds to 2 different objects? I am trying to make a user-controlled circle animation go faster than another randomly moving circle animation, but the delay function applies to all above it.
Also, how would I set limits to the x-and-y-coordinates of my circles to prevent them from going off the page?
I am using Turing 4.1.1.
The code is below.
Thanks

var x, y : int
x := 100
y := 100
var obstx, obsty : int
obstx := 200
obsty := 100
var obstx2, obsty2 : int
obstx2 := 245
obsty2 := 295
var chars: array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
y := y + 2
end if
if chars (KEY_RIGHT_ARROW) then
x := x + 2
end if
if chars (KEY_LEFT_ARROW) then
x := x - 2
end if
if chars (KEY_DOWN_ARROW) then
y := y - 2
end if
cls
drawfilloval (x, y, 10, 10, blue)
drawfilloval (obstx, obsty, 20, 20, red)
drawfilloval (obstx2, obsty2, 20, 20, red)
obstx := obstx + Rand.Int (-10, 10)
obsty := obsty + Rand.Int (-10, 10)
obstx2 := obstx2 + Rand.Int (-10, 10)
obsty2 := obsty2 + Rand.Int (-10, 10)
if x >= obstx - 20 & x <= obstx + 20 & y >= obsty2 - 20 & y <= obsty2 + 20 then
put "Game Over!"
exit
end if
if x >= obstx - 20 & x <= obstx + 20 & y >= obsty - 20 & y <= obsty + 20 then
put "Game Over!"
exit
end if

end loop
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Jun 10, 2017 6:51 am   Post subject: RE:Delay Function and Window

How about instead of changing the delay, you change the number of pixels you move per delay?
Omster




PostPosted: Sat Jun 10, 2017 7:40 am   Post subject: Re: Delay Function and Window

How would I do that?
And also how would I stop the circles from going off the screen?
Insectoid




PostPosted: Sat Jun 10, 2017 7:43 am   Post subject: RE:Delay Function and Window

Instead of moving 2 pixels at a time, do 4 pixels at a time. Now your circle moves twice as fast.

Can you think of a way to check if the circle is at the edge of the screen?
Display posts from previous:   
   Index -> General Discussion
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: