home *** CD-ROM | disk | FTP | other *** search
/ Trixter's Scene Collection / trixter.zip / trixter / Demos / GN_SKP.ZIP / SRC / GN1.C < prev    next >
C/C++ Source or Header  |  1994-06-26  |  59KB  |  2,446 lines

  1. #include <alloc.h>
  2. #include <math.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <time.h>
  8. #include <io.h>
  9. #include <wgt4.h>
  10. #include <wgt3d.h>
  11. #include <sound.h>
  12. #include <irq.h>
  13. #include <drvload.h>
  14.  
  15. /*
  16. ╔═════════════════════════════════════════════════════════════════╗
  17. ║ Gooroo Nation   by Chris Egerter, April 1994                    ║
  18. ║ --------------------------------------------------------------- ║
  19. ║ The demo is made of the following parts:                        ║
  20. ║  -Introduction: Color fading                                    ║
  21. ║  -Title screen:  Texture Warper                                 ║
  22. ║  -Transforming Vector Balls                                     ║
  23. ║  -Wormhole Starfield                                            ║
  24. ║  -Magnifying Lens                                               ║
  25. ║  -Dual Plasma                                                   ║
  26. ║  -Shadebob Scrollers                                            ║
  27. ║  -Voxel Landscape                                               ║
  28. ║  -3D cubes (with texture mapping)                               ║
  29. ║  -Credits:  Gummi Scroller                                      ║
  30. ║                                                                 ║
  31. ║ Some parts of the code are commented, others are not.           ║
  32. ║                                                                 ║
  33. ║ Turbo C++ v1.0 was used to compile the demo.  Borland C++ has   ║
  34. ║ not been tested, so there may be some parts which need changes. ║
  35. ║ The WordUp Graphics Toolkit v4.0 is required for linking.  This ║
  36. ║ library was used to handle the basic graphics functions for     ║
  37. ║ loading in pictures, sprites, and palettes.                     ║
  38. ║ WGT4 is available on the Internet at the following FTP sites:   ║
  39. ║  -oak.oakland.edu   in pub/msdos/cpluspls                       ║
  40. ║  -nic.funet.fi      in pub/msdos/games/programming              ║
  41. ║  -ftp.wustl.edu     in pub/MSDOS_UPLOADS/programming            ║
  42. ║                                                                 ║
  43. ║ A few parts have been optimized in assembly, however a large    ║
  44. ║ portion of the demo remains in C.  If this demo was for a       ║
  45. ║ competition I might have actually used assembly.  Don't complain║
  46. ║ if it is too slow on your computer.  I recommend a 486DX and    ║
  47. ║ if you don't have one, BUY ONE NOW!                             ║
  48. ║                                                                 ║
  49. ║ Finally, don't even try to run this demo on your ancient 286.   ║
  50. ║                                                                 ║
  51. ║ *** Send any comments to chris.egerter@homebase.com ***         ║
  52. ║                                                                 ║
  53. ╚═════════════════════════════════════════════════════════════════╝
  54. */
  55.  
  56. /* The following variables are used by all parts of the demo. */
  57. block virt;  /* Virtual screen used for background work */
  58. block virt2;
  59. block virt3;
  60. block virt4; 
  61. int i;
  62. color pal1[256];    /* A few different palettes for fading, etc */
  63. color pal2[256];
  64. color pal3[256];
  65. color pal4[256];
  66. color pal5[256];
  67. color blackpal[256];    /* Full of 0's */
  68. block sprites[128];
  69.  
  70. int shaker = 0;
  71.  
  72. /* Gummi letters */
  73. #define TEXTPOS 75
  74. int skullx[10];
  75. char let;
  76. int skullpos[10];
  77. int ypos[400];
  78. int x,y;
  79. char skullmessage[] = "THE CREDITS....  CODING AND GRAPHICS BY GOOROO   FIRST TUNE BY FALCON   SECOND TUNE BY GRAND VERBALIZER   THIRD TUNE BY GOOROO   ENDING ANSI BY PYROMANIAX                    ";
  80. int donegummiscroll = 0;
  81.  
  82. int music_on;
  83.  
  84. void calc_sin (void);
  85. void start_intro (void);
  86. void start_gummi_scroller (void);
  87. void draw_gummi (void);
  88. void calculate_gummi (void);
  89. void draw_letters (void);
  90. void calc_sinus (void);
  91.  
  92. void start_vector_balls (void);
  93. void run_vector_balls (void);
  94.  
  95. void start_starfield (void);
  96. void start_lens (void);
  97. void start_plasma (void);
  98.  
  99. void draw_land_plasma(void);
  100. void start_landscape (void);
  101.  
  102. void start_firecube (void);
  103.  
  104. void startmusic(char *filename);
  105. void stopmusic(int fade);
  106.  
  107. void fade_in(int start, int end, int speed, color *pal);
  108. void fade_out(int start, int end, int speed, color *pal);
  109.  
  110. void show_end_text (void);
  111.  
  112. void start_warper (void);
  113.  
  114. /* Sound System */
  115. PSMFH PSM;
  116. SC S;
  117. PM *p;
  118. MS *m;
  119. int MVol = 252;
  120.  
  121. long memleft=999999;
  122. int lowest = 0;
  123.  
  124. int gravis = 0;
  125.  
  126. void shut_down (char *str)
  127. {
  128.  printf ("\n\n%s\n\n",str);
  129.  exit (1);
  130. }
  131.  
  132.  
  133. void main (void)
  134. {
  135.  extern void showmem(void);
  136.  clrscr ();
  137.  printf ("Gooroo Nation - Startup\n\n");
  138.  delay (400);
  139. // printf ("Initializing Sound System\n");
  140. // delay (400);
  141.  setlib ("gn.dmo");
  142.  setpassword ("voodoo");
  143.  
  144.  startmusic ("gn.psm");
  145.  
  146.  printf ("Checking for VGA\n");
  147.   if (!vgadetected())
  148.     shut_down ("No VGA card found!");
  149.  printf ("Checking for 386\n");
  150.   if (wdetectcpu () < 3)
  151.     shut_down ("This demo requires a 386 or better.");
  152.  
  153. /* printf ("Checking Free memory\n");
  154.   if (farcoreleft() < 200000L)
  155.     shut_down ("Not enough memory to run demo.");*/
  156.   
  157.  printf ("Starting Demo...\n");
  158.  
  159.  
  160.  wreadpalette (0,255,pal2);
  161.  fade_out (0, 16, 4, pal2);
  162.  vga256 ();
  163.  
  164.   if (music_on)
  165.   {
  166.    mMusicPlay (&PSM, "MAINSONG");
  167.    mSetMusicVolume (MVol);
  168.   }
  169.  vga256 ();
  170.  wsetpalette (0, 255, pal1);        /* Set to a black palette */
  171.  calc_sin ();
  172.  
  173.  start_intro ();
  174.  start_warper ();
  175.  start_vector_balls ();
  176.  start_starfield ();
  177.  start_lens ();
  178.  start_plasma ();
  179.  start_greets ();
  180.  start_landscape ();
  181.  if (music_on)
  182.  {
  183.   for (i = 0; i < 64; i++)    /* Fade out volume and colors */
  184.   {
  185.     if (MVol > 4)
  186.     {
  187.       MVol -= 4;
  188.       mSetMusicVolume (MVol);
  189.     }
  190.     wretrace ();        /* DELAY doesn't work with Interrupts */
  191.     wretrace ();        /* Use several retrace commands instead */
  192.     wretrace ();
  193.   }
  194.   MVol = 252;
  195.   mMusicStop();
  196.   mFreePSM(&PSM);
  197.  
  198.   i = mLoadPSM ("tres.psm", &PSM, 0);
  199.   if (i) {
  200.     mFreePSM(&PSM);
  201.     mCloseDriver();
  202.     mFreeDrivers();
  203.     wsetmode (3);
  204.   }
  205.   mMusicPlay (&PSM, "MAINSONG");
  206.   mSetMusicVolume (MVol);
  207.  }
  208.  start_firecube ();
  209.  start_gummi_scroller ();
  210.  start_lightedcube ();
  211.  
  212.  wsetmode (3);
  213.  show_end_text ();
  214. }
  215.  
  216.  
  217.  
  218. /*************************************************************
  219. * Introduction screen:                                       *
  220. *   Uses color fading to smoothly fade in and out some fonts.* 
  221. **************************************************************/
  222.  
  223. /* Returns the x coordinate of the centred string */
  224. int centre_string (char *string)
  225. {
  226. int slen;  /* String length (in characters) */
  227. int plen;  /* String length (in pixels) */
  228. char ch;
  229. int i;
  230.  
  231.  slen = strlen (string);
  232.  plen = 0;
  233.  
  234.  for (i = 0; i < slen; i++)
  235.   {
  236.    ch = string[i]-65;
  237.    if ((ch >= 0) && (sprites[ch] != NULL))  /* don't display spaces */
  238.      plen += wgetblockwidth (sprites[ch])+3;
  239.    else
  240.      plen += 20;
  241.   }
  242.  
  243.   return (160 - plen/2);
  244. }
  245.  
  246. /* Draws a single letter on the screen */
  247. void addletter (int x, int y, block let)
  248. {
  249. int w,h;
  250. int i,j;
  251. block rowptr;
  252. block ptr;
  253.  
  254.  w = wgetblockwidth (let);
  255.  h = wgetblockheight (let);
  256.  let += 4;
  257.  
  258.  rowptr = abuf+ y*320 + x;
  259.  
  260.  for (i = 0; i < h; i++)
  261.   {
  262.    ptr = rowptr;
  263.    for (j = 0; j < w; j++)
  264.     {
  265.      *ptr = *ptr + (*let) * 2;
  266.      let++;
  267.      ptr++;
  268.     }
  269.    rowptr += 320;
  270.   }
  271. }
  272.  
  273.  
  274. /* Displays a string using sprites, centred on the string */
  275. void displaystring (char *string, int y, int mode)
  276. {
  277. int len;
  278. int i;
  279. int ch;
  280. int x;
  281.  
  282.  x = centre_string (string);
  283.  len = strlen (string);
  284.  
  285.  for (i = 0; i < len; i++)
  286.   {
  287.    ch = string[i] - 65;
  288.    if ((ch >= 0) & (sprites[ch] != NULL))  /* don't display spaces */
  289.     {
  290.      if (mode == 0)
  291.        wputblock (x, y, sprites[ch], 0);
  292.      else
  293.        addletter (x,y, sprites[ch]);
  294.      x += wgetblockwidth (sprites[ch]) + 3;
  295.     }
  296.    else x += 20; /* Skip over blank spaces */
  297.   }
  298. }
  299.  
  300.  
  301. void start_intro (void)
  302. {
  303.  wloadsprites (pal4, "monolet.spr", sprites, 0, 127);
  304.  
  305.  wcls (0);
  306.  wsetrgb (0, 0,   0,  0, pal1);
  307.  wsetrgb (1, 63, 63, 63, pal1);
  308.  wsetrgb (2, 0,   0,