Example #1
0
play()
{
	register struct ship *sp;

	for (;;) {
		switch (sgetch("~\b", (struct ship *)0, 0)) {
		case 'm':
			acceptmove();
			break;
		case 's':
			acceptsignal();
			break;
		case 'g':
			grapungrap();
			break;
		case 'u':
			unfoulplayer();
			break;
		case 'v':
			Signal("%s", (struct ship *)0, version);
			break;
		case 'b':
			acceptboard();
			break;
		case 'f':
			acceptcombat();
			break;
		case 'l':
			loadplayer();
			break;
		case 'c':
			changesail();
			break;
		case 'r':
			repair();
			break;
		case 'B':
			Signal("'Hands to stations!'", (struct ship *)0);
			unboard(ms, ms, 1);	/* cancel DBP's */
			unboard(ms, ms, 0);	/* cancel offense */
			break;
		case '\f':
			centerview();
			blockalarm();
			draw_board();
			draw_screen();
			unblockalarm();
			break;
		case 'L':
			mf->loadL = L_EMPTY;
			mf->loadR = L_EMPTY;
			mf->readyL = R_EMPTY;
			mf->readyR = R_EMPTY;
			Signal("Broadsides unloaded", (struct ship *)0);
			break;
		case 'q':
			Signal("Type 'Q' to quit", (struct ship *)0);
			break;
		case 'Q':
			leave(LEAVE_QUIT);
			break;
		case 'I':
			foreachship(sp)
				if (sp != ms)
					eyeball(sp);
			break;
		case 'i':
			if ((sp = closestenemy(ms, 0, 1)) == 0)
				Signal("No more ships left.");
			else
				eyeball(sp);
			break;
		case 'C':
			centerview();
			blockalarm();
			draw_view();
			unblockalarm();
			break;
		case 'U':
			upview();
			blockalarm();
			draw_view();
			unblockalarm();
			break;
		case 'D':
		case 'N':
			downview();
			blockalarm();
			draw_view();
			unblockalarm();
			break;
		case 'H':
			leftview();
			blockalarm();
			draw_view();
			unblockalarm();
			break;
		case 'J':
			rightview();
			blockalarm();
			draw_view();
			unblockalarm();
			break;
		case 'F':
			lookout();
			break;
		case 'S':
			dont_adjust = !dont_adjust;
			blockalarm();
			draw_turn();
			unblockalarm();
			break;
		}
	}
}
int main()
{
    if(!initialize())    return 1;
    int spawn, lastspawn=-1,spawnbomb,lastspawnbomb=-1;
    if(!loadplayer()) {
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load tarma");
        return 1;
    }
    if(!loadenemy()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load bulldogs");
        return 1;
    }
    if(!loadpistol()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load pistols");
        return 1;
    }
    if(!loadbomber()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load bomber");
        return 1;
    }
    if(!loadbomb()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load bomb");
        return 1;
    }

    /*if(!loadgun()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load guns");
        return 1;
    }*/
    /*if(!loadboss()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load boss");
        return 1;
    }*/
    //int volume=250,pan=128,pitch=1000;
    //play_sample(level1,volume,pan,pitch,TRUE);
    int intro=0,exits=0;
    while(!exits){
         intro=counter;
         while(counter-intro<2)
        blit(welcome,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;
        while(counter-intro<2)
        blit(instruction1,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;
        while(counter-intro<2)
        blit(instruction2,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;

        while(counter-intro<2)
        blit(instruction3,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;
        gameover=0;
        loadplayer();
        loadenemy();
        loadbomber();
        loadpistol();
        loadbomb();

        while(!key[KEY_ESC] && !gameover){
       // clear_bitmap(buffer);

        if(mils-lastinput>2) inputflag=1;
        if(inputflag)   checkinputs();

        updatehero();
        if(gameover==1) break;
        if((tarma.x%(640*2))<5 && lastspawn!=tarma.x/(640*2)){
            spawn=1;
            lastspawn=tarma.x/(640*2);
        }
         if((tarma.x%(640*5))<5 && lastspawnbomb!=tarma.x/(640*5)){
            spawnbomb=1;
            lastspawnbomb=tarma.x/(640*5);
        }


        updateenemy(spawn);
        updatebombers(spawnbomb);
        updatedeaths();
        updatebullets();
        updatebombs();
        displaystats();
        acquire_screen();
        blit(buffer,screen,0,0,0,0,WIDTH,HEIGHT);
        release_screen();
        ticks++;
        rest(DELAY);
    }
    intro=counter;
    while(counter-intro<2)
        blit(gameoverscreen,screen,0,0,0,0,WIDTH,HEIGHT);
    if(key[KEY_ESC])     exits=1;

    }

     destroy_sample(level1);
     remove_sound();
    remove_int(timer1);
    destroy_bitmap(buffer);
    destroy_bitmap(welcome);
    destroy_bitmap(instruction1);
    destroy_bitmap(instruction2);
    destroy_bitmap(instruction3);
    destroy_bitmap(gameoverscreen);
    delete []bulldogs;
    delete []pistols;
    delete gun;
    delete []bomb;
    delete []bombman;
    delete rocket;
     for(int i=0;i<6;i++)
                for(int j=0;j<TARMAMAX[i];j++)
                    destroy_bitmap(tarma.heroimg[i][j]);
     for(int i=2;i<5;i++)
                for(int j=0;j<REBELMAX[i];j++)
                destroy_bitmap(enemypics.enemyimg[i][j]);
    for(int i=0;i<4;i++)
                destroy_bitmap(bulletpics.bullets[i]);
    for(int i=0;i<14;i++)
        destroy_bitmap(bomberpics.bomber[i]);

    MapFreeMem();
    allegro_exit();
    return 0;
}