Computer Science Canada Changelevel in a maze upon collision help. |
Author: | MattehMatt [ Sat Nov 01, 2008 6:55 pm ] | ||
Post subject: | Changelevel in a maze upon collision help. | ||
Hey I'm coding a simple maze game right now but I cant get it so that when one square hits the other square the level ends and goes to the next level, I cant even seem to get collision to work either. If anyone wouldn't mind coding in what I should have to make the code below terminate or clear the screen or something obvious so that I know it worked, (btw this isn't for school, just trying to figure it out!)
|
Author: | S_Grimm [ Sat Nov 01, 2008 7:04 pm ] | ||
Post subject: | RE:Changelevel in a maze upon collision help. | ||
There is a great tutorial on collision detection in the turing tutorials. i don't have a link right now, ill pm it to you l8r. anyway, to detect collision between two boxes, you have to determine if the edges hit. it goes something like this (assuming that the wall is at an x coordinate of 300 and there is a top wall at a y coordinate of 400)
|
Author: | MattehMatt [ Sat Nov 01, 2008 7:09 pm ] |
Post subject: | Re: Changelevel in a maze upon collision help. |
Thanks for the tip, ill try that out. About that collision tutorial, I read it, multiple times, but I couldnt seem to wrap my head around it ![]() |
Author: | MattehMatt [ Sat Nov 01, 2008 9:02 pm ] | ||
Post subject: | Re: Changelevel in a maze upon collision help. | ||
Alright well it changes levels now, but I need a way to replace the goal dot. Any suggestions? Code so far :
|
Author: | CodeMonkey2000 [ Sat Nov 01, 2008 9:45 pm ] |
Post subject: | Re: Changelevel in a maze upon collision help. |
MattehMatt @ Sat Nov 01, 2008 7:09 pm wrote: Thanks for the tip, ill try that out.
About that collision tutorial, I read it, multiple times, but I couldnt seem to wrap my head around it ![]() The basic idea is that you store the world in a 2D matrix (array). Each element in the matrix represent an nXn area of pixels of screen. So if each element represented 10x10 pixels, element at [2,2] represents the pixels from 20,20 to 30,30. Now if you are given a pixel coordinate: 25,26 for example, you can figure out what element you are in using some basic math. If each element represents an area of 10x10 pixels, then you floor divide (divide and round down) 25 and 26 to get 2,2 (25/10=2 and 26/10 =2). Intuitively you should see why this is true. It's very basic math, it has been used in many games from the snes and nes era. So the point 25,26 lies in element 2,2. This method is much faster since you no longer need to compare one object to all other object; you immediately know what is in the area. This method is also better since pathfinding for AI is MUCH easier since you are using a 2d matrix. I plan to rewrite that tutorial one of these days... |