Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with collision
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
drewst18




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Apr 23, 2004 5:24 pm   Post subject: (No 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
AsianSensation




PostPosted: Fri Apr 23, 2004 5:40 pm   Post subject: (No 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.
Cervantes




PostPosted: Sat Apr 24, 2004 5:19 am   Post subject: (No 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.
AsianSensation




PostPosted: Sat Apr 24, 2004 6:18 am   Post subject: (No 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.
Delta




PostPosted: Mon Apr 26, 2004 7:35 pm   Post subject: (No 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: