Multiple files

I am using dev c++ and the allegro library. Im makeing a simple game however i
need to figure out how to make a program with multiple cpp files. So, how do i do it? I thought u make ur main, make a header file, make the other cpp file, and say #include <(name of header file)> in the main cpp file. Is this right, because it doesnt work for me.

google has not helped me, as i get indefinite results...
For Dev C++ check under Window -> List and make sure that all of your files are included in the project. If any of them aren't then add them through Project -> Add To Project. This is the most common problem anyway, if it's not what you are experiancing then we'll need to see some error codes.
Okay, when i say "it doesnt work for me" I realy mean, I have no idea what im doing...

heres my main code...

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
/*
  Name: Widget360 
  Copyright: 2011
  Author: Widget360
  Date: 07/04/11 14:09
  Description: My First Game
*/

#include <allegro.h>
// main
int main(int argc, char *argv[])
{
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode(GFX_AUTODETECT, 1280,800,0,0);
    // background
    BITMAP *Intro_Background = load_bitmap("C:/Users/Widget360/Documents/projects/My First Game/Images/Intro_Background.bmp", NULL);
    // sprite
    BITMAP *Intro_Sprite = load_bitmap("C:/Users/Widget360/Documents/projects/My First Game/Images/Intro_Sprite.bmp", NULL);
    // buffer
    BITMAP *Intro_Buffer = create_bitmap(1280,800);
    // check
    int Intro_Check = 1;
    int Intro_Check_Main = 1;
    int Intro_Start_Top = 400;
    int Intro_Start_Bottom = 300;
    int Intro_Start_Right = 1000;
    int Intro_Start_Left = 750;
    int Intro_Quit_Top = 600;
    int Intro_Quit_Bottom = 500;
    int Intro_Quit_Left = 750;
    int Intro_Quit_Right = 1000;
    int Intro_Sprite_X = 0;
    int Intro_Sprite_Y = 0;
    // main intro loop
    while (Intro_Check != 0)
    {
        while (Intro_Check_Main != 0)
        {
            if(key[KEY_RIGHT])
            {
                Intro_Sprite_X ++;
            }
            if (key[KEY_LEFT])
            {
                Intro_Sprite_X --;
            }
            if (key[KEY_UP])
            {
                Intro_Sprite_Y --;
            }
            if (key[KEY_DOWN])
            {
                Intro_Sprite_Y ++;
            }
            // show buffer
            blit(Intro_Background, Intro_Buffer, 0, 0, 0, 0, 1280, 800);
            draw_sprite(Intro_Buffer, Intro_Sprite, Intro_Sprite_X, Intro_Sprite_Y);
            blit(Intro_Buffer,screen,0,0,0,0, 1280, 800);
            // start - boundries
            if (Intro_Sprite_X >= Intro_Start_Left && Intro_Sprite_X <= Intro_Start_Right)
            {
                if (Intro_Sprite_Y >= Intro_Start_Bottom && Intro_Sprite_Y <= Intro_Start_Top)
                {
                    Intro_Check = 0;
                    Intro_Check_Main = 0;
                }
            }
            // quit - boundries
            if (Intro_Sprite_X >= Intro_Quit_Left && Intro_Sprite_X <= Intro_Quit_Right)
            {
                if (Intro_Sprite_Y >=  Intro_Quit_Bottom && Intro_Sprite_Y <= Intro_Quit_Top)
                {
                    allegro_message("Game Quit");
                    exit(EXIT_FAILURE);
                }
            }
        }
    }
    // clean up
    destroy_bitmap(Intro_Background);
    destroy_bitmap(Intro_Buffer);
    destroy_bitmap(Intro_Sprite);
}
END_OF_MAIN()


where i Have

1
2
3
4
5
6
7
8
if (Intro_Sprite_X >= Intro_Start_Left && Intro_Sprite_X <= Intro_Start_Right)
            {
                if (Intro_Sprite_Y >= Intro_Start_Bottom && Intro_Sprite_Y <= Intro_Start_Top)
                {
                    Intro_Check = 0;
                    Intro_Check_Main = 0;
                }
            }


I would have it run this cpp if true... How do I do that...
closed account (D80DSL3A)
For a file in your own project it's #include "fname.h" not #include <fname.h> . Hope that's the problem.
I dont get any compiling issues. Now instead of having a header, i included a cpp file. Is that ok are do you have to have a header to add a cpp file?
oh, also. Now that i have included it, how do i run it. I want it to completley closed down the first and go to the next.
You should not be including a header source (cpp) file. Could you elaborate on the problem a bit more? I'm not sure what specifically is wrong. Copying the compiler/linker/runtime error message(s) would be helpful.
Last edited on
.cpp files included into your project are normally just functions for your header files. They aren't meant to be seperate stand alone applications, they COULD be, but there are a half dozen better ways to do that.

@ Zhuge: Why shouldn't he include a header file? This is his programs entry point, not the other app right?
Apologies, I made a typo. I meant to say "source" file, as the OP said:
Now instead of having a header, i included a cpp file.

(Fixed in original post)
Topic archived. No new replies allowed.