Alegro closes out on me

This is a discussion on Alegro closes out on me within the C++ Programming forums, part of the General Programming Boards category; I am having trouble with allegro, when I complie the program, I dont get any errors, but when I run ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Planet X
    Posts
    12

    Alegro closes out on me

    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:
    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();
    I have attached my files I used (main file, header file, datafile)

    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
    Attached Files Attached Files

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > void main(void)
    main returns an int

    > while(key[KEY_ESC])
    So where are you reading a key?
    Seems to me it just happens to stumble on the exit condtion
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Planet X
    Posts
    12
    Quote Originally Posted by Salem
    > void main(void)
    main returns an int

    > while(key[KEY_ESC])
    So where are you reading a key?
    Seems to me it just happens to stumble on the exit condtion
    I am reading the 'while(key[KEY_ESC])' in 'int main'

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    But key[KEY_ESC] is just a reference to an element of an array with no obvious sign of how that array gets modified.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Location
    Planet X
    Posts
    12
    Quote Originally Posted by Salem
    But key[KEY_ESC] is just a reference to an element of an array with no obvious sign of how that array gets modified.
    ok, the program is set to loop while quit=0, my program will loop. if you press the ESC key. you get a message asking if you are sure you want to quit. if you let go of the esc key, the while(key[KEY_ESC]) loop ends, continuing the program, but if you click 'y' while pressing the esc key, quit will 1 and it will break out of the main loop ending the program. I have used this setup many times like in this program, which works:

    Code:
    #include <conio.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include "allegro.h"
    
    #define WHITE makecol(255,255,255)
    
    BITMAP *buffer;
    BITMAP *back;
    
    int quit=0;
    int off_set;
    int off_width;
    int off_height;
    int cur_x;
    int life=3;
    int left_side;
    int right_side;
    int movement=1;
    int explosion_test=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;
    	}SPRITE;
    
    //r_bee variables
    BITMAP *r_bee_img[12];
    SPRITE r_bee_struct[16];
    SPRITE *r_bee[16];
    char r_bee_char[100];
    
    //b_bee variables
    BITMAP *b_bee_img[12];
    SPRITE b_bee_struct[20];
    SPRITE *b_bee[20];
    char b_bee_char[100];
    
    //enemy variables
    BITMAP *b_ship_img[12];
    BITMAP *g_ship_img[12];
    SPRITE enemy_struct[4];
    SPRITE *enemy[4];
    char enemy_char[100];
    
    //ship variables
    BITMAP *w_ship_img[4];
    BITMAP *r_ship_img[4];
    SPRITE ship_struct[10];
    SPRITE *ship[10];
    char ship_char[100];
    
    //ship_shoot variables
    BITMAP *ship_shoot_img[2];
    SPRITE ship_shoot_struct[2];
    SPRITE *ship_shoot[2];
    char ship_shoot_char[2];
    
    /////////////////////////////////////r_bee//////////////////////////////////////////////////
    
    void update_r_bee(SPRITE *spr){
    
    	//update x position
    	if((++spr->xcount)>(spr->xdelay)){
    		spr->xcount=0;
    		spr->x+=spr->xspeed;
    	}
    
    	//update y position
    	if((++spr->ycount)>(spr->ydelay)){
    		spr->ycount=0;
    		spr->y+=spr->yspeed;
    	}
    
    	//update frame base on animdir
    	if((++spr->framecount)>(spr->framedelay)){
    		spr->framecount=0;
    
    		if(spr->animdir==4){
    			spr->animdir=0;
    			spr->curframe=6;
    		}
    		if(spr->animdir==3){
    			if((++spr->curframe)==11){
    				spr->curframe=9;
    			}
    		}
    		if(spr->animdir==2){
    			if((++spr->curframe)==2){
    				spr->animdir=3;
    				spr->curframe=9;
    				spr->xspeed=(-4);
    			}
    		}
    		if(spr->animdir==1){
    			if((++spr->curframe)==5){
    				spr->curframe=3;
    			}
    		}
    		if(spr->animdir==0){
    			if((++spr->curframe)==3){
    				spr->curframe=0;
    				spr->xspeed=0;
    				spr->yspeed=0;
    			}
    		}
    	}
    }
    
    void move_r_bee(SPRITE *spr){
    
    	//simple screen bouncing behavior
    	if((spr->x)<0){
    		spr->x=0;
    		spr->xspeed=0;
    		spr->animdir=0;
    		spr->curframe=6;
    	}
    
    	if((spr->x)>(SCREEN_W-(spr->width))){
    		spr->x=SCREEN_W-(spr->width);
    		spr->xspeed=0;
    		spr->animdir=2;
    		spr->curframe=0;
    	}
    }
    
    /////////////////////////////////////b_bee//////////////////////////////////////////////////
    
    void update_b_bee(SPRITE *spr){
    
    	//update x position
    	if((++spr->xcount)>(spr->xdelay)){
    		spr->xcount=0;
    		spr->x+=spr->xspeed;
    	}
    
    	//update y position
    	if((++spr->ycount)>(spr->ydelay)){
    		spr->ycount=0;
    		spr->y+=spr->yspeed;
    	}
    
    	//update frame base on animdir
    	if((++spr->framecount)>(spr->framedelay)){
    		spr->framecount=0;
    
    		if(spr->animdir==4){
    			spr->animdir=0;
    			spr->curframe=6;
    		}
    		if(spr->animdir==3){
    			if((++spr->curframe)==11){
    				spr->curframe=9;
    			}
    		}
    		if(spr->animdir==2){
    			if((++spr->curframe)==2){
    				spr->animdir=3;
    				spr->curframe=9;
    				spr->xspeed=(-4);
    			}
    		}
    		if(spr->animdir==1){
    			if((++spr->curframe)==5){
    				spr->curframe=3;
    			}
    		}
    		if(spr->animdir==0){
    			if((++spr->curframe)==3){
    				spr->curframe=0;
    				spr->xspeed=0;
    				spr->yspeed=0;
    			}
    		}
    	}
    }
    
    void move_b_bee(SPRITE *spr){
    
    	//simple screen bouncing behavior
    	if((spr->x)<0){
    		spr->x=0;
    		spr->xspeed=0;
    		spr->animdir=0;
    		spr->curframe=6;
    	}
    
    	if((spr->x)>(SCREEN_W-(spr->width))){
    		spr->x=SCREEN_W-(spr->width);
    		spr->xspeed=0;
    		spr->animdir=2;
    		spr->curframe=0;
    	}
    }
    
    /////////////////////////////////////enemy//////////////////////////////////////////////////
    
    void update_enemy(SPRITE *spr){
    
    	//update x position
    	if((++spr->xcount)>(spr->xdelay)){
    		spr->xcount=0;
    		spr->x+=spr->xspeed;
    	}
    
    	//update y position
    	if((++spr->ycount)>(spr->ydelay)){
    		spr->ycount=0;
    		spr->y+=spr->yspeed;
    	}
    
    	//update frame base on animdir
    	if((++spr->framecount)>(spr->framedelay)){
    		spr->framecount=0;
    
    		if(spr->animdir==4){
    			spr->animdir=0;
    			spr->curframe=6;
    		}
    		if(spr->animdir==3){
    			if((++spr->curframe)==11){
    				spr->curframe=9;
    			}
    		}
    		if(spr->animdir==2){
    			if((++spr->curframe)==2){
    				spr->animdir=3;
    				spr->curframe=9;
    				spr->xspeed=(-4);
    			}
    		}
    		if(spr->animdir==1){
    			if((++spr->curframe)==5){
    				spr->curframe=3;
    			}
    		}
    		if(spr->animdir==0){
    			if((++spr->curframe)==3){
    				spr->curframe=0;
    				spr->xspeed=0;
    				spr->yspeed=0;
    			}
    		}
    	}
    }
    
    void move_enemy(SPRITE *spr){
    
    	if((spr->x)<0){
    		spr->x=0;
    		spr->xspeed=0;
    		spr->animdir=0;
    		spr->curframe=6;
    	}
    
    	if((spr->x)>(SCREEN_W-(spr->width))){
    		spr->x=SCREEN_W-(spr->width);
    		spr->xspeed=0;
    		spr->animdir=2;
    		spr->curframe=0;
    	}
    }
    
    /////////////////////////////////////ship///////////////////////////////////////////////////
    
    void update_ship(SPRITE *spr){
    
    	//update x position
    	if((++spr->xcount)>(spr->xdelay)){
    		spr->xcount=0;
    		spr->x+=spr->xspeed;
    	}
    
    	//update y position
    	if((++spr->ycount)>(spr->ydelay)){
    		spr->ycount=0;
    		spr->y+=spr->yspeed;
    	}
    
    	//update frame base on animdir
    	if((++spr->framecount)>(spr->framedelay)){
    		spr->framecount=0;
    
    		if(spr->animdir==4){
    			spr->animdir=0;
    			spr->curframe=6;
    		}
    		if(spr->animdir==3){
    			if((++spr->curframe)==11){
    				spr->curframe=9;
    			}
    		}
    		if(spr->animdir==2){
    			if((++spr->curframe)==2){
    				spr->animdir=3;
    				spr->curframe=9;
    				spr->xspeed=(-4);
    			}
    		}
    		if(spr->animdir==1){
    			if((++spr->curframe)==1){
    				spr->curframe=1;
    			}
    		}
    		if(spr->animdir==0){
    		//	if((++spr->curframe)==0){
    				spr->curframe=0;
    				spr->xspeed=0;
    				spr->yspeed=0;
    		//	}
    		}
    	}
    }
    
    void move_ship(SPRITE *spr){
    
    	//simple screen bouncing behavior
    	if((spr->x)<0){
    		spr->x=0;
    		spr->xspeed=0;
    		spr->animdir=0;
    		spr->curframe=6;
    	}
    
    	if((spr->x)>(SCREEN_W-(spr->width))){
    		spr->x=SCREEN_W-(spr->width);
    		spr->xspeed=0;
    		spr->animdir=2;
    		spr->curframe=0;
    	}
    }
    
    //////////////////////////////////ship_shoot////////////////////////////////////////////////
    
    void update_ship_shoot(SPRITE *spr){
    
    	//update y position
    	if((++spr->ycount)>(spr->ydelay)){
    		spr->ycount=0;
    		spr->y+=spr->yspeed;
    	}
    
    	//update frame base on animdir
    	if((++spr->framecount)>(spr->framedelay)){
    		spr->framecount=0;
    
    		if(spr->animdir==1){
    			if((++spr->curframe)==1){
    				spr->curframe=0;
    				spr->y+=spr->yspeed;
    			}
    		}
    	}
    }
    
    void move_ship_shoot(SPRITE *spr){
    
    	if((spr->y)<0){
    		spr->stage=0;
    		spr->y=ship[life]->y;
    	}
    
    	if((spr->y)>0){
    		spr->yspeed=(-10);
    		spr->animdir=1;
    	}
    }
    
    void col_ship_shoot(SPRITE *spr){
    
    	for(int x=0;x<4;x++){
    		if(enemy[x]->stage==2){
    			if(((spr->y)<((enemy[x]->y)+(enemy[x]->height)))&&((spr->y)>(enemy[x]->y))&&((spr->x)<((enemy[x]->x)+(enemy[x]->width)))&&((spr->x)>(enemy[x]->x))){
    				enemy[x]->stage=0;
    				spr->y=0;
    				explosion_test=1;
    				return;
    			}
    		}
    		if(enemy[x]->stage==1){
    			if(((spr->y)<((enemy[x]->y)+(enemy[x]->height)))&&((spr->y)>(enemy[x]->y))&&((spr->x)<((enemy[x]->x)+(enemy[x]->width)))&&((spr->x)>(enemy[x]->x))){
    				enemy[x]->stage=2;
    				spr->y=0;
    				explosion_test=1;
    				return;
    			}
    		}
    	}
    
    	for(int x=0;x<12;x++){
    		if(r_bee[x]->stage==1){
    			if(((spr->y)<((r_bee[x]->y)+(r_bee[x]->height)))&&((spr->y)>(r_bee[x]->y))&&((spr->x)<((r_bee[x]->x)+(r_bee[x]->width)))&&((spr->x)>(r_bee[x]->x))){
    				r_bee[x]->stage=0;
    				spr->y=0;
    				explosion_test=1;
    				return;
    			}
    		}
    	}
    
    	for(int x=0;x<20;x++){
    		if(b_bee[x]->stage==1){
    			if(((spr->y)<((b_bee[x]->y)+(b_bee[x]->height)))&&((spr->y)>(b_bee[x]->y))&&((spr->x)<((b_bee[x]->x)+(b_bee[x]->width)))&&((spr->x)>(b_bee[x]->x))){
    				b_bee[x]->stage=0;
    				spr->y=0;
    				explosion_test=1;
    				return;
    			}
    		}
    	}
    }
    
    
    
    /////////////////////////////////check_left///////////////////////////////////////////////
    
    void check_left(SPRITE *enemy[],SPRITE *r_bee[],SPRITE *b_bee[]){
    
    	//col 1
    	if(b_bee[0]->stage==1){
    		left_side=b_bee[0]->x;
    		return;
    	}
    	if(b_bee[10]->stage==1){
    		left_side=b_bee[10]->x;
    		return;
    	}
    	//col 2
    	if(r_bee[0]->stage==1){
    		left_side=r_bee[0]->x;
    		return;
    	}
    	if(r_bee[8]->stage==1){
    		left_side=b_bee[8]->x;
    		return;
    	}
    	if(b_bee[1]->stage==1){
    		left_side=b_bee[1]->x;
    		return;
    	}
    	if(b_bee[11]->stage==1){
    		left_side=b_bee[11]->x;
    		return;
    	}
    	//col 3
    	if(r_bee[1]->stage==1){
    		left_side=r_bee[1]->x;
    		return;
    	}
    	if(r_bee[9]->stage==1){
    		left_side=b_bee[9]->x;
    		return;
    	}
    	if(b_bee[2]->stage==1){
    		left_side=b_bee[2]->x;
    		return;
    	}
    	if(b_bee[12]->stage==1){
    		left_side=b_bee[12]->x;
    		return;
    	}
    	//col 4
    	if(enemy[0]->stage==1){
    		left_side=enemy[0]->x;
    		return;
    	}
    	if(enemy[0]->stage==2){
    		left_side=enemy[0]->x;
    		return;
    	}
    	if(r_bee[2]->stage==1){
    		left_side=r_bee[2]->x;
    		return;
    	}
    	if(r_bee[10]->stage==1){
    		left_side=b_bee[10]->x;
    		return;
    	}
    	if(b_bee[3]->stage==1){
    		left_side=b_bee[3]->x;
    		return;
    	}
    	if(b_bee[13]->stage==1){
    		left_side=b_bee[13]->x;
    		return;
    	}
    	//col 5
    	if(enemy[1]->stage==1){
    		left_side=enemy[1]->x;
    		return;
    	}
    	if(enemy[1]->stage==2){
    		left_side=enemy[1]->x;
    		return;
    	}
    	if(r_bee[3]->stage==1){
    		left_side=r_bee[3]->x;
    		return;
    	}
    	if(r_bee[11]->stage==1){
    		left_side=b_bee[11]->x;
    		return;
    	}
    	if(b_bee[4]->stage==1){
    		left_side=b_bee[4]->x;
    		return;
    	}
    	if(b_bee[14]->stage==1){
    		left_side=b_bee[14]->x;
    		return;
    	}
    	//col 6
    	if(enemy[2]->stage==1){
    		left_side=enemy[2]->x;
    		return;
    	}
    	if(enemy[2]->stage==2){
    		left_side=enemy[2]->x;
    		return;
    	}
    	if(r_bee[4]->stage==1){
    		left_side=r_bee[4]->x;
    		return;
    	}
    	if(r_bee[10]->stage==1){
    		left_side=b_bee[12]->x;
    		return;
    	}
    	if(b_bee[5]->stage==1){
    		left_side=b_bee[5]->x;
    		return;
    	}
    	if(b_bee[15]->stage==1){
    		left_side=b_bee[15]->x;
    		return;
    	}
    	//col 7
    	if(enemy[3]->stage==1){
    		left_side=enemy[3]->x;
    		return;
    	}
    	if(enemy[3]->stage==2){
    		left_side=enemy[3]->x;
    		return;
    	}
    	if(r_bee[5]->stage==1){
    		left_side=r_bee[5]->x;
    		return;
    	}
    	if(r_bee[13]->stage==1){
    		left_side=b_bee[13]->x;
    		return;
    	}
    	if(b_bee[6]->stage==1){
    		left_side=b_bee[6]->x;
    		return;
    	}
    	if(b_bee[16]->stage==1){
    		left_side=b_bee[16]->x;
    		return;
    	}
    	//col 8
    	if(r_bee[6]->stage==1){
    		left_side=r_bee[6]->x;
    		return;
    	}
    	if(r_bee[14]->stage==1){
    		left_side=b_bee[14]->x;
    		return;
    	}
    	if(b_bee[7]->stage==1){
    		left_side=b_bee[7]->x;
    		return;
    	}
    	if(b_bee[17]->stage==1){
    		left_side=b_bee[17]->x;
    		return;
    	}
    	//col 9
    	if(r_bee[7]->stage==1){
    		left_side=r_bee[7]->x;
    		return;
    	}
    	if(r_bee[15]->stage==1){
    		left_side=b_bee[15]->x;
    		return;
    	}
    	if(b_bee[8]->stage==1){
    		left_side=b_bee[8]->x;
    		return;
    	}
    	if(b_bee[18]->stage==1){
    		left_side=b_bee[18]->x;
    		return;
    	}
    	//col 10
    	if(b_bee[9]->stage==1){
    		left_side=b_bee[9]->x;
    		return;
    	}
    	if(b_bee[19]->stage==1){
    		left_side=b_bee[19]->x;
    		return;
    	}
    }
    
    /////////////////////////////////check_right//////////////////////////////////////////////
    
    void check_right(SPRITE *enemy[],SPRITE *r_bee[],SPRITE *b_bee[]){
    
    	//col 1
    	if(b_bee[9]->stage==1){
    		right_side=((b_bee[9]->x)+(b_bee[9]->width));
    		return;
    	}
    	if(b_bee[19]->stage==1){
    		right_side=((b_bee[19]->x)+(b_bee[19]->width));
    		return;
    	}
    	//col 2
    	if(r_bee[7]->stage==1){
    		right_side=((r_bee[7]->x)+(r_bee[7]->width));
    		return;
    	}
    	if(r_bee[15]->stage==1){
    		right_side=((b_bee[15]->x)+(r_bee[7]->width));
    		return;
    	}
    	if(b_bee[8]->stage==1){
    		right_side=((b_bee[8]->x)+(r_bee[7]->width));
    		return;
    	}
    	if(b_bee[18]->stage==1){
    		right_side=((b_bee[18]->x)+(b_bee[18]->width));
    		return;
    	}
    	//col 3
    	if(r_bee[6]->stage==1){
    		right_side=((r_bee[6]->x)+(r_bee[6]->width));
    		return;
    	}
    	if(r_bee[14]->stage==1){
    		right_side=((b_bee[14]->x)+(b_bee[14]->width));
    		return;
    	}
    	if(b_bee[7]->stage==1){
    		right_side=((b_bee[7]->x)+(b_bee[7]->width));
    		return;
    	}
    	if(b_bee[17]->stage==1){
    		right_side=((b_bee[17]->x)+(b_bee[17]->width));
    		return;
    	}
    	//col 4
    	if(enemy[3]->stage==1){
    		right_side=((enemy[3]->x)+(enemy[3]->width));
    		return;
    	}
    	if(enemy[3]->stage==2){
    		right_side=((enemy[3]->x)+(enemy[3]->width));
    		return;
    	}
    	if(r_bee[5]->stage==1){
    		right_side=((r_bee[5]->x)+(r_bee[5]->width));
    		return;
    	}
    	if(r_bee[13]->stage==1){
    		right_side=((b_bee[13]->x)+(b_bee[13]->width));
    		return;
    	}
    	if(b_bee[6]->stage==1){
    		right_side=((b_bee[6]->x)+(b_bee[6]->width));
    		return;
    	}
    	if(b_bee[16]->stage==1){
    		right_side=((b_bee[16]->x)+(b_bee[16]->width));
    		return;
    	}
    	//col 5
    	if(enemy[2]->stage==1){
    		right_side=((enemy[2]->x)+(enemy[2]->width));
    		return;
    	}
    	if(enemy[2]->stage==2){
    		right_side=((enemy[2]->x)+(enemy[2]->width));
    		return;
    	}
    	if(r_bee[4]->stage==1){
    		right_side=((r_bee[4]->x)+(r_bee[4]->width));
    		return;
    	}
    	if(r_bee[10]->stage==1){
    		right_side=((b_bee[12]->x)+(b_bee[12]->width));
    		return;
    	}
    	if(b_bee[5]->stage==1){
    		right_side=((b_bee[5]->x)+(b_bee[5]->width));
    		return;
    	}
    	if(b_bee[15]->stage==1){
    		right_side=((b_bee[15]->x)+(b_bee[15]->width));
    		return;
    	}
    	//col 6
    	if(enemy[1]->stage==1){
    		right_side=((enemy[1]->x)+(enemy[1]->width));
    		return;
    	}
    	if(enemy[1]->stage==2){
    		right_side=((enemy[1]->x)+(enemy[1]->width));
    		return;
    	}
    	if(r_bee[3]->stage==1){
    		right_side=((r_bee[3]->x)+(r_bee[3]->width));
    		return;
    	}
    	if(r_bee[11]->stage==1){
    		right_side=((b_bee[11]->x)+(b_bee[11]->width));
    		return;
    	}
    	if(b_bee[4]->stage==1){
    		right_side=((b_bee[4]->x)+(b_bee[4]->width));
    		return;
    	}
    	if(b_bee[14]->stage==1){
    		right_side=((b_bee[14]->x)+(b_bee[14]->width));
    		return;
    	}
    	//col 7
    	if(enemy[0]->stage==1){
    		right_side=((enemy[0]->x)+(enemy[0]->width));
    		return;
    	}
    	if(enemy[0]->stage==2){
    		right_side=((enemy[0]->x)+(enemy[0]->width));
    		return;
    	}
    	if(r_bee[2]->stage==1){
    		right_side=((r_bee[2]->x)+(r_bee[2]->width));
    		return;
    	}
    	if(r_bee[10]->stage==1){
    		right_side=((b_bee[10]->x)+(b_bee[10]->width));
    		return;
    	}
    	if(b_bee[3]->stage==1){
    		right_side=((b_bee[3]->x)+(b_bee[3]->width));
    		return;
    	}
    	if(b_bee[13]->stage==1){
    		right_side=((b_bee[13]->x)+(b_bee[13]->width));
    		return;
    	}
    	//col 8
    	if(r_bee[1]->stage==1){
    		right_side=((r_bee[1]->x)+(r_bee[1]->width));
    		return;
    	}
    	if(r_bee[9]->stage==1){
    		right_side=((b_bee[9]->x)+(b_bee[9]->width));
    		return;
    	}
    	if(b_bee[2]->stage==1){
    		right_side=((b_bee[2]->x)+(b_bee[2]->width));
    		return;
    	}
    	if(b_bee[12]->stage==1){
    		right_side=((b_bee[12]->x)+(b_bee[12]->width));
    		return;
    	}
    	//col 9
    	if(r_bee[0]->stage==1){
    		right_side=((r_bee[0]->x)+(r_bee[0]->width));
    		return;
    	}
    	if(r_bee[8]->stage==1){
    		right_side=((b_bee[8]->x)+(b_bee[8]->width));
    		return;
    	}
    	if(b_bee[1]->stage==1){
    		right_side=((b_bee[1]->x)+(b_bee[1]->width));
    		return;
    	}
    	if(b_bee[11]->stage==1){
    		right_side=((b_bee[11]->x)+(b_bee[11]->width));
    		return;
    	}
    	//col 10
    	if(b_bee[0]->stage==1){
    		right_side=((b_bee[0]->x)+(b_bee[0]->width));
    		return;
    	}
    	if(b_bee[10]->stage==1){
    		right_side=((b_bee[10]->x)+(b_bee[10]->width));
    		return;
    	}
    }
    
    ////////////////////////////////////SETUP/////////////////////////////////////////////////
    
    int main(){
    
    	//initialize program
    	allegro_init();
    	set_color_depth(16);
    	set_gfx_mode(GFX_AUTODETECT_FULLSCREEN,640,480,0,0);
    	srand(time(NULL));
    	install_keyboard();
    	install_timer();
    	install_mouse();
    
    //	//install a digital sound driver
    //	if(install_sound(DIGI_AUTODETECT,MIDI_NONE,"")!=0){
    //		allegro_message("Error initializing the sound system");
    //		return 0;
    //	}
    
     	//load the background image
    	back=load_bitmap("background.bmp",NULL);
    
    	//set off_sets
    	off_set=((SCREEN_W-(back->w))/2);
    	off_width=back->w;
    	off_height=back->h;
    
    	//create a secondary screen buffer
    	buffer=create_bitmap(off_width,off_height);
    
    	//load the r_bee image
    	for(int x=0;x<12;x++){
    		sprintf(r_bee_char,"r_bee(%d).bmp",x);
    		r_bee_img[x]=load_bitmap(r_bee_char,NULL);
    	}
    
    	//initialize the r_bee variables
    	for(int x=0;x<16;x++){
    		r_bee[x]=&r_bee_struct[x];
    		r_bee[x]->x=0;
    		r_bee[x]->y=0;
    		r_bee[x]->width=r_bee_img[0]->w;
    		r_bee[x]->height=r_bee_img[0]->h;
    		r_bee[x]->xdelay=0;
    		r_bee[x]->ydelay=0;
    		r_bee[x]->xcount=0;
    		r_bee[x]->ycount=0;
    		r_bee[x]->xspeed=0;
    		r_bee[x]->yspeed=0;
    		r_bee[x]->curframe=0;
    		r_bee[x]->maxframe=11;
    		r_bee[x]->framecount=0;
    		r_bee[x]->framedelay=10;
    		r_bee[x]->animdir=0;
    		r_bee[x]->stage=1;
    		r_bee[x]->act=0;
    	}
    
    	for(int x=0;x<16;x++){
    		if(x<8){
    			if(x==0){
    				r_bee[x]->x=80;
    				r_bee[x]->y=100;
    			}
    			if(x>0){
    				r_bee[x]->x=((r_bee[x-1]->x)+10+(r_bee[x]->width));
    				r_bee[x]->y=100;
    			}
    		}
    		if(x>7){
    			if(x==8){
    				r_bee[x]->x=80;
    				r_bee[x]->y=(100+10+(r_bee[x]->width));
    			}
    			if(x>8){
    				r_bee[x]->x=((r_bee[x-1]->x)+10+(r_bee[x]->width));
    				r_bee[x]->y=(100+10+(r_bee[x]->width));
    			}
    		}
    	}
    
    		//load the b_bee image
    		for(int x=0;x<12;x++){
    			sprintf(b_bee_char,"b_bee(%d).bmp",x);
    			b_bee_img[x]=load_bitmap(b_bee_char,NULL);
    	}
    
    		//initialize the b_bee variables
    		for(int x=0;x<20;x++){
    			b_bee[x]=&b_bee_struct[x];
    			b_bee[x]->x=0;
    			b_bee[x]->y=0;
    			b_bee[x]->width=b_bee_img[0]->w;
    			b_bee[x]->height=b_bee_img[0]->h;
    			b_bee[x]->xdelay=0;
    			b_bee[x]->ydelay=0;
    			b_bee[x]->xcount=0;
    			b_bee[x]->ycount=0;
    			b_bee[x]->xspeed=0;
    			b_bee[x]->yspeed=0;
    			b_bee[x]->curframe=0;
    			b_bee[x]->maxframe=11;
    			b_bee[x]->framecount=0;
    			b_bee[x]->framedelay=10;
    			b_bee[x]->animdir=0;
    			b_bee[x]->stage=1;
    			b_bee[x]->act=0;
    		}
    
    		for(int x=0;x<20;x++){
    			if(x<10){
    				if(x==0){
    					b_bee[x]->x=52;
    					b_bee[x]->y=((r_bee[8]->y)+(r_bee[8]->height)+10);
    				}
    				if(x>0){
    					b_bee[x]->x=((b_bee[x-1]->x)+10+(b_bee[x]->width));
    					b_bee[x]->y=((r_bee[8]->y)+(r_bee[8]->height)+10);
    				}
    			}
    			if(x>9){
    				if(x==10){
    					b_bee[x]->x=52;
    					b_bee[x]->y=((b_bee[x-10]->y)+(b_bee[x-10]->height)+10);
    				}
    				if(x>10){
    					b_bee[x]->x=((b_bee[x-1]->x)+10+(b_bee[x]->width));
    					b_bee[x]->y=((b_bee[x-10]->y)+(b_bee[x-10]->height)+10);
    				}
    			}
    		}
    
    		//load the enemy image
    		for(int x=0;x<12;x++){
    			sprintf(enemy_char,"b_ship(%d).bmp",x);
    			b_ship_img[x]=load_bitmap(enemy_char,NULL);
    		}
    		for(int x=0;x<12;x++){
    			sprintf(enemy_char,"g_ship(%d).bmp",x);
    			g_ship_img[x]=load_bitmap(enemy_char,NULL);
    		}
    
    		//initialize the enemy variables
    		for(int x=0;x<4;x++){
    			enemy[x]=&enemy_struct[x];
    			enemy[x]->x=0;
    			enemy[x]->y=0;
    			enemy[x]->width=b_ship_img[0]->w;
    			enemy[x]->height=b_ship_img[0]->h;
    			enemy[x]->xdelay=0;
    			enemy[x]->ydelay=0;
    			enemy[x]->xcount=0;
    			enemy[x]->ycount=0;
    			enemy[x]->xspeed=0;
    			enemy[x]->yspeed=0;
    			enemy[x]->curframe=0;
    			enemy[x]->maxframe=11;
    			enemy[x]->framecount=0;
    			enemy[x]->framedelay=10;
    			enemy[x]->animdir=0;
    			enemy[x]->stage=1;
    			enemy[x]->act=0;
    		}
    
    		for(int x=0;x<4;x++){
    			if(x==0){
    				enemy[x]->x=((r_bee[1]->x)+((enemy[x]->width)/3));
    				enemy[x]->y=((r_bee[1]->y)-(enemy[x]->height)-10);
    			}
    			if(x>0){
    				enemy[x]->x=((enemy[x-1]->x)+10+(enemy[x]->width));
    				enemy[x]->y=((r_bee[1]->y)-(enemy[x]->height)-10);
    			}
    		}
    
    		//load the ship image
    		for(int x=0;x<4;x++){
    			sprintf(ship_char,"w_ship(%d).bmp",x);
    			w_ship_img[x]=load_bitmap(ship_char,NULL);
    		}
    //		for(int x=0;x<4;x++){
    //			sprintf(ship_char,"r_ship(%d).bmp",x);
    //			r_ship_img[x]=load_bitmap(ship_char,NULL);
    //		}
    
    		//initialize the ship variables
    		for(int x=0;x<10;x++){
    			ship[x]=&ship_struct[x];
    			ship[x]->x=0;
    			ship[x]->y=0;
    			ship[x]->width=w_ship_img[0]->w;
    			ship[x]->height=w_ship_img[0]->h;
    			ship[x]->xdelay=0;
    			ship[x]->ydelay=0;
    			ship[x]->xcount=0;
    			ship[x]->ycount=0;
    			ship[x]->xspeed=0;
    			ship[x]->yspeed=0;
    			ship[x]->curframe=0;
    			ship[x]->maxframe=3;
    			ship[x]->framecount=0;
    			ship[x]->framedelay=10;
    			ship[x]->animdir=0;
    			ship[x]->stage=1;
    			ship[x]->act=0;
    		}
    
    		for(int x=0;x<10;x++){
    			if(x<3){
    				if(x==0){
    					ship[x]->x=0;
    					ship[x]->y=(off_height-(ship[x]->height));
    				}
    				if(x>0){
    					ship[x]->x=((ship[x-1]->x)+10+(ship[x]->width));
    					ship[x]->y=(off_height-(ship[x]->height));
    				}
    				ship[x]->stage=1;
    			}
    			if(x==3){
    				ship[x]->x=((off_width/2)-((ship[x]->width)/2));
    				ship[x]->y=(off_height-((ship[x]->height)*2));
    			}
    			if(x>3){
    				ship[x]->stage=0;
    			}
    		}
    
    		cur_x=ship[life]->x;
    
    		//load the ship_shoot image
    		for(int x=0;x<2;x++){
    			sprintf(ship_shoot_char,"ship_shoot(%d).bmp",x);
    			ship_shoot_img[x]=load_bitmap(ship_shoot_char,NULL);
    		}
    
    		//initialize the ship_shoot variables
    		for(int x=0;x<2;x++){
    			ship_shoot[x]=&ship_shoot_struct[x];
    			ship_shoot[x]->x=0;
    			ship_shoot[x]->y=0;
    			ship_shoot[x]->width=ship_shoot_img[0]->w;
    			ship_shoot[x]->height=ship_shoot_img[0]->h;
    			ship_shoot[x]->xdelay=0;
    			ship_shoot[x]->ydelay=10;
    			ship_shoot[x]->xcount=0;
    			ship_shoot[x]->ycount=0;
    			ship_shoot[x]->xspeed=0;
    			ship_shoot[x]->yspeed=0;
    			ship_shoot[x]->curframe=0;
    			ship_shoot[x]->maxframe=3;
    			ship_shoot[x]->framecount=0;
    			ship_shoot[x]->framedelay=10;
    			ship_shoot[x]->animdir=0;
    			ship_shoot[x]->stage=0;
    			ship_shoot[x]->act=0;
    		}
    
    		for(int x=0;x<2;x++){
    			ship_shoot[x]->y=ship[life]->y;
    		}
    
    ////////////////////////////////////SOUND/////////////////////////////////////////////////
    
    //		int volume=128;
    //		int pan=128;
    //		int pitch=1000;
    //
    //		//start
    //		SAMPLE *start;
    //		start=load_sample("start.wav");
    //
    //		//explosion
    //		SAMPLE *explosion;
    //		explosion=load_sample("explosion.wav");
    
    
    ////////////////////////////////////START/////////////////////////////////////////////////
    
    	//wait to start
    	while(!key[KEY_SPACE]){
    		textprintf_centre(screen,font,SCREEN_W/2,SCREEN_H/2,WHITE,"Press Space Bar to Start");
    		if(key[KEY_ESC]){
    			return 0;
    		}
    	}
    
    //	play_sample(start,volume,pan,pitch,FALSE);
    
    ///////////////////////////////////MAIN LOOP//////////////////////////////////////////////
    
    	//main loop
    	while(quit==0){
    		//clear screen the slow way (redraw background)
    		blit(back,buffer,0,0,0,0,off_width,off_height);
    
    ///////////////////////////////////sides//////////////////////////////////////////////////
    
    		//figure left value
    		check_left(enemy,r_bee,b_bee);
    
    		//move left?
    		if(movement==2){
    			if((left_side-2)<1){
    				movement=1;
    			}
    			if((left_side-2)>1){
    				for(int x=0;x<16;x++){
    					(r_bee[x]->x)=((r_bee[x]->x)-2);
    				}
    				for(int x=0;x<20;x++){
    					(b_bee[x]->x)=((b_bee[x]->x)-2);
    				}
    				for(int x=0;x<4;x++){
    					(enemy[x]->x)=((enemy[x]->x)-2);
    				}
    			}
    		}
    
    		//figure right value
    		check_right(enemy,r_bee,b_bee);
    
    		//move right?
    		if(movement==1){
    			if((right_side+2)>off_width){
    				movement=2;
    			}
    			if((right_side+2)<off_width){
    				for(int x=0;x<16;x++){
    					(r_bee[x]->x)=((r_bee[x]->x)+2);
    				}
    				for(int x=0;x<20;x++){
    					(b_bee[x]->x)=((b_bee[x]->x)+2);
    				}
    				for(int x=0;x<4;x++){
    					(enemy[x]->x)=((enemy[x]->x)+2);
    				}
    			}
    		}
    
    ///////////////////////////////////r_bee//////////////////////////////////////////////////
    
    		for(int x=0;x<16;x++){
    			//Update r_bee position
    			update_r_bee(r_bee[x]);
    
    			//move r_bee?
    			move_r_bee(r_bee[x]);
    		}
    
    ///////////////////////////////////b_bee//////////////////////////////////////////////////
    
    		for(int x=0;x<20;x++){
    			//Update b_bee position
    			update_b_bee(b_bee[x]);
    
    			//move b_bee?
    			move_b_bee(b_bee[x]);
    		}
    
    ///////////////////////////////////enemy//////////////////////////////////////////////////
    
    		for(int x=0;x<4;x++){
    			//Update enemy position
    			update_enemy(enemy[x]);
    
    			//move enemy?
    			move_enemy(enemy[x]);
    		}
    
    ////////////////////////////////////ship//////////////////////////////////////////////////
    
    		if(key[KEY_P]){
    			while(!key[KEY_O]){
    				//nothing
    			}
    		}
    
    		if((key[KEY_LCONTROL])||(key[KEY_LCONTROL])){
    			for(int y=0;y<2;y++){
    				if(ship_shoot[y]->stage==0){
    					ship_shoot[y]->stage=1;
    					ship_shoot[y]->x=((ship[life]->x)+(((ship[life]->width)/2)-((ship_shoot[y]->width)/2)));
    					ship_shoot[y]->y=ship[life]->y;
    					ship_shoot[y]->curframe=0;
    					ship_shoot[y]->yspeed=(-10);
    					ship_shoot[y]->animdir=1;
    					break;
    				}
    			}
    		}
    
    		if(key[KEY_RCONTROL]){
    			for(int y=0;y<2;y++){
    				if(ship_shoot[y]->stage==0){
    					ship_shoot[y]->stage=1;
    					ship_shoot[y]->x=((ship[life]->x)+(((ship[life]->width)/2)-((ship_shoot[y]->width)/2)));
    					ship_shoot[y]->y=ship[life]->y;
    					ship_shoot[y]->curframe=0;
    					ship_shoot[y]->yspeed=(-10);
    					ship_shoot[y]->animdir=1;
    					break;
    				}
    			}
    		}
    
    		if(key[KEY_LEFT]){
    			if(cur_x-10>0){
    				cur_x=cur_x-10;
    				ship[life]->x=cur_x;
    			}
    		}
    
    		if(key[KEY_RIGHT]){
    			if((cur_x+10+(ship[life]->width))<off_width){
    				cur_x=cur_x+10;
    				ship[life]->x=cur_x;
    			}
    		}
    
    		for(int x=0;x<10;x++){
    			//Update ship position
    			update_ship(ship[x]);
    
    			//move ship?
    			move_ship(ship[x]);
    		}
    
    //////////////////////////////////ship_shoot////////////////////////////////////////////////
    
    		for(int x=0;x<2;x++){
    
    			if(ship_shoot[x]->stage==1){
    
    				//Update ship position
    				update_ship_shoot(ship_shoot[x]);
    
    				//move ship?
    				move_ship_shoot(ship_shoot[x]);
    
    				//check for collision
    				col_ship_shoot(ship_shoot[x]);
    			}
    		}
    
    //		if(explosion_test==1){
    //			play_sample(explosion,volume,pan,pitch,FALSE);
    //		}
    //		explosion_test=0;
    
    /////////////////////////////////////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 r_bee
    		for(int x=0;x<16;x++){
    			if((r_bee[x]->stage)==1){
    				draw_sprite(buffer,r_bee_img[r_bee[x]->curframe],r_bee[x]->x,r_bee[x]->y);
    			}
    		}
    
    		//draw the b_bee
    		for(int x=0;x<20;x++){
    			if((b_bee[x]->stage)==1){
    				draw_sprite(buffer,b_bee_img[b_bee[x]->curframe],b_bee[x]->x,b_bee[x]->y);
    			}
    		}
    
    		//draw the enemy
    		for(int x=0;x<4;x++){
    			if((enemy[x]->stage)==1){
    				draw_sprite(buffer,g_ship_img[enemy[x]->curframe],enemy[x]->x,enemy[x]->y);
    			}
    			if((enemy[x]->stage)==2){
    				draw_sprite(buffer,b_ship_img[enemy[x]->curframe],enemy[x]->x,enemy[x]->y);
    			}
    		}
    
    		//draw the ship
    		for(int x=0;x<10;x++){
    			if((ship[x]->stage)==1){
    				draw_sprite(buffer,w_ship_img[ship[x]->curframe],ship[x]->x,ship[x]->y);
    			}
    			if((ship[x]->stage)==2){
    				draw_sprite(buffer,r_ship_img[ship[x]->curframe],ship[x]->x,ship[x]->y);
    			}
    		}
    
    		//draw the ship_shoot
    		for(int x=0;x<2;x++){
    			if((ship_shoot[x]->stage)>0){
    				draw_sprite(buffer,ship_shoot_img[ship_shoot[x]->curframe],ship_shoot[x]->x,ship_shoot[x]->y);
    			}
    		}
    
    		//update the screen
    		blit(buffer,screen,0,0,off_set,0,off_width,off_height);
    
    		rest(10);
    	}
    
    	for(int x=0;x<12;x++){
    		destroy_bitmap(r_bee_img[x]);
    	}
    
    	for(int x=0;x<12;x++){
    		destroy_bitmap(b_bee_img[x]);
    	}
    
    	for(int x=0;x<12;x++){
    		destroy_bitmap(b_ship_img[x]);
    		destroy_bitmap(g_ship_img[x]);
    	}
    
    	for(int x=0;x<4;x++){
    		destroy_bitmap(r_ship_img[x]);
    		destroy_bitmap(w_ship_img[x]);
    	}
    
    	for(int x=0;x<2;x++){
    		destroy_bitmap(ship_shoot_img[x]);
    	}
    
    	destroy_bitmap(buffer);
    	destroy_bitmap(back);
    
    	//destroy_sample(start);
    	//destroy_sample(explosion);
    
    	return 0;
    }
    END_OF_MAIN();

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    How about producing a really small program which waits for a key press, rather than forging ahead with masses of code irrelevant to the problem.

    key[x] is a reference to an array
    key(x) is a function call.

    Where are you CALLING a function which gets the key state?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Location
    Planet X
    Posts
    12
    Quote Originally Posted by Salem
    How about producing a really small program which waits for a key press, rather than forging ahead with masses of code irrelevant to the problem.

    key[x] is a reference to an array
    key(x) is a function call.

    Where are you CALLING a function which gets the key state?
    I am using a refrence, not a function, how would I set it up to be a function?

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Ok, explain how your code is different to
    Code:
    int main ( ) {
      int key[10] = { 0 };
    #define KEY_SPACE 0
    #define KEY_ESC 1
    
    // snipped from your code
    while(!key[KEY_SPACE]){
    		textprintf_centre(screen,font,SCREEN_W/2,SCREEN_H/2,WHITE,"Press Space Bar to Start");
    		if(key[KEY_ESC]){
    			return 0;
    		}
    	}
    
    
    }
    It it pointless looking at an element of the key array if there is no way for anything to update entries in that key array. Either it does nothing or it loops forever.

    So unless there is some secret way of updating that array which isn't obvious from the code, it just isn't going to happen.

    Like I said, create an easy test program with just a few lines to check out the idea before burying it in 100's of lines of fluff which has nothing to do with how it responds to key presses (or not).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Jan 2006
    Location
    Planet X
    Posts
    12
    It might not seem like it works, but it does, check out this program which I use those sets of commands

    Thanks for your help, I appricate it, but Ive decided to scrap this method and redo the program without datafiles, which seem to be working better

    ~~Campsoup1988

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL app closes instantly
    By jmd15 in forum C++ Programming
    Replies: 2
    Last Post: 07-25-2006, 06:38 PM
  2. Program closes when startup form closes
    By dcboy in forum C# Programming
    Replies: 1
    Last Post: 07-01-2006, 02:40 AM
  3. Program closes prematurely. Help needed
    By strategicman in forum C++ Programming
    Replies: 3
    Last Post: 04-12-2006, 03:09 PM
  4. Dos Window closes after I press enter
    By ProgrammingDlux in forum C++ Programming
    Replies: 4
    Last Post: 01-24-2002, 11:13 AM
  5. dos closes right away after executing
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 01-18-2002, 02:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21