Computer Science Canada Using an Array with collision detection |
Author: | vapour99 [ Wed Jun 11, 2008 8:13 am ] | ||
Post subject: | Using an Array with collision detection | ||
My spaceshooter game uses arrays to create bullets and falling meteors. If I implement simple collision detection, it seems to use the x/y vars of the most recently created meteor (possibly due to the "upper" command?) side notes: -I haven't fine tuned collision detection do to the entailed problem -Asteroids and Meteors produce the same "falling meteor" effect but each use different arrays. -asteroids are slightly smaller than the meteors and are grey. Any help is much appreciated! here is the code:
|
Author: | Insectoid [ Wed Jun 11, 2008 3:20 pm ] |
Post subject: | RE:Using an Array with collision detection |
It would be nice if you'd make it an attatchment, so that we have the pictures as well. I can't help until then. |
Author: | vapour99 [ Wed Jun 11, 2008 6:02 pm ] |
Post subject: | Re: Using an Array with collision detection |
Here you are -You may have to nil-out (with %) some other sounds I threw in but are unused in this version (elite-1.wav) |
Author: | riveryu [ Wed Jun 11, 2008 10:41 pm ] | ||
Post subject: | Re: Using an Array with collision detection | ||
vapour99 wrote: My spaceshooter game uses arrays to create bullets and falling meteors. If I implement simple collision detection, it seems to use the x/y vars of the most recently created meteor (possibly due to the "upper" command?) -I haven't fine tuned collision detection do to the entailed problem... To solve your problem, all you need to do is to for loop through the array of your meteors or asteroids arrays and check each one. I assume that you already know how to do it according to your coding habit that im seeing, but heres an example. Hope this helps you, sry if its too obvious. Also, when I ran your program from your posted attachement, it didnt work because "illegal picture ID number". if you didnt know already, you dont have to put the directory "e:/picFileName.pic" if you have your turing file in the same directory, you can just put "picFileName.pic" if the turing file is also in "e:/". This makes it easier when you want to move your files, so you dont have to keep editing your loading dir.
|
Author: | vapour99 [ Thu Jun 12, 2008 8:24 am ] |
Post subject: | Re: Using an Array with collision detection |
Sorry about the pictures and propable sound errors from my previous attachement Im just looking at "riveryu's" suggestion and am attempting to implementing it now (im a tad busy with exams) Unfortunatly, flexible Arrays are a relatively new skill to me, as is the use of "mod" can anyone shed light on precisely what is going on inside of the for loops (it would be a great help as i'm relatively new to coding) thanks for the quick replies! Here is the most recent version of my game with all the necessary files (it dosen't have riveryu's for loops implemented yet) |
Author: | vapour99 [ Thu Jun 12, 2008 7:22 pm ] |
Post subject: | Re: Using an Array with collision detection |
sorry about myself replying again; here is another update of the source code (now has crude options for the speed of computer the program is run on, it changes projectile speeds accordingly) |
Author: | Insectoid [ Thu Jun 12, 2008 7:37 pm ] |
Post subject: | RE:Using an Array with collision detection |
Instead of reposting you new copy, you can edit your last one and click 'update attachment' after you click on 'posted attatchments'. Save some bandwidth, make less reading. |
Author: | riveryu [ Thu Jun 12, 2008 9:01 pm ] | ||
Post subject: | Re: Using an Array with collision detection | ||
Im busy with them damned exams too actually. If this is reply is not late... - you can add a loading screen before the picture loading. Ex. insert the line put "loading ..." right before loading pictures, so the user sees the load screen while program loads pictures. - the for loop explaination...read the comments...
mod, or modulo operator returns the remainder of a number. Ex. 4 mod 2 yields 0 , 4 divided by 2 does not have remainder, therefore 0. Another case, 5 mod 2 yields 1, because 2 goes into 5 two times, 5 - 4(from 2*2) = 1. |
Author: | vapour99 [ Sun Jun 15, 2008 3:13 pm ] | ||
Post subject: | Re: Using an Array with collision detection | ||
well, I now have the for loop checking all the asteroids that are created (im starting with clooision detection on the asteroids) but I have ran into another problem; it seems it checks EVERY asteroid or meteor that has been created; this means that it will collide even if the Asteroid/meteor is long gone... not good. is there a way to check for the asteroids/meteors that are currently on the screen? (possibly remove the asteroids/meteors that have exceeded the max y value of the window from the array?) here is the procedure code that has to do with collision detection in asteroids:
NOTE: -the most recent version uses a small flashing box in the lower left corner to show that it is colliding instead of a sound - is set to a sort of "debug mode" so that only one asteroid is created every 8 seconds |
Author: | riveryu [ Sun Jun 15, 2008 9:07 pm ] | ||
Post subject: | RE:Using an Array with collision detection | ||
Sry but, you should bundle your posts with pictures so we dont have to look at your previous ones and search for pics when we want to SEE it. For the checking for collison part, you should only allow a set number of meteors on screen maybe increase with level or difficulty. Recycle your array elements, when the asteroids are off screen, reasign them to a new position as if they are new asteroids. Heres a non-working code to show you the structure.
|