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

Username:   Password: 
 RegisterRegister   
 boucing ball help with the code
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rookie




PostPosted: 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! Laughing so if anyone could help in anyway, that would be awesome!
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Tue Feb 17, 2004 2:26 pm   Post subject: (No 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
Maverick




PostPosted: Tue Feb 17, 2004 3:48 pm   Post subject: (No 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
recneps




PostPosted: Tue Feb 17, 2004 3:49 pm   Post subject: (No subject)

Or you could try looking at some of the Turing Examples, like the Bouncing House one. Smile
Cervantes




PostPosted: Tue Feb 17, 2004 3:51 pm   Post subject: (No subject)

Paul the second link isn't a good one Razz 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 Razz 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 Confused
rookie




PostPosted: Wed Feb 18, 2004 2:02 pm   Post subject: (No 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
rookie




PostPosted: Wed Feb 18, 2004 2:08 pm   Post subject: (No 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 Laughing
Cervantes




PostPosted: Wed Feb 18, 2004 4:10 pm   Post subject: (No 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
Sponsor
Sponsor
Sponsor
sponsor
rookie




PostPosted: Thu Feb 19, 2004 10:44 pm   Post subject: (No 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]
Paul




PostPosted: Fri Feb 20, 2004 11:01 am   Post subject: (No 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.
rookie




PostPosted: Fri Feb 20, 2004 2:37 pm   Post subject: (No 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
Cervantes




PostPosted: Fri Feb 20, 2004 4:30 pm   Post subject: (No subject)

Well in that case you need lots of physics. Confused

check out this topic
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  [ 12 Posts ]
Jump to:   


Style:  
Search: