Using Arrays instead of structs (galaga)

Hey guys for a class final I'm building Galaga, I was wonder how to shorten my code using arrays, I want to be able to use more enemy ships and have them perform movement, firing, and collisions. My friend mentioned that I might need to use loops as well. Help would be great! thanks guys!

heres what I have by just using structs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
struct Enemy
{
    double x;
    int y;
    int speedX;
    int speedY;
    int points;
    int image;
};

struct User
{
    double x;
    int y;
    int speedX;
    int speedY;
    int image;
};

void MoveEnemy(Enemy &e);
void MoveUserShip(User &s);
bool redraw, move_down = false, move_up = false, move_left = false, move_right = false,
     shoot_space = false, start_enter = false, enemy_hit = false, enemy_shoota= false ,enemy_shoot2= false,enemy_shoot3= false,enemy_shoot4= false,enemy_shoot5= false,enemy_shoot6= false,enemy_shoot7= false;

int main(int argc, char **argv)
{

    ALLEGRO_DISPLAY * display = NULL;
    ALLEGRO_BITMAP * SpriteSheet = NULL;
    ALLEGRO_EVENT_QUEUE * EvQue = NULL;
    ALLEGRO_EVENT Event;
    ALLEGRO_TIMER * Timer = NULL;


    User ship = {200, 300, 1, -1, 1};
    User bullet;
    User bulleta;
    User bulletb;
    User enemy_bullet;
    Enemy a = {50, 50, 1, -1, 1};
    Enemy b = {150, 50, 1, -1, 1};
    Enemy c = {250, 50, 1, -1, 1};
    Enemy d = {350, 50, 1, -1, 1};
    Enemy r1 = {100, 75, 1, -1,1};
    Enemy r2 = {200, 75,1 ,-1,1};
    Enemy r3 = {300, 75, 1, -1,1};
theres not really any code to help you with using arrays, i think we either need more code or more of a problem
Do you know how to use arrays and multidimensional arrays? It's definitely going to need loops to get the user's ship to move right and for the enemies and bullets to do the same. You're also going to want to use a loop for assigning enemy values to an array...


How much experience do you have with C++? How long before the final is due?
Last edited on
Hs intro, its due Thursday morning. I have been working on it all day, me and my partner are almost done, we just finished all the enemies shooting, collisions w explosion for the user n enemy ship. we are just working on glitches and stuff
Topic archived. No new replies allowed.