Computer Science Canada How to make a simple ball bounce off walls? |
Author: | jpui [ Sun Dec 03, 2006 7:10 pm ] | ||
Post subject: | How to make a simple ball bounce off walls? | ||
Hello, I'm new to Turing and I am starting to learn it in my Gr. 11 Comp. Engineering class. I need to know the code to make a simple ball bounce off walls. So far I got:
Please help me on this. Thanks. -jpui[/code] |
Author: | jpui [ Sun Dec 03, 2006 7:14 pm ] |
Post subject: | |
I can make the ball bounce once and then it gets stuck. If anyone know a different way that makes the ball bounce everywhere instead of just one direction, please post it here (Just make the code simple so I can at least understand it ![]() Thanks. (And Don't worry about the codes with the %, I don't need them.) |
Author: | Clayton [ Sun Dec 03, 2006 7:32 pm ] |
Post subject: | |
Go check out the Turing Walkthrough for the tutorials on collision detection, there you should find what you need, if not, post back here with more questions. Welcome to CompSci.ca btw |
Author: | jpui [ Sun Dec 03, 2006 7:42 pm ] |
Post subject: | |
Freakman wrote: Go check out the <a href="http://www.compsci.ca/v2/viewtopic.php?t=8808">Turing Walkthrough</a> for the tutorials on collision detection, there you should find what you need, if not, post back here with more questions.
Welcome to CompSci.ca btw Hello, Thanks. Sorry, but I'm in a bit of a hurry (due tmw), and i need the codes fast. Can someone just fix up the codes? It's just this time lol. Thx. |
Author: | jpui [ Sun Dec 03, 2006 7:45 pm ] |
Post subject: | |
(Where's the Edit button?) Anyways, There's nothing there I need. I need a ball that bounces off walls, not another ball. |
Author: | uberwalla [ Sun Dec 03, 2006 7:56 pm ] | ||
Post subject: | |||
1) dont rush people it makes us not want to help you 2) we cant just give you the code (or we can but theres a challenge to it) ok.. so here it is. a ball that bounces off walls.
like i was talking about in #2 there is a challenge to this//catch. just so u cant completely take the code u have to explain how it works to ur teacher , for it is not my job to do so. (not trying to sound like a jerk but i no1 here at compsci really wants to do ur work for u. we'll help (which i did u just explain it ![]() |
Author: | jpui [ Sun Dec 03, 2006 8:14 pm ] |
Post subject: | |
I know. Its a bit of a rush and thanks for the help ![]() I usually read the stuff slowly and try to figure the stuff out myself and with a bit help from other people. but since I've been stuck on this question for awhile and its due tmw, I needed some codes to make the program work. Thanks uberwalla for the help and Freakman for trying to help ![]() |
Author: | jpui [ Sun Dec 03, 2006 8:24 pm ] |
Post subject: | |
..... I don't really understand the codes you put in. Is it okay if you please change my code around using simple codes (without the sound and the View.Update thing). Thanks. |
Author: | Clayton [ Sun Dec 03, 2006 8:27 pm ] |
Post subject: | |
If you read some tutorials in the Turing Walkthrough, I'm sure you'll find your answers soon enough. |
Author: | Piro24 [ Sun Dec 03, 2006 8:32 pm ] |
Post subject: | |
You are overthinking it. Make another variable for axis of each ball, maybe call it direction or something. So for one ball, make directionX, directionY. If you want the ball to travel up and right, make their values 1 and 1. If you want them to travel down and left, make them -1 and -1. Than use the normal parameters for the ball, and add it to the direction. Lets say the x-cordinate is called 'x1' on your ball and the y is 'y1'. Do x1 += directionX and y1+=directionY That will move the balls. Than make statements like 'if x1 = maxx then direction *= -1' The direction *= -1 will make the ball go in the opposite direction, since it is now the opposite integer (ie. If you made it positive to go up, it will be negative therefor go down. Same with left and right). |
Author: | TokenHerbz [ Sun Dec 03, 2006 8:36 pm ] |
Post subject: | |
if both x1/y1 are active at a time, it creats a dierections: x1 = 1 so its moving right at 1 px / loop y2 = 2 so its moving up this will make the ball move at an angle shooting top right of the screen. Adjust and minipulate the velocities of the ball to creat other directional points, and use ifs etc: to keep the ball inside. |
Author: | jpui [ Sun Dec 03, 2006 10:52 pm ] |
Post subject: | |
TokenHerbz wrote: if both x1/y1 are active at a time, it creats a dierections:
x1 = 1 so its moving right at 1 px / loop y2 = 2 so its moving up this will make the ball move at an angle shooting top right of the screen. Adjust and minipulate the velocities of the ball to creat other directional points, and use ifs etc: to keep the ball inside. Thank you guys for the many help. ![]() |