Okay I have a two files here. A header file called types.hpp and main.cpp. Here is the contents of types.hpp:
Code:
/*
types.hpp
header file that defines all the types used in the game
*/
#include <allegro.h>
#pragma once
typedef BITMAP bmp;
typedef MIDI mid;
typedef DATAFILE dat;
//this is because i can't include the windows.h header because of the BITMAP
//redefinition
struct point{
int x;
int y;
};
The contents of main.cpp file are as follows:
Code:
/*
main.cpp
main file for the program
*/
#include <iostream>
#include <cstdlib>
#include <list>
#include "types.hpp"
#include "sprites.h"
//bat class
class bat{
private:
point position;
int lSide, rSide, middle, bbTop, bbLeft, bbRight, bbBottom;
dat *temp;
bmp *sprite;
public:
bat();
~bat();
void setX(int x){position.x = x;}
void setY(int y){position.y = y;}
void incX(int inc){position.x += inc;}
void incY(int inc){position.y += inc;}
void decX(int dec){position.x -= dec;}
void decY(int dec){position.y -= dec;}
int getX(){return position.x;}
int getY(){return position.y;}
int getLSide(){return lSide;}
int getRSide(){return rSide;}
int getMiddle(){return middle;}
int getBBTop(){return bbTop;}
int getBBLeft(){return bbLeft;}
int getBBRight(){return bbRight;}
int getBBBottom(){return bbBottom;}
bmp *getSprite(){return sprite;}
};
//ball class
class ball{
private:
point position;
int lSide, rSide, middle, bbTop, bbLeft, bbRight, bbBottom;
bmp *sprite;
dat *temp;
public:
ball();
~ball();
void setX(int x){position.x = x;}
void setY(int y){position.y = y;}
void incX(int inc){position.x += inc;}
void incY(int inc){position.y += inc;}
void decX(int dec){position.x -= dec;}
void decY(int dec){position.y -= dec;}
int getX(){return position.x;}
int getY(){return position.y;}
int getLSide(){return lSide;}
int getRSide(){return rSide;}
int getMiddle(){return middle;}
int getBBTop(){return bbTop;}
int getBBLeft(){return bbLeft;}
int getBBRight(){return bbRight;}
int getBBBottom(){return bbBottom;}
bmp *getSprite(){return sprite;}
};
//brick class
class brick{
private:
point position;
int lSide, rSide, middle, bbTop, bbLeft, bbRight, bbBottom, id;
static int idCounter;
public:
brick();
~brick();
void setX(int x){position.x = x;}
void setY(int y){position.y = y;}
void incIDCounter(){idCounter++;}
int getX(){return position.x;}
int getY(){return position.y;}
int getLSide(){return lSide;}
int getRSide(){return rSide;}
int getMiddle(){return middle;}
int getBBTop(){return bbTop;}
int getBBLeft(){return bbLeft;}
int getBBRight(){return bbRight;}
int getBBBottom(){return bbBottom;}
int getID(){return id;}
};
int main(){
allegro_init();
install_keyboard();
set_color_depth(24);
set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0);
//create the image back buffer
bmp *imgBackBuffer = create_bitmap(800, 600);
if(!imgBackBuffer){
allegro_message("Error creating the image back buffer. Program terminating.");
exit(1);
}
//create an isntance of the bat class
bat playerBat;
//main game loop
while(!key[KEY_ESC]){
//draw the bat sprite to the image back buffer
draw_sprite(screen, playerBat.getSprite(), playerBat.getX(), playerBat.getY());
//copy the contents of the image back buffer to the screen
blit(imgBackBuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
//clear the contents of the image back buffer
clear(imgBackBuffer);
}
//destroy the bitmaps and unload datafiles
destroy_bitmap(imgBackBuffer);
}
END_OF_MAIN();
//bat class constructor
bat :: bat(){
//load the datafile into memory so that the sprites can be used
temp = load_datafile("spritesDat.dat");
//load the bat sprite into the sprite private member
sprite = static_cast<bmp*>(temp[batSprite].dat);
//set the position of the bat
position.x = 50;
position.y = 50;
//set the other attributes of the bat class
//this allows for the appropriate information to be used
lSide = 0;
rSide = sprite->w;
middle = sprite->w / 2;
bbLeft = position.x;
bbTop = position.y;
bbRight = (bbLeft + sprite->w);
bbBottom = (bbTop + sprite->h);
//unload the datafile from memory
unload_datafile(temp);
}
//bat class destructor
bat :: ~bat(){
//destroy the sprites and set all vars to null
destroy_bitmap(sprite);
position.x = 0;
position.y = 0;
lSide = 0;
rSide = 0;
middle = 0;
bbLeft = 0;
bbTop = 0;
bbRight = 0;
bbBottom = 0;
}
//ball class constructor
ball :: ball(){
//use the bat constructor for a template
}
//ball class destructor
ball :: ~ball(){
//use the bat destructor for a template
}
//brick class constructor
brick :: brick(){}
//brick class destructor
brick :: ~brick(){}
The main problem isn't that the program compiles. The problem is that the bat sprite doesn't appear on the screen. Can someone help me with this?