Computer Science Canada rectangle picture collision |
Author: | rcbhs [ Thu Dec 06, 2007 8:58 am ] |
Post subject: | rectangle picture collision |
if my coordinates are variables because both object are constantly moving, how do I get the collision for all sides? My variables are manx, many, ghostx, ghosty for the 2 objects I need to collide. What I have now is totaly screwed and works quite strangely. if (manx <= ghostX + Pic.Width (ghostID)) and (many >= ghostY - Pic.Height (manID)) and (many <= ghostY + Pic.Height (ghostID)) then put "collision" end if is the code i currently have for the collision and my collision is weird (I'll try to draw it out here) ------------------------------------------------------------------ ---------------------------------------------------------lGHOSTl ------------------------------------------------------------------ Now with what I have, whenever my man crosses those dotted lines in any way it sees collision, instead of just colliding with the ghost box. Any help at all as to how I can fix my collision so it works properly would be great. (the explination above didn't help much) I tried getting it to work based on what was said earlier but I failed horribly. |
Author: | Silent Avenger [ Thu Dec 06, 2007 9:40 am ] |
Post subject: | Re: rectangle picture collision |
All you have to do is think of what parts of your objects will hit. I'm used to VB but the concept is the same. If object.left < object2.left + object.width then if object.left + object.width > object2.left then if object.top + object. height > object2.top then if object.top < object2.top + object2.height then "put your operation here" end if end if end if end if I believe that is right, for it to work you will need to have 4 decision statements for it to work and all of them have to be written properly. Hope this helps and good luck. |
Author: | rcbhs [ Thu Dec 06, 2007 10:03 am ] | ||
Post subject: | Re: rectangle picture collision | ||
Ok so I have this sort of working. I got the collision working but am lost. I now need it to end the program as soon as there is collision.
Now I know what to do (sort of) but don't know exactly how to do it. I know I would need to put my collision into a boolean variable (srry if im not explaining this right) that is false. Then I can use an exit when statment that exits the program when it is true. Now I don't have a clue how to do that properly though...any help would be great. |
Author: | Silent Avenger [ Thu Dec 06, 2007 10:15 am ] |
Post subject: | Re: rectangle picture collision |
As I am not used to Turing this may not be right but you can try it. Try puttin your exit when statement after your put "collision" %this is here to let me know there is collision for now line and it should end the program. Hope this helps. |