Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Space Invaders using Classes

This topic is 5813 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

I''m trying to make a Space Invaders clone (DirectDraw) as my first complete game. I''ve got the furthest I''ve ever got with a game so far but I''m not sure on how to implement the collision detection between the shots and the enemy ships. At the moment, I have a base class that has move and draw functions and a POINT variable for the position. Derived from that I''ve got an enemy class, which I have a 2D array of instances, a shot class, which is a linked list (implemented myself to see if I could do it) and a player class which has the shots linked list as a member variable. How would I get everything to talk to each other so that shot positions can be compared to enemy positions? I was thinking that I''d need some sort of forward declaration of the enemy class in the player class and then call a "CheckCollision" function everytime I call the move function for the player (every frame). Is there a better way to do this, or is this the most acceptable route to take? Thanks in advance for any help or suggestions. PhilHalf

Share this post

Link to post
Share on other sites
Make an outside (non-object) function to deal with the collisions. Or just put the code into your updating routines.
You'll have to run through one list or the other for each item in the opposite list. Ha ha, I mean like this (in C)..

int enemy;
ShotObj *shot;

for(enemy=0; enemy < NUM_ENEMIES; enemy++)
shot = FirstShotPointer;
// do collision check here with Enemies[enemy] and *shot
shot = shot->next;

Hope that helps at all..

[edited by - Jiia on August 17, 2002 3:52:57 AM]

Share this post

Link to post
Share on other sites

  • 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!