Computer Science Canada Circular Collision Detection- HELP! |
Author: | adamlover [ Thu May 30, 2013 7:12 pm ] | ||
Post subject: | Circular Collision Detection- HELP! | ||
Hi all, this is my first ever question, so bare with me. For my ISU, I'm making a game where the user moves around the screen, collecting stars and avoiding enemies. These circular enemies will kill the circular user. My issue is with detecting collision. The enemies are not random, but they do move across the screen using "for" statements; the user moves with the keyboard arrows. I'm using processes and the distance formula and radii, but for some reason, the distance between the two circles is not recognized, so the program won't "GAME OVER". Any help/advice/suggestions are beyond greatly appreciated. Thanks-
|
Author: | Dreadnought [ Thu May 30, 2013 8:24 pm ] |
Post subject: | Re: Circular Collision Detection- HELP! |
First and foremost I strongly recommend that you do not use processes. I understand it's tempting, but it will likely cause you more grief than good. Why are you calling fork over and over again? You don't need multiple user and enemy1 processes, one will suffice (note that I think you would be better off not using processes). As for why your game is not exiting, you check for collision once every 1.83 seconds and when you do foo is probably 1. Instead of using processes, try keeping track of where your objects are, where they are going, then run a loop to update where they are on the screen and check for collision every time. |
Author: | evildaddy911 [ Fri May 31, 2013 6:24 pm ] |
Post subject: | RE:Circular Collision Detection- HELP! |
the biggest 2 things wrong with it are: 1. you should have put your "fork" statements OUTSIDE the main loop if you are using processes (which should NOT be used in Turing) because then you start a new process every few seconds, which generally just blows up your program 2. when you exit the main loop because the player has collided with the ball of death, you don't end the processes. that is why processes are bad. they don't end until either they run out of code to execute or the program ends. as far as i know, there is only 1 way to end a process prematurely: by putting "exit when done" statement ONLY inside the biggest loop of the process. What i suggest doing is incorporating the processes into 1 big main loop. have player movement, then ball-of-death movement. then have your "am i dead?" check, exiting if neccesary. No processes. 1 more thing: when you use setscreen and View.Set, you aren't switching the drawing mode to "offscreenonly" so View.Update is doing nothing. if you don't understand what this means, check out the Turing Walkthrough |