home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Glypha 3v2 / GlyphaIII Code ƒ / Main.c < prev    next >
Encoding:
Text File  |  1995-06-30  |  3.4 KB  |  114 lines  |  [TEXT/CWIE]

  1.  
  2. //============================================================================
  3. //----------------------------------------------------------------------------
  4. //                                Glypha III 1.0.2
  5. //                                by  Scheherazade
  6. //----------------------------------------------------------------------------
  7. //============================================================================
  8.  
  9. // Here is the "main" file for Glypha.  Here is where the game begins and ends.
  10. // Also included are the preference calls.
  11.  
  12. #include "Externs.h"
  13. #include <Sound.h>
  14.  
  15.  
  16. #define kPrefsVersion            0x0001
  17.  
  18.  
  19. void ReadInPrefs (void);
  20. void WriteOutPrefs (void);
  21. void main (void);
  22.  
  23.  
  24. prefsInfo    thePrefs;
  25. short        wasVolume;
  26.  
  27. extern    Boolean        quitting, playing, pausing, evenFrame;
  28.  
  29.  
  30. //==============================================================  Functions
  31. //--------------------------------------------------------------  ReadInPrefs
  32.  
  33. //    This function loads up the preferences.  If the preferences 
  34. //    aren't found, all settings are set to their defaults.
  35.  
  36. void ReadInPrefs (void)
  37. {
  38.     short        i;
  39.                             // Call LoadPrefs() function - returns TRUE if it worked.
  40.     if (LoadPrefs(&thePrefs, kPrefsVersion))
  41.         SetSoundVol(thePrefs.wasVolume);
  42.     else                    // If LoadPrefs() failed, set defaults.
  43.     {
  44.         thePrefs.prefVersion = kPrefsVersion;                // version of prefs
  45.         thePrefs.filler = 0;                                // just padding
  46.         PasStringCopy("\pYour Name", thePrefs.highName);    // last highscores name
  47.         for (i = 0; i < 10; i++)                            // loop through scores
  48.         {
  49.             PasStringCopy("\pNemo", thePrefs.highNames[i]);    // put "Nemo" in name
  50.             thePrefs.highScores[i] = 0L;                    // set highscore to 0
  51.             thePrefs.highLevel[i] = 0;                        // level attained = 0
  52.         }
  53.         GetSoundVol(&thePrefs.wasVolume);
  54.     }
  55.                             // Get sound volume so we can restore it.
  56.     GetSoundVol(&wasVolume);
  57. }
  58.  
  59. //--------------------------------------------------------------  WriteOutPrefs
  60.  
  61. //    This function writes out the preferences to disk and restores 
  62. //    the sound volume to its setting before Glypha was launched.
  63.  
  64. void WriteOutPrefs (void)
  65. {
  66.     if (!SavePrefs(&thePrefs, kPrefsVersion))
  67.         SysBeep(1);
  68.     SetSoundVol(wasVolume);
  69. }
  70.  
  71. //--------------------------------------------------------------  main
  72.  
  73. //    This is the main function.  Every C program has one of these.
  74. //    First it initializes our program and then falls into a loop
  75. //    until the user chooses to quit.  At that point, it cleans up
  76. //    and exits.
  77.  
  78. void main (void)
  79. {
  80.     long        tickWait;
  81.     
  82.     ToolBoxInit();            // Call function that initializes the ToolBox managers.
  83.     CheckEnvirons();        // Check the Mac we're on to see if we can run.
  84.     OpenMainWindow();        // Open up the main window - it will fill the monitor.
  85.     InitVariables();        // Initialize Glypha's variables.
  86.     InitSound();            // Create sound channels and load up sounds.
  87.     InitMenubar();            // Set up the game's menubar.
  88.     ReadInPrefs();            // Load up the preferences.
  89.     
  90.     do                        // Here begins the main loop.
  91.     {
  92.         HandleEvent();        // Check for events.
  93.         if ((playing) && (!pausing))
  94.             PlayGame();        // If user began game, drop in game loop. (play mode)
  95.         else                // If no game, animate the screen. (idle mode)
  96.         {
  97.             tickWait = TickCount() + 2L;
  98.             evenFrame = !evenFrame;
  99.             DrawTorches();    // Flicker torches.
  100.             CopyAllRects();    // Refresh screen.
  101.             do                // Wait for 2 Ticks to pass to keep fast Macs at bay.
  102.             {
  103.             }
  104.             while (TickCount() < tickWait);
  105.         }
  106.     }
  107.     while (!quitting);
  108.     
  109.     KillSound();            // Dispose of sound channels.
  110.     ShutItDown();            // Dispose of other structures.
  111.     WriteOutPrefs();        // Save preferences to disk.
  112. }
  113.  
  114.