Computer Science Canada Collison Detection, Help |
Author: | miller6 [ Mon Jan 25, 2010 3:54 pm ] | ||
Post subject: | Collison Detection, Help | ||
What is it you are trying to achieve? I am trying to get an image to move around and act just like the ball in brick breaker. What is the problem you are having? Using collision detection to make sure it does not go off the screen. Describe what you have tried to solve this problem I ahve tried using a variety of different techniques in order to make the image move. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) So far i have to procedures and collision detection for the top and bottom butt he bottom is not working.
Please specify what version of Turing you are using 4.1.1 |
Author: | TheGuardian001 [ Mon Jan 25, 2010 5:09 pm ] | ||
Post subject: | Re: Collison Detection, Help | ||
Instead of having 4 separate procedures for each direction, you should be using 1 procedure to move the flake, and using different velocity values to change direction. So first, create a variable for each X velocity and Y velocity. Set them both equal to 1 (you can set them to whatever you want, but this is a good starting point to get it working. Having a positive x and y velocity means that the flake will move Up and to the Right. Whenever the flake hits the side of the screen, you should multiply the X velocity by -1. This will switch whether it is moving left or right. Whenever the flake hits the top or bottom of the screen, you should multiply Y velocity by -1, which switches whether it moves up or down. Once you've done that, the one remaining movement procedure should follow this sort of structure:
It should be pointed out that there is no loop in that procedure structure. you should be looping calls to the procedure, not looping the contents of the procedure. |
Author: | miller6 [ Mon Jan 25, 2010 5:55 pm ] | ||
Post subject: | Re: Collison Detection, Help | ||
Do i still incorporate the different angles so that each time it hits it bounces off a new direction (just like the ball in brick breaker) if so, where? This is the new codding i changed.
|
Author: | TheGuardian001 [ Mon Jan 25, 2010 6:46 pm ] | ||
Post subject: | Re: Collison Detection, Help | ||
As I said, you can use any value you want for the velocities. 1, 1 is just easier to work with for the purposes of my example. It will work with any number though. You can incorporate these by simply setting the X and Y velocities to the random values as required. So instead of simply inverting the X/Y velocity when the flake hits a wall, set it to a random number, with the correct sign, depending on the direction it is moving. So for example
One question though, what exactly is the loop with counter doing? Depending on what it's doing, there might be a better way to do that without having a loop inside of a procedure (loops inside procedures are generally not good ideas, they make everything else stop and wait for them) |