Code: Select all
//Draw.cpp
#include "Draw.h"
int Draw::DrawMap(int flag, int i, int t)
{
if( flag == 1)
{
color = makecol( 128, 255, 255);
}
else if( flag == 2)
{
color = makecol( 255, 128, 0);
}
else if( flag == 3)
{
color = makecol( 255, 0, 0);
}
else if( flag == 4)
{
color = makecol( 0, 0, 0);
}
rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 40, color);
}
void Draw::SetBuffer()
{
Buffer = create_bitmap( 640, 480);
if(Buffer == NULL)
{
set_gfx_mode(GFX_TEXT,0,0,0,0);
allegro_message("Could not create buffer!");
exit(EXIT_FAILURE);
}
}
BITMAP* Draw::bBuffer()
{
return Buffer;
}
void Draw::DrawBuffer()
{
draw_sprite( screen, Buffer, 0, 0);
}
void Draw::DrawSprite(BITMAP* sprite, int x, int y)
{
masked_blit(sprite, Buffer, 0, 0, x, y, 172,64);
}
Code: Select all
//Draw.h
#include <allegro.h>
#ifndef DRAW_H
#define DRAW_H
class Draw
{
private:
BITMAP* Buffer;
int color;
public:
int DrawMap(int flag, int i, int t);
void SetBuffer();
BITMAP* bBuffer();
void DrawBuffer();
void DrawSprite(BITMAP* sprite, int x, int y);
};
#endif
Code: Select all
//Player.h
#include <allegro.h>
#ifndef PLAYER_H
#define PLAYER_H
class Player
{
private:
int playerx;
int playery;
BITMAP *Player_Sprite;
int Frame;
public:
void SetPlayer();
BITMAP* PlayerSprite();
int Player_X();
int Player_Y();
int Player_Frame();
};
#endif
Code: Select all
//Player.cpp
#include "Player.h"
void Player::SetPlayer()
{
Player_Sprite = load_bitmap("Snake.bmp", NULL);
if(Player_Sprite == NULL)
{
set_gfx_mode(GFX_TEXT,0,0,0,0); //Set the screen mode for allegro messages
allegro_message("Could not load Snake.bmp");
exit(EXIT_FAILURE);
}
playerx = 0;
playery = 0;
Frame = 0;
}
BITMAP* Player::PlayerSprite()
{
return Player_Sprite;
}
int Player::Player_X()
{
return playerx;
}
int Player::Player_Y()
{
return playery;
}
int Player::Player_Frame()
{
return Frame;
}
Code: Select all
//Main.cpp
#include "Player.h"
#include "Collision.h"
#include "Map.h"
#include "Draw.h"
void init();
void deinit();
int main()
{
init();
Player P;
Map m;
Draw D;
D.SetBuffer();
P.SetPlayer();
m.GetMap();
while (!key[KEY_ESC])
{
clear_keybuf();
clear_bitmap(D.bBuffer());
acquire_screen();
for (int r = 0; r < 12; r++)
{
for( int c = 0; c < 16; c++)
{
D.DrawMap(m.MapCoor(c, r), r, c);
}
}
D.DrawSprite(P.PlayerSprite(), P.Player_X(), P.Player_Y());
D.DrawBuffer();
release_screen();
rest(50);
}
deinit();
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
}
void deinit() {
clear_keybuf();
}
I think the problem is that Im not loading the Bitmap right...
Code: Select all
void Player::SetPlayer()
{
Player_Sprite = load_bitmap("Snake.bmp", NULL);
if(Player_Sprite == NULL)
{
set_gfx_mode(GFX_TEXT,0,0,0,0); //Set the screen mode for allegro messages
allegro_message("Could not load Snake.bmp");
exit(EXIT_FAILURE);
}
That should be working but its not... Or I can be wrong and its the draw function thats wrong
Code: Select all
void Draw::DrawSprite(BITMAP* sprite, int x, int y)
{
masked_blit(sprite, Buffer, 0, 0, x, y, 172,64);
}
I think Im gonna just forget Allegro and try SDL... sounds more easier... Unless some one gives me a reason to stay with Allegro...