#define MAXFRAMES 6 #include #include"datafile.h" //Bitmaps BITMAP *virtScreen; BITMAP *cursor; PALETTE *gamePalette; DATAFILE *dataFile; struct FACE{ int x,y; float xvel,yvel; }; //Global constant stuff volatile int Speed_Ctr=0; void Inc_Speed_Ctr(){ //increments speed counter Speed_Ctr++; }END_OF_FUNCTION(Inc_Speed_Ctr); void moveFaceAround(struct FACE *face); void checkBulletHitHead(struct FACE *face); int main(){ struct FACE face={320,240,1,1}; srand(time(NULL)); allegro_init(); LOCK_VARIABLE(Speed_Ctr); LOCK_FUNCTION(Inc_Speed_Ctr); install_int(Inc_Speed_Ctr,5); install_keyboard(); install_mouse(); detect_digi_driver(DIGI_AUTODETECT); install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL); //Install sound driver set_volume(255,0); set_gfx_mode(GFX_AUTODETECT,640,480,0,0); dataFile=load_datafile("dtf.dat"); gamePalette=(PALLETE *)dataFile[PAL].dat; set_palette((RGB *)gamePalette); virtScreen=create_bitmap(640,480); while(!key[KEY_ESC]){ while(Speed_Ctr>0){ moveFaceAround(&face); checkBulletHitHead(&face); poll_mouse(); Speed_Ctr--; } vsync(); draw_sprite(virtScreen,(BITMAP *)dataFile[0].dat,face.x,face.y); draw_sprite(virtScreen,(BITMAP *)dataFile[MOUSE].dat,mouse_x-16,mouse_y-16); if(key[KEY_S]) save_bitmap("scrsht.bmp",virtScreen,(RGB*)gamePalette); blit(virtScreen,screen,0,0,0,0,SCREEN_W,SCREEN_H); clear(virtScreen); } allegro_exit(); return 0; }END_OF_MAIN(); void moveFaceAround(struct FACE *face){ if((face->x<0)||(face->x+64>SCREEN_W)) face->xvel*=-1; if((face->y<0)||(face->y+64>SCREEN_H)) face->yvel*=-1; face->x+=face->xvel; face->y+=face->yvel; } void checkBulletHitHead(struct FACE *face){ int x; if(mouse_b & 1 || mouse_b & 2){ if((mouse_x < face->x+64)&&(mouse_x > face->x)&&(mouse_y < face->y+64)&&(mouse_y>face->y)){ stop_sample((SAMPLE*)dataFile[SOUND_HIT].dat); for(x=0;x<4;x++) play_sample((SAMPLE *)dataFile[SOUND_HIT].dat,255,128,1000,0); for(x=1;xx,face->y); rest(100); } face->x=SCREEN_W/2; face->y=SCREEN_H/2; face->xvel=-3+rand()%6; if(face->xvel==0) face->xvel=1; face->yvel=-3+rand()%6; if(face->yvel==0) face->yvel=1; } } }