Public Group

Archived

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

Problem that has been bugging me for ages

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

Recommended Posts

Ok i''ve been working on a space invaders game for a while now but I can''t get it working right. Probelm: I have an array of 8 aliens, when the first alien in the reaches the edge of the screen I want them all to drop together to the next line. At the moment each one drops one at a time Here is what I have: for(int j = 1; j < ALIENS; j++) { if((Aliens[j].alive == TRUE)&&(nIDEvent == 1)) Aliens[j] = ShiftAliens(Aliens[j],j); } ///////////////////////////////////////////// ShiftAliens(DEVIL Aliens, int Num) { if(Aliens.alive) { if (Aliens.rect.left < m_WinRect.left) {Aliens.dir=m_DevStepSize; Aliens.point.Offset(CPoint 0,48));InvalidateRect(Aliens.rect);} }

Share on other sites
Couple of problems I notice off the bat.

<< for(int j = 1; j < ALIENS; j++) >>

You should be starting your index at 0 instead of 1. Also, your function should shift all the aliens at once. Looks like you are shifting only one in your ShiftAliens function. Once you detect one has reached the side, you then call ShiftAliens (or Shift_ALL_Aliens) which should be a loop from 0 to ALIENS shifting all of them down. I think that''s how I would do it. You then check whether they hit the bottom and set game_over to TRUE or something.

<< if((Aliens[j].alive == TRUE)&&(nIDEvent == 1)) >>

Also the == TRUE is redundant since you can simply say

if ((Aliens[j].alive)&&(nIDEvent == 1))

Not sure what nIDEVent is. Sounds fun, I would not use classes, maybe a struct for the aliens (type of alien, etc). I would do it in straight C and make your DEVIL Aliens array global so there is no passing required to ShiftAliens.

Print it out, and step through each line in your head slowly to see what''s going on.

Phil P

Share on other sites
Cheers I''ll give that a shot

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5
A4L
14

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633736
• Total Posts
3013602
×