Sign in to follow this  
omfgkittenz

basic allegro multi-file problem PPPLZZZZ HELLLP

Recommended Posts

omfgkittenz    100
This is a basic three file program. All it does is move a player, the player's image is just a textout_ex -> @ but I am getting all these errors after i wrote the code for the player class.

------------------------main.cpp--------------------------------------------

#ifndef MAIN_CPP
#define MAIN_CPP
#include "player.h"
#include <allegro.h>


int bounding_box_collision ( int b1_x, int b1_y, int b1_w, int b1_h, int b2_x, int b2_y, int b2_w, int b2_h )
{
if ( ( b1_x > b2_x + b2_w - 1 )|| // is b1 on the right side of b2?
( b1_y > b2_y + b2_h - 1 )|| // is b1 under b2?
( b2_x > b1_x + b1_w - 1 )|| // is b2 on the right side of b1?
( b2_y > b1_y + b1_h - 1 ) ) // is b2 under b1?
{
// no collision
return 0;
}

// collision
return 1;
}


int main()
{
allegro_init();
install_keyboard();
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);

BITMAP *buffer = create_bitmap(640, 480);
clear_to_color(buffer, makecol(0,0,0));

while(!key[KEY_ESC])
{

draw_sprite(screen, buffer, 0, 0);
}
} END_OF_MAIN();

#endif

---------------------------player.h---------------------------------------

#ifndef PLAYER_H
#define PLAYER_H

class player{
public:
player();
~player();

void move();
void draw();
private:
int x;
int y;
}
#endif

------------------------------player.cpp-------------------------------------

#include <allegro.h>
#include "player.h"
#include "main.cpp"

player::player()
{
this.x = 500;
this.y = 240;
textout_ex(buffer, font, "@", this.x, this.y, makecol(255, 0, 0), makecol(0, 0, 0));
}
player:~player()
{
textout_ex(buffer, font, " ", this.x, this.y, makecol(0, 0, 0), makecol(0, 0, 0));
}

player::move()
{
if(key[KEY_UP]) this.y--;

if(key[KEY_LEFT]) this.x--;

if(key[KEY_DOWN]) this.y++;

if(key[KEY_RIGHT]) this.x++;
}

player::draw()
{
textout_ex(buffer, font, "@",this.x, this.y, makecol(255, 0, 0), makecol(0, 0, 0));
}





it gives my the following errors:
25 C:\DEV-CPP\include\allegro\base.h:24, from C:\DEV-CPP\include\allegro.h In file included from C:/DEV-CPP/include/allegro/base.h:24, from C:/DEV-CPP/include/allegro.h

4 C:\DEV-CPP\include\allegro.h:25, from main.cpp from C:/DEV-CPP/include/allegro.h:25, from main.cpp

4 C:\Users\Brandon\Documents\DEV\New folder\main.cpp from main.cpp

80 C:\DEV-CPP\include\errno.h expected unqualified-id before string constant

80 C:\DEV-CPP\include\errno.h expected `,' or `;' before string constant

C:\Users\Brandon\Documents\DEV\New folder\Makefile.win [Build Error] [main.o] Error 1

-end-



p.s. please give me any advice or pointers that oculd lead to all these errors being resolved :)
thanks!!

Share this post


Link to post
Share on other sites
MaulingMonkey    1730
Semicolon errors in headers that aren't yours usually hint that the problem is in whatever was #included in the translation unit before it. In this case, it's spot on the money: We #include player.h right before allegro.h, and what do you know, this is at the end of player.h:
class player{
...
}; <---- missing
Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this