Computer Science Canada boucing ball help with the code

 Author: rookie [ Tue Feb 17, 2004 1:41 pm ] Post subject: boucing ball help with the code i have just started turing in my class, and i really have no idea wat to do i understand somethings but not alot i need to do a program like amovie im asking if some one could help me with how i need to make a simple ball bounce! so if anyone could help in anyway, that would be awesome!

 Author: Paul [ Tue Feb 17, 2004 2:26 pm ] Post subject: check this out http://www.compsci.ca/v2/viewtopic.php?t=3525 or/and this http://www.compsci.ca/v2/viewtopic.php?t=3704

Author:  Maverick [ Tue Feb 17, 2004 3:48 pm ]
Post subject:

heres my ball thing

 code: %n00bish bouncing ball setscreen("nocursor") setscreen("graphics:400;350") var ballx,bally,ballxdir,ballydir:int drawfillbox(1,1,400,350,white) randint(ballx,0,maxx) randint(bally,0,maxy) ballxdir:=1 ballydir:=1 loop     drawfilloval(ballx,bally,5,5,12)     delay(1)     drawfilloval(ballx,bally,5,5,0)     if ballx>maxx and ballxdir>0 then ballxdir:=-ballxdir elsif ballx<0 and ballxdir<0 then ballxdir:=-ballxdir elsif bally>maxy and ballydir>0 then ballydir:=-ballydir elsif bally<0 and ballydir<0 then ballydir:=-ballydir end if ballx +=ballxdir bally+=ballydir end loop

 Author: recneps [ Tue Feb 17, 2004 3:49 pm ] Post subject: Or you could try looking at some of the Turing Examples, like the Bouncing House one.

 Author: Cervantes [ Tue Feb 17, 2004 3:51 pm ] Post subject: Paul the second link isn't a good one too complicated. rookie, Read through the first part of code in the first link. Basically in this problem you have to store the position of a ball. We do that by declaring variables, x and y, as integers. The other thing we need to store is its pattern of movement (ie. its speed along the x axis and its speed on the y axis.) I call these variables dx and dy, but you can call them whatever you want. In DanShadow's tutorial they are called xmod and ymod. Inside a loop (so that it happens many times) the ball is drawn at its position that we have stored in the 2 variables, x and y. (In dan's they are called ballx and bally). The other thing that we have to do is add the dx or the xmod to the x variable, as well as adding the dy or ymod to the y variable. That will make the ball move. The final step is to clear the ball so that it doesn't leave a big line behind it We can do this in 2 ways: by clearing the entire screen and drawing everything again, or by drawing another ball that is identicle to the first ball, except that its colour matches the background colour. You have to be careful where you place it though. It should be after the delay, whereas the first drawing should be before the delay. EDIT 2 ppl posted while I was typing

 Author: rookie [ Wed Feb 18, 2004 2:02 pm ] Post subject: thanks for your help everyone . is their a way so i could make it bounce be restricted so that it goes / \ / \ / \ _ / \? kinda like that? i know it looks bad but i hope u get the point... anyhelp would be appreciated

 Author: rookie [ Wed Feb 18, 2004 2:08 pm ] Post subject: i looked at one of the programs by Cervantes and is it possible that i could draw a white box to risrict it? i dono im still a rookie

Author:  Cervantes [ Wed Feb 18, 2004 4:10 pm ]
Post subject:

Draw a white box? Well because you said white, then you can use whatdotcolour.
The other way to do it is to use if statements to determine whether a collision has occured.

I'm not too sure what you're asking though... You want the ball to go like this?
 code: / \ / \

or like this?
 code: / \ _ / \

For a predefined pattern of movement like the second on I would use case.

If its the first one, just say
 code: if ballu > maxu or ballu < 0 then    bally *= -1 end if

 code: bally *= -1

is the same as
 code: bally := bally * -1

 Author: rookie [ Thu Feb 19, 2004 10:44 pm ] Post subject: ok what i need to do is make an annimation movie type thing and my idea was to make a simple ball (with a mind of its self) bouncing through out a setting i just want the ball to do a simple bounce forward like its jumping! i know strange idea.hahaha ok so if that helps explains my idea and u can understand wat help i need thanks! [/code]

 Author: Paul [ Fri Feb 20, 2004 11:01 am ] Post subject: You want the ball to "have a mind of its own" you mean, jumping around like a person, not in an orderly fashion? That would mean you don't need physics, but an animation. like moving a circle around.

 Author: rookie [ Fri Feb 20, 2004 2:37 pm ] Post subject: all i wat is for it to take little jumps. like its playing leap frog so that it does little hops. im sorry my discriptive skills suck ass

 Author: Cervantes [ Fri Feb 20, 2004 4:30 pm ] Post subject: Well in that case you need lots of physics. check out this topic

 :