Computer Science Canada

Help with collision

Author:  drewst18 [ Fri Apr 23, 2004 4:01 pm ]
Post subject:  Help with collision

I have most of it down but, I don't know how to make the things disapear when they collide. It is an asteroids game so I want the aliens and the bullets to leave the screen if they collide but I cant get it

eg code;

code:

if y1 = y2 and x1 = x2 then
(Help here)

score:= score + 100   
end if



Can some1 help with the middle part

Author:  Cervantes [ Fri Apr 23, 2004 5:24 pm ]
Post subject: 

the simplest thing to do, though this will really slow down the program in the long run, is to move the x and y values of both off the screen. The best way (from my knowledge) is more complicated. What are you using to keep track of your aliens / bullets? Arrays? If its arrays, switch them to flexible arrays and reduce the bounds of the array and shift the data, effectively getting rid of it.

this stuff is so much easier in GameMaker. "if collision then instance object destroy and destroy self". gah. Confused

Author:  AsianSensation [ Fri Apr 23, 2004 5:40 pm ]
Post subject: 

to make an asteroid dissappear, don't draw it.

Seriously, that's what you are suppose to do. Have an array of flags for your asteroids, and at your part of your program where you are drawing everything, do something like this:

code:
if flagDissappear = false then
    Pic.Draw (asteroid, x, y, picMerge)
end if


and whenever you hit an asteroid, just turn the flag true, so you won't draw it anymore.

Author:  Cervantes [ Sat Apr 24, 2004 5:19 am ]
Post subject: 

that isn't enough though, because the asteroid is still there, just not being drawn. You can still crash into it and so can your bullets.
if you were using whatdotcolour detection it'd be fine, but alas, you're not.

Author:  AsianSensation [ Sat Apr 24, 2004 6:18 am ]
Post subject: 

Well, when we are using flags, anytime you attempt to do an if statement on either the location of the asteroid or something, you check to see if the flag was true or not. So you would be doing the

code:
if blah blah blah and flagDissappear = false then


well, the best way to handle this problem is with OOP. If you know how to use classes in Turing, you could just create an asteroid object every single time you need one by using new, and then kill that object once you no longer needed by using free.

Author:  Delta [ Mon Apr 26, 2004 7:35 pm ]
Post subject: 

ok or even simpler you could do something similar to this....

once the asteroid is hit, set the direction of the bullet to 0 (so it doesn't move) place it on the player (playerX, playerY), then reset the alien's position offscreen so it moves onto the screen again from a different position.


: