Computer Science Canada Need some help with some collision detection |
| Author: | aspire [ Wed Oct 03, 2007 10:08 am ] | ||
| Post subject: | Need some help with some collision detection | ||
Hey everyone. I am back with some more questions. Well, at the moment I am really lost lol. I need to make a pong game. So far this is what I have * A moving ball * A movable paddle * Boundarys for the ball This is what I need some help with/cant figure out what/how to apply it with/ * Make the ball bounce off the paddle So far here is what I have: **Couldnt remember what the turing tags were at the time I posted this, have to look them up lol**
|
|||
| Author: | Bored [ Sat Oct 06, 2007 8:36 pm ] |
| Post subject: | Re: Need some help with some collision detection |
OK, there's a lot I'm gonna mention about your code here, so I'll start off with answering your question. Collision detection in this case is rather simple at the most basic levels. Once the ball has reached the height where it would hit the paddle you simply check if it is within the bounds of the paddle. So if your Y value reaches a certain spot you check if your X value is between left and right values. If so then you change the direction of travel DY. OK, now for my comments. Firstly please for the sake of all learn to use cls and View.Update. Here's a tutorial of View.Update and View.Set, please see the section on eliminating screen flicker. Next is if you would like change the sign on a variable rather then going variable := variable * -1 you can simply use the *= command which will multiply a variable by a certain number and assign the result to the variable. So you code woul become variable *= -1. Plus brackets are not needed around the -1. You can use this trick asweel for some other operations; +=, -=, /=, div=, mod=, **=, or=, and=, not== (works not how you would expect) and possibly a few other i don't know of. Any ways, your variable right and left can simply be changed to one variable position and replace right with position + 50 and left to position - 50. And finally what is the point of leftr and rightr? The only time you use them is to change there values but you never again use them. This isn't bad for a starter, just a few things to clean up. |
|
| Author: | cpu_hacker4.0 [ Tue Oct 09, 2007 7:33 pm ] | ||
| Post subject: | Re: Need some help with some collision detection | ||
Here is a really choppy example of a png game I made. It isn't finishe yet, bu the basics are thre. Try using a MathDistance and a MathDistancePointLine for the collision detection with the ball and paddles.
|
|||