Space Invaders using Classes

Started by
1 comment, last by PhilHalf 21 years, 8 months ago
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
Advertisement
Bounding Boxes maybe? Thats how I did my space invaders game
//att
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]

This topic is closed to new replies.

Advertisement