home *** CD-ROM | disk | FTP | other *** search
/ Game Programming - All in One (3rd Edition) / game_prog_all_in_one_3rd_ed.iso / sources / TankWar-Final / setup.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-09-17  |  5.6 KB  |  205 lines

  1. //////////////////////////////////////////////////////////////////
  2. // Game Programming All In One, Third Edition
  3. // Tank War Final - setup.c
  4. //////////////////////////////////////////////////////////////////
  5.  
  6. #include "tankwar.h"
  7.  
  8.  
  9. void loaddatafile()
  10. {
  11.     datafile = load_datafile("sounds.dat");
  12.     if (!datafile) 
  13.         fatalerror("Error loading data file");
  14. }
  15.  
  16. void loadsounds()
  17. {
  18.     //install a digital sound driver
  19.     if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, "") != 0) 
  20.         fatalerror("Error initializing sound system");
  21.  
  22.     //load the ammo sound
  23.     sounds[AMMO] = (SAMPLE *)datafile[AMMO_WAV].dat;
  24.     if (!sounds[AMMO]) 
  25.         fatalerror("Error loading ammo.wav");
  26.  
  27.     //load the hit1 sound
  28.     sounds[HIT1] = (SAMPLE *)datafile[HIT1_WAV].dat;
  29.     if (!sounds[HIT1]) 
  30.         fatalerror("Error reading hit1.wav");
  31.  
  32.     //load the hit2 sound
  33.     sounds[HIT2] = (SAMPLE *)datafile[HIT2_WAV].dat;
  34.     if (!sounds[HIT2]) 
  35.         fatalerror("Error reading hit2.wav");
  36.  
  37.     //load the fire sound
  38.     sounds[FIRE] = (SAMPLE *)datafile[FIRE_WAV].dat;
  39.     if (!sounds[FIRE]) 
  40.         fatalerror("Error reading fire.wav");
  41.  
  42.     //load the goopy sound
  43.     sounds[GOOPY] = (SAMPLE *)datafile[GOOPY_WAV].dat;
  44.     if (!sounds[GOOPY]) 
  45.         fatalerror("Error reading goopy.wav");
  46.  
  47.     //load the harp sound
  48.     sounds[HARP] = (SAMPLE *)datafile[HARP_WAV].dat;
  49.     if (!sounds[HARP]) 
  50.         fatalerror("Error reading harp.wav");
  51.  
  52.     //load the scream sound
  53.     sounds[SCREAM] = (SAMPLE *)datafile[SCREAM_WAV].dat;
  54.     if (!sounds[SCREAM]) 
  55.         fatalerror("Error reading scream.wav");
  56.  
  57.     //load the ohhh sound
  58.     sounds[OHHH] = (SAMPLE *)datafile[OHHH_WAV].dat;
  59.     if (!sounds[OHHH])
  60.         fatalerror("Error reading ohhh.wav");
  61.  
  62.     //load music tracks
  63.     music_title = load_midi("title.mid");
  64.     if (!music_title) fatalerror("Error loading title music");
  65.     
  66.     music_battle = load_midi("battle.mid");
  67.     if (!music_battle) fatalerror("Error loading battle music");
  68.  
  69.     music_victory = load_midi("victory.mid");
  70.     if (!music_victory) fatalerror("Error loading victory music");
  71.  
  72.  
  73.     //get things rolling
  74.     play_midi(music_title, 1);
  75.     play_sample(sounds[0], VOLUME, PAN, PITCH, FALSE);
  76.  
  77. }
  78.  
  79. void loadgraphics()
  80. {
  81.     int n;
  82.  
  83.     //load explosions for each tank
  84.     //each window will show a pair of explosions in close quarters
  85.     for (int a=0; a<2; a++) {
  86.         for (int b=0; b<4; b++) {
  87.             explosions[a][b] = new sprite();
  88.             explosions[a][b]->load("explosion.bmp");
  89.             explosions[a][b]->alive = 0;
  90.             explosions[a][b]->totalframes = 16;
  91.             explosions[a][b]->width = 96;
  92.             explosions[a][b]->height = 96;
  93.             explosions[a][b]->animcolumns = 4;
  94.             explosions[a][b]->framedelay = 2;
  95.         }
  96.     }
  97.  
  98.     //create player 1's tank
  99.     tanks[0] = new sprite();
  100.     tanks[0]->load("tank1.bmp");
  101.     tanks[0]->direction = 3;
  102.     tanks[0]->totalframes = 7;
  103.     tanks[0]->animcolumns = 8;
  104.     tanks[0]->width = 32;
  105.     tanks[0]->height = 32;
  106.     tanks[0]->framedelay = 10;
  107.     tanks[0]->animdir = 0;
  108.  
  109.  
  110.     //create player 2's tank
  111.     tanks[1] = new sprite();
  112.     tanks[1]->load("tank2.bmp");
  113.     tanks[1]->velx = 0.0f;
  114.     tanks[1]->direction = 7;
  115.     tanks[1]->totalframes = 7;
  116.     tanks[1]->animcolumns = 8;
  117.     tanks[1]->width = 32;
  118.     tanks[1]->height = 32;
  119.     tanks[1]->framedelay = 10;
  120.     tanks[1]->animdir = 0;
  121.  
  122.     //initialize bullets
  123.     for (n=0; n<2; n++)
  124.     {
  125.        bullets[n] = new sprite();
  126.        bullets[n]->load("bullet.bmp");
  127.        bullets[n]->alive = 0;
  128.        bullets[n]->xdelay = 1;
  129.        bullets[n]->ydelay = 1;
  130.     }
  131.  
  132.     //center tanks inside scroll windows
  133.     tanks[0]->x = 5 + SCROLLW/2 - 16;
  134.     tanks[0]->y = 90 + SCROLLH/2 - 16;
  135.     tanks[1]->x = 325 + SCROLLW/2 - 16;
  136.     tanks[1]->y = 90 + SCROLLH/2 - 16;
  137.  
  138.  
  139.     //load side views of tanks for status windows
  140.     sideviews[0] = new sprite();
  141.     sideviews[0]->x = 34;
  142.     sideviews[0]->y = 10;
  143.     if (!sideviews[0]->load("tankside1.bmp")) {
  144.         fatalerror("Error loading tankside1.bmp");
  145.     }
  146.  
  147.     //side view of tank 2   
  148.     sideviews[1] = new sprite();
  149.     sideviews[1]->x = 465;
  150.     sideviews[1]->y = 12;
  151.     if (!sideviews[1]->load("tankside2.bmp")) {
  152.         fatalerror("Error loading tankside2.bmp");
  153.     }
  154.  
  155.     //load background image
  156.     back = new sprite();
  157.     if (!back->load("background2.bmp"))
  158.         fatalerror("Error loading background");
  159.  
  160.     //load title screen
  161.     title = new sprite();
  162.     if (!title->load("tankwartitle.bmp"))
  163.         fatalerror("Error loading title");
  164.  
  165.     //load victory screens
  166.     victory1 = new sprite();
  167.     if (!victory1->load("victory1.bmp"))
  168.         fatalerror("Error loading victory1");
  169.  
  170.     victory2 = new sprite();
  171.     if (!victory2->load("victory2.bmp"))
  172.         fatalerror("Error loading victory2");
  173.  
  174. }
  175.  
  176. void setupscreen()
  177. {
  178.     //set video mode    
  179.     set_color_depth(DEPTH);
  180.     if (set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0) != 0)
  181.         fatalerror(allegro_error);
  182.  
  183.     //create the double buffer
  184.     buffer = create_bitmap(WIDTH, HEIGHT);
  185.     if (!buffer)
  186.         fatalerror("Error creating double buffer");
  187.  
  188.     //load the Mappy file
  189.     //remember, it returns 0 on success, which is a bug
  190.     if (MapLoad(MAPFILE) != 0)
  191.         fatalerror("Can't find map file");
  192.  
  193.     //position the radar
  194.     radarx = 270;
  195.     radary = 1;
  196.  
  197.     //position the scroll windows
  198.     startx[0] = 7;
  199.     starty[0] = 95;
  200.     startx[1] = 327;
  201.     starty[1] = 95;
  202.  
  203. }
  204.  
  205.