Original Post
I am making a game similar to missile defence so that I can become used to Allegro and whatnot. I wrote something up that generates a background and saves it to a bitmap, everything was going good until I added a class in a separate .cpp file. That's the tank class header and .cpp file. The program compiles fine, but this error is given when it runs: The instruction at "0x10020efc" referenced memory at "0x00000038". The memory could not be "read". Click on OK to terminate the program Click on CANCEL to debug the problem. Help, please?
[source lang = "cpp"]
/********************
* Tank Class Header*
********************/
#ifndef _TANK_H
#define _TANK_H
#define MAX_BULLETS 10
#define MOVE_LEFT 0
#define MOVE_RIGHT 1
#define TANK_W 100
#define TANK_H 35
#define CANNON_W 25
#define CANNON_H 50
class CTank
{
public:
CTank();
~CTank();
int x, y; // x and y coordinate of the player
int health; // health of the player
int reload; // reload time of the player
int score;
BITMAP *tank, *cannon; //bitmaps to hold the tank and cannon
void MoveTank(int dir);
void FireBullet();
};
#endif
[source lang = "cpp"]
/********************
* Tank Source File *
********************/
#include <allegro.h>
#include "tank.h"
CTank::CTank()
/* Sets up tank object */
{
x = (SCREEN_W/2); // init player
y = (SCREEN_H/4);
health = 100;
reload = 0;
score = 0;
tank = create_bitmap(TANK_W, TANK_H);
cannon = create_bitmap(CANNON_W, CANNON_H);
rectfill(tank, 10, 0, (TANK_W-10), TANK_H, makecol(45, 200, 60));
rect(tank, 10, 0, (TANK_W-10), TANK_H, makecol(60, 230, 70));
}
//--------------------------------------------
CTank::~CTank()
/* Deletes tank bmps */
{
destroy_bitmap(tank);
destroy_bitmap(cannon);
}
//--------------------------------------------
void CTank::MoveTank(int dir)
/* Moves tank */
{
if((dir == MOVE_LEFT) && (x < 0))
x -= 1;
else if((dir == MOVE_RIGHT) && ((x+TANK_W) > (SCREEN_W))
x += 1;
return;
}
//--------------------------------------------
void CTank::FireBullet()
{}
//--------------------------------------------