I am having trouble with allegro, when I complie the program, I dont get any errors, but when I run the program, I see it open, but the next instant the program closes on me without any error messages, illegal acesses, esc.
Here is my main code:
I have attached my files I used (main file, header file, datafile)Code:#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include "allegro.h"
#include "background_dat.h"
#define WHITE makecol(255,255,255)
BITMAP *buffer;
int quit=0;
//define sprite structure
typedef struct SPRITE{
int x,y;
int width;
int height;
int xspeed;
int yspeed;
int xdelay;
int ydelay;
int xcount;
int ycount;
int curframe;
int maxframe;
int animdir;
int framecount;
int framedelay;
int stage;
int act;
BITMAP *bmp;
}SPRITE;
//setting background sprites
#define MAX_BACKGROUND 1
#define MAX_SPRITES 1
SPRITE background_struct[MAX_BACKGROUND][MAX_SPRITES];
SPRITE *background[MAX_BACKGROUND][MAX_SPRITES];
//Define Title
#define TITLE 0
#define TITLE_SPRITES_BEG_IMG 0
#define TITLE_SPRITES_END 1
void main(void){
DATAFILE *background_dat;
//initalize the program
allegro_init();
install_keyboard();
install_timer();
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT_FULLSCREEN,640,480,0,0);
text_mode(-1);
//load the datafile
background_dat=load_datafile("background_dat");
//initialize the Title variables
for(int x=0;x<TITLE_SPRITES_END;x++){
background[TITLE][x]=&background_struct[TITLE][x];
background[TITLE][x]->bmp=(BITMAP *)background_dat[TITLE_0_BMP].dat;
background[TITLE][x]->x=0;
background[TITLE][x]->y=0;
background[TITLE][x]->width=(background[TITLE][x]->bmp)->w;
background[TITLE][x]->height=(background[TITLE][x]->bmp)->h;
background[TITLE][x]->xdelay=0;
background[TITLE][x]->ydelay=0;
background[TITLE][x]->xcount=0;
background[TITLE][x]->ycount=0;
background[TITLE][x]->xspeed=0;
background[TITLE][x]->yspeed=0;
background[TITLE][x]->curframe=0;
background[TITLE][x]->maxframe=1;
background[TITLE][x]->framecount=0;
background[TITLE][x]->framedelay=10;
background[TITLE][x]->animdir=0;
background[TITLE][x]->stage=1;
background[TITLE][x]->act=0;
}
///////////////////////////////////MAIN LOOP//////////////////////////////////////////////
//main loop
while(quit==0){
//clear screen the slow way (redraw background)
//blit(back,buffer,0,0,0,0,360,480);
//display title
textout(buffer,font,"Super Mario Bros.(ESC to quit)",0,0,WHITE);
/////////////////////////////////////QUIT//////////////////////////////////////////////////
while(key[KEY_ESC]){
textprintf_centre(screen,font,SCREEN_W/2,(SCREEN_H/2)-15,WHITE,"Are you sure you want to quit?");
textprintf_centre(screen,font,SCREEN_W/2,(SCREEN_H/2)-5,WHITE,"Press 'Y' to quit");
textprintf_centre(screen,font,SCREEN_W/2,(SCREEN_H/2)+5,WHITE,"or");
textprintf_centre(screen,font,SCREEN_W/2,(SCREEN_H/2)+15,WHITE,"Press 'N' to resume");
if(key[KEY_Y]){
quit=1;
break;
}
if(key[KEY_N]){
break;
}
}
////////////////////////////////////UPDATE////////////////////////////////////////////////
//draw the Background
for(int x=0;x<MAX_SPRITES;x++){
if((background[TITLE][x]->stage)==1){
draw_sprite(buffer,background[TITLE][x]->bmp,background[TITLE][x]->x,background[TITLE][x]->y);
}
}
//update the screen
blit(buffer,screen,0,0,0,0,360,480);
rest(10);
}
//remove datafiles from memory
unload_datafile(background_dat);
allegro_exit();
}
END_OF_MAIN();
PS: I would attach my actual datafile, but the uploader wont support it, so I have a link to it from my site http://www.freewebs.com/01inuyashafa...ground_dat.dat