Allegro/C++ Game [I Need Help]...

Hi,
I made a simple game using Allegro in C++...
First I will show you my full code then i will show you the problem.
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// main.cpp
#include <allegro.h>
#include <cstdlib>   
#include "SHOOTINGSTAR.h"
// #include "BACKROUNDDELETE.h"
// #include "MOUSE.h"
// #include "ASTEROID.h"
#include "NEBULA.h"

BITMAP *PLAYER;
BITMAP *PLAYERUP;
BITMAP *PLAYERRIGHT;
BITMAP *PLAYERLEFT;
BITMAP *PLAYERDELETE;

int x = 10;
int y = 10;

int main(){

    allegro_init();
    install_mouse();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
    
    while( !key[KEY_ESC]){
     
        moveCircle();
        

        acquire_screen();
        PLAYER = load_bitmap( "PLAYER.bmp", NULL);
        PLAYERUP = load_bitmap( "PLAYERUP.bmp", NULL);
        PLAYERRIGHT = load_bitmap( "PLAYERRIGHT.bmp", NULL);
        PLAYERLEFT = load_bitmap( "PLAYERLEFT.bmp", NULL);
        PLAYERDELETE = load_bitmap( "PLAYERDELETE.bmp", NULL);
        /* textout_ex( screen, font, " ", x, y, makecol( 0, 0, 0), makecol( 0, 0, 0) ); */
        draw_sprite( screen, PLAYERDELETE, x, y);
        
        if (key[KEY_UP])
        {
                        y = y - 4;
                        draw_sprite( screen, PLAYERUP, x, y);
        }
        else if (key[KEY_DOWN]) 
        {
                        y = y + 4;
                        draw_sprite( screen, PLAYER, x, y);
        }    
        else if (key[KEY_RIGHT]) 
        {
                        x = x + 4;
                        draw_sprite( screen, PLAYERRIGHT, x, y);
        }
        else if (key[KEY_LEFT]) 
        {
                        x = x - 4;
                        draw_sprite( screen, PLAYERLEFT, x, y);
        }
        else 
        {
                        draw_sprite( screen, PLAYER, x, y);
        } 
        //--
                if (key[KEY_UP] && key[KEY_RIGHT])
        {
                        y = y - 2;
                        x = x + 2;
        }
                if (key[KEY_UP] && key[KEY_LEFT])
        {
                        y = y - 2;
                        x = x - 2;
        }
                if (key[KEY_DOWN] && key[KEY_RIGHT])
        {
                        y = y + 2;
                        x = x + 2;
        }
                if (key[KEY_DOWN] && key[KEY_LEFT])
        {
                        y = y + 2;
                        x = x - 2;
        }
        
       
       /* draw_sprite( screen, PLAYER, x, y); /
       /* textout_ex( screen, font, "@", x, y, makecol( 255, 0, 0), makecol( 0, 0, 0) ); */
       
       //-----------------------------------------------------------------------
    }    
    
    return 0;

}
END_OF_MAIN();


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
// SHOOTINGSTAR.h
#define SHOOTINGSTAR_H
BITMAP *SHOOTINGSTAR;
BITMAP *SHOOTINGSTARDELETE;

int SHOOTINGSTARx[10] = {10,20,150,200,300,360,400,450,480,500};
int SHOOTINGSTARy[10] = {10,20,100,10 ,300,260,111,400,410,440};

int xSHOOTINGSTAR = 100;
int ySHOOTINGSTAR = 100;

int dirSHOOTINGSTAR = 1; //This will keep track of the circles direction
                        //1= Down
                        
void moveCircle()
{
    if (dirSHOOTINGSTAR == 1)
       for (int i = 0; i<10; i++)
       {
           
           xSHOOTINGSTAR = SHOOTINGSTARx[i];
           ySHOOTINGSTAR = SHOOTINGSTARy[i];
           
           if (ySHOOTINGSTAR>500)
             SHOOTINGSTARy[i] = - 100;
           else
           {
               SHOOTINGSTARy[i] = SHOOTINGSTARy[i] + 5;
           }
    
           acquire_screen();
           SHOOTINGSTAR = load_bitmap( "SHOOTINGSTAR.bmp", NULL);
           SHOOTINGSTARDELETE = load_bitmap( "SHOOTINGSTARDELETE.bmp", NULL);
           draw_sprite( screen, SHOOTINGSTAR, xSHOOTINGSTAR, ySHOOTINGSTAR);
           draw_sprite( screen, SHOOTINGSTARDELETE, xSHOOTINGSTAR, ySHOOTINGSTAR);
           /* circlefill ( screen, tempX, tempY, 20, makecol( 0, 0, 0)); */
           /* circlefill ( screen, x, y, 20, makecol( 128, 255, 0)); */
           
           release_screen();           
        }
     rest(10);
} 


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
// BACKROUND.h
#define BACKROUND_H
BITMAP *NEBULA;
BITMAP *NEBULADELETE;

int NEBULAx = 10;
int NEBULAy = 10;

int xNEBULA = 100;
int yNEBULA = 100;

int dirNEBULA = 1; //This will keep track of the circles direction
                        //1= Down
                        
void moveCircle()
{
    if (dirNEBULA == 1)
       for (int i = 0; i<10; i++)
       {
           
           xNEBULA = NEBULAx[i];
           yNEBULA = NEBULAy[i];
           
           if (yNEBULA>500)
             NEBULAy[i] = - 100;
           else
           {
               NEBULAy[i] = NEBULAy[i] + 5;
           }
    
           acquire_screen();
           NEBULA = load_bitmap( "NEBULA.bmp", NULL);
           NEBULADELETE = load_bitmap( "NEBULADELETE.bmp", NULL);
           draw_sprite( screen, NEBULA, xNEBULA, ySNEBULA);
           draw_sprite( screen, NEBULADELETE, xNEBULA, yNEBULA);
           /* circlefill ( screen, tempX, tempY, 20, makecol( 0, 0, 0)); */
           /* circlefill ( screen, x, y, 20, makecol( 128, 255, 0)); */
           
           release_screen();           
        }
     rest(10);
} 


My code compiles perfectly when i don't use the "NEBULA.h" code...
Here are the errors:
1
2
3
4
5
6
7
8
9
10
11
12
8 C:\Dev-Cpp\Projects\Project 3\Space Quest\main.cpp In file included from main.cpp 
 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h In function `void moveCircle()': 
16 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h redefinition of `void moveCircle()' 
16 C:\Dev-Cpp\Projects\Project 3\Space Quest\SHOOTINGSTAR.h `void moveCircle()' previously defined here 
21 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h invalid types `int[int]' for array subscript 
22 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h invalid types `int[int]' for array subscript 
25 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h invalid types `int[int]' for array subscript 
28 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h invalid types `int[int]' for array subscript 
28 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h invalid types `int[int]' for array subscript 
34 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h `ySNEBULA' undeclared (first use this function) 
  (Each undeclared identifier is reported only once for each function it appears in.) 
 C:\Dev-Cpp\Projects\Project 3\Space Quest\Makefile.win [Build Error]  [main.o] Error 1  

I know this is simple but each time i post about Allegro on the Beginners forum there are no replys. So I'm hoping you can help out.
~ Thanks...
Well i corrected mos i can, here it is =/
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
// BACKROUND.h
#define BACKROUND_H
BITMAP *NEBULA;
BITMAP *NEBULADELETE;

int NEBULAx = 10;
int NEBULAy = 10;

int dirNEBULA = 1; //This will keep track of the circles direction
                        //1= Down
                        
void moveCircle()
{
    if (dirNEBULA == 1)
       for (int i = 0; i<10; i++)
       {
           
           if (NEBULAy>500)
             NEBULAy = - 100;
           else
           {
               NEBULAy = NEBULAy + 5;
           }
    
           acquire_screen();
           NEBULA = load_bitmap( "NEBULA.bmp", NULL);
           NEBULADELETE = load_bitmap( "NEBULADELETE.bmp", NULL);
           draw_sprite( screen, NEBULA, NEBULAx, NEBULAy);
           draw_sprite( screen, NEBULADELETE, NEBULAx, NEBULAy);
           /* circlefill ( screen, tempX, tempY, 20, makecol( 0, 0, 0)); */
           /* circlefill ( screen, x, y, 20, makecol( 128, 255, 0)); */
           
           release_screen();           
        }
     rest(10);
} 

errors:
1
2
3
4
5
8 C:\Dev-Cpp\Projects\Project 3\Space Quest\main.cpp In file included from main.cpp 
 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h In function `void moveCircle()': 
13 C:\Dev-Cpp\Projects\Project 3\Space Quest\NEBULA.h redefinition of `void moveCircle()' 
16 C:\Dev-Cpp\Projects\Project 3\Space Quest\SHOOTINGSTAR.h `void moveCircle()' previously defined here 
 C:\Dev-Cpp\Projects\Project 3\Space Quest\Makefile.win [Build Error]  [main.o] Error 1  
-_- Bump...
Usually a question includes a question mark...
Either way... take a look at the error. It says you have redefined void moveCircle(). Or, in other words, the function has been declared more than once. To solve this, give each function a separate name.

Also, your include guards are wrong. This is not the cause of your error, but you should write it correctly either way. Include guards are done like this (make sure to replace the INCLUDEGUARDNAME):

1
2
3
4
5
6
#ifndef INCLUDEGUARDNAME
#define INCLUDEGUARDNAME

... {your code here} ...

#endif 
Topic archived. No new replies allowed.