home *** CD-ROM | disk | FTP | other *** search
- //////////////////////////////////////////////////////////////////
- // Game Programming All In One, Third Edition
- // Tank War Final - setup.c
- //////////////////////////////////////////////////////////////////
-
- #include "tankwar.h"
-
-
- void loaddatafile()
- {
- datafile = load_datafile("sounds.dat");
- if (!datafile)
- fatalerror("Error loading data file");
- }
-
- void loadsounds()
- {
- //install a digital sound driver
- if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, "") != 0)
- fatalerror("Error initializing sound system");
-
- //load the ammo sound
- sounds[AMMO] = (SAMPLE *)datafile[AMMO_WAV].dat;
- if (!sounds[AMMO])
- fatalerror("Error loading ammo.wav");
-
- //load the hit1 sound
- sounds[HIT1] = (SAMPLE *)datafile[HIT1_WAV].dat;
- if (!sounds[HIT1])
- fatalerror("Error reading hit1.wav");
-
- //load the hit2 sound
- sounds[HIT2] = (SAMPLE *)datafile[HIT2_WAV].dat;
- if (!sounds[HIT2])
- fatalerror("Error reading hit2.wav");
-
- //load the fire sound
- sounds[FIRE] = (SAMPLE *)datafile[FIRE_WAV].dat;
- if (!sounds[FIRE])
- fatalerror("Error reading fire.wav");
-
- //load the goopy sound
- sounds[GOOPY] = (SAMPLE *)datafile[GOOPY_WAV].dat;
- if (!sounds[GOOPY])
- fatalerror("Error reading goopy.wav");
-
- //load the harp sound
- sounds[HARP] = (SAMPLE *)datafile[HARP_WAV].dat;
- if (!sounds[HARP])
- fatalerror("Error reading harp.wav");
-
- //load the scream sound
- sounds[SCREAM] = (SAMPLE *)datafile[SCREAM_WAV].dat;
- if (!sounds[SCREAM])
- fatalerror("Error reading scream.wav");
-
- //load the ohhh sound
- sounds[OHHH] = (SAMPLE *)datafile[OHHH_WAV].dat;
- if (!sounds[OHHH])
- fatalerror("Error reading ohhh.wav");
-
- //load music tracks
- music_title = load_midi("title.mid");
- if (!music_title) fatalerror("Error loading title music");
-
- music_battle = load_midi("battle.mid");
- if (!music_battle) fatalerror("Error loading battle music");
-
- music_victory = load_midi("victory.mid");
- if (!music_victory) fatalerror("Error loading victory music");
-
-
- //get things rolling
- play_midi(music_title, 1);
- play_sample(sounds[0], VOLUME, PAN, PITCH, FALSE);
-
- }
-
- void loadgraphics()
- {
- int n;
-
- //load explosions for each tank
- //each window will show a pair of explosions in close quarters
- for (int a=0; a<2; a++) {
- for (int b=0; b<4; b++) {
- explosions[a][b] = new sprite();
- explosions[a][b]->load("explosion.bmp");
- explosions[a][b]->alive = 0;
- explosions[a][b]->totalframes = 16;
- explosions[a][b]->width = 96;
- explosions[a][b]->height = 96;
- explosions[a][b]->animcolumns = 4;
- explosions[a][b]->framedelay = 2;
- }
- }
-
- //create player 1's tank
- tanks[0] = new sprite();
- tanks[0]->load("tank1.bmp");
- tanks[0]->direction = 3;
- tanks[0]->totalframes = 7;
- tanks[0]->animcolumns = 8;
- tanks[0]->width = 32;
- tanks[0]->height = 32;
- tanks[0]->framedelay = 10;
- tanks[0]->animdir = 0;
-
-
- //create player 2's tank
- tanks[1] = new sprite();
- tanks[1]->load("tank2.bmp");
- tanks[1]->velx = 0.0f;
- tanks[1]->direction = 7;
- tanks[1]->totalframes = 7;
- tanks[1]->animcolumns = 8;
- tanks[1]->width = 32;
- tanks[1]->height = 32;
- tanks[1]->framedelay = 10;
- tanks[1]->animdir = 0;
-
- //initialize bullets
- for (n=0; n<2; n++)
- {
- bullets[n] = new sprite();
- bullets[n]->load("bullet.bmp");
- bullets[n]->alive = 0;
- bullets[n]->xdelay = 1;
- bullets[n]->ydelay = 1;
- }
-
- //center tanks inside scroll windows
- tanks[0]->x = 5 + SCROLLW/2 - 16;
- tanks[0]->y = 90 + SCROLLH/2 - 16;
- tanks[1]->x = 325 + SCROLLW/2 - 16;
- tanks[1]->y = 90 + SCROLLH/2 - 16;
-
-
- //load side views of tanks for status windows
- sideviews[0] = new sprite();
- sideviews[0]->x = 34;
- sideviews[0]->y = 10;
- if (!sideviews[0]->load("tankside1.bmp")) {
- fatalerror("Error loading tankside1.bmp");
- }
-
- //side view of tank 2
- sideviews[1] = new sprite();
- sideviews[1]->x = 465;
- sideviews[1]->y = 12;
- if (!sideviews[1]->load("tankside2.bmp")) {
- fatalerror("Error loading tankside2.bmp");
- }
-
- //load background image
- back = new sprite();
- if (!back->load("background2.bmp"))
- fatalerror("Error loading background");
-
- //load title screen
- title = new sprite();
- if (!title->load("tankwartitle.bmp"))
- fatalerror("Error loading title");
-
- //load victory screens
- victory1 = new sprite();
- if (!victory1->load("victory1.bmp"))
- fatalerror("Error loading victory1");
-
- victory2 = new sprite();
- if (!victory2->load("victory2.bmp"))
- fatalerror("Error loading victory2");
-
- }
-
- void setupscreen()
- {
- //set video mode
- set_color_depth(DEPTH);
- if (set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0) != 0)
- fatalerror(allegro_error);
-
- //create the double buffer
- buffer = create_bitmap(WIDTH, HEIGHT);
- if (!buffer)
- fatalerror("Error creating double buffer");
-
- //load the Mappy file
- //remember, it returns 0 on success, which is a bug
- if (MapLoad(MAPFILE) != 0)
- fatalerror("Can't find map file");
-
- //position the radar
- radarx = 270;
- radary = 1;
-
- //position the scroll windows
- startx[0] = 7;
- starty[0] = 95;
- startx[1] = 327;
- starty[1] = 95;
-
- }
-
-