Jump to content
  • Advertisement
Sign in to follow this  
ishkabible

SDL Endless Dynamic collision detection of Projectiles

This topic is 3080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi im wondering how to do somthing that i do all the time in flash but cant do here. im trying to make a simple astriods/space invaders game and i would like to test all the collisions like so
Sprite Array[256];
Sprite Array2[256]
CheckAllCollisions() {
 for(i=0;i<=256;i++) {
    Sprite temp;
    temp = Array;
    for(j=0;j<=256;j++) {
      Sprite temp2;
      temp2 = Array2[j];
      if(CheckCollision(temp, temp2);
        Kill(temp);
        Kill(temp);
      }
    }
  }
}
could someone tell me how to do this in SDL. i know how to check collisions between two of my sprites (class i made). it uses a SDL_rectangle that is part of the Sprite class and an SDL_Surface that i use for animation to give Pixel Perfect Collisions. but this method dosnt seem to work. o and yes even though you cant see that i have done it i have populated the arrays.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
could someone tell me how to do this in SDL.
You might be misunderstanding what SDL is exactly. This isn't something that you 'do in SDL'. SDL is a low-level library for handling graphics, sound, input, etc. - it doesn't have anything to do with what you've posted here (aside, perhaps, from the fact that you're making use of SDL's 'rect' structure).

Are you maybe wondering how to do this in the C or C++ programming language? If so, it would probably look largely like what you posted, presuming that the Kill() function does something that makes sense. (Technically, you'd probably want to structure the loop differently so as to avoid redundant checks, and even then, that looks like a lot of tests to be performing - however, those aren't really language-specific issues.)

If that doesn't help, perhaps you could explain in a little more detail how it's not working.

Share this post


Link to post
Share on other sites
ok well your right i wasn't very clear and this is more of c/c++ issue than it is a SDL issue. i stated something along the lines of "...it doesn't seem to work" vs. actually telling you whats happing. the only reason i came here is because i was working with SDL so any help i might need could be found here i guess. o and Kill() was just to put something there as to say "do something here". ok so back to whats happing. one there is no real way that i can see to "stack" with an array the way i did in flash. this seems to create and issue when its checking things because when it checks for collisions it runs over what might have been "Killed" so to speak but because the "Killed Surface" has been freed it cant check for collision and the program just stops working like with the little load bar and windows saying would you like to check online for a solution.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!