Archived

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

PhilHalf

Space Invaders using Classes

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;
while(shot)
{
// do collision check here with Enemies[enemy] and *shot
shot = shot->next;
}
}


Hope that helps at all..
Jiia

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

Share this post


Link to post
Share on other sites