home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / Source / PacMan / PacManView.h < prev    next >
Encoding:
Text File  |  1992-06-29  |  4.4 KB  |  106 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. // This object is the guts of the whole game.  It is like a central clearing
  5. // house... it renders all the peices within itself.  Rather than having lots
  6. // of independent views that do theire rendering all throughout the game, this
  7. // view ties together a lot of player/ghost objects and has them render
  8. // themselves inside of itself.  This makes the drawing a bit more efficient
  9. // and allows allows easy programmatic control of which order things get drawn
  10. // in.  Since the images all use transparency, etc., this order is very
  11. // important.  The two main methods in here are the autoUpdate: method, which
  12. // is a giant state machine that handles the logic of the game, and the
  13. // updateSelf:: method that updates the screen from one animation frame to the
  14. // next.  drawSelf:: is  a less complex version of updateSelf:: because it
  15. // always renders the whole view, not just the things which have changed since
  16. // the last update.  By having two different methods, drawing is sped up at
  17. // the sacrifice of code clarity.  (Having two different rendering methods
  18. // gives better speed, but code complexity is nasty and the difficulty of
  19. // keeping both methods in sync so that they give identical results make for
  20. // a lot of work.)  I haven't yet found a good way to simplify the rendering
  21. // engine without slowing it down...if you have any suggestions, I would like
  22. // to hear them of course, but I've already tried quite a few things.
  23.  
  24. #import "GameView.h"        // super class
  25.  
  26. // states -- tells autoUpdate what to do
  27. #define BLINK_LEVEL 10    // when out of dots we do this
  28. #define READY 11        // READY on screen (starting a new level)
  29. #define DIEREADY 12        // READY on screen (after a die)
  30. #define DYING_PAC 13    // the Pac melts during this phase
  31. #define GAME_OVER GAMEOVER    // I forget which one to use, so define both
  32.  
  33. // Sizes of arrays used to determine which maze to use for a level
  34. // and the point value for a fruit on a particular level
  35. #define NUMSCREENS 24
  36. #define NUMFRUITVALS 16
  37.             
  38. #define WAITFORDEMO 600    // Wait x cycles before gameover to start demo
  39.  
  40. // values for "fruitOn" (besides YES and NO; these two are transitory states)
  41. #define DRAW    2        // do we put fruit on the screen?
  42. #define ERASE    3        // do we erase fruit from the screen?
  43.  
  44. // offset for drawing ghost/fruit point values.
  45. #define TEXTOFFSET (-10)
  46. #define WIPETEXT (-1)    // flag to undraw text scores
  47.  
  48. // when fruit gets erased
  49. #define ERASEFRUIT    (200 + (([controller level] <= 10) ? 10 * (10 - \
  50.     [controller level]) : 0) + timeToFruit)
  51.  
  52. // macro for zapping rectangle at specific coords
  53. #define ZAPRECT(r, x, y) NX_X(&(r)) = (x); NX_Y(&(r)) = (y); \
  54.     [self drawBackground:&(r)]
  55.  
  56. @interface PacManView:GameView
  57. {
  58.     id  readyText;        // "Get Ready!" message
  59.     id  fruitText;        // point value of fruit
  60.  
  61.     id  ghost1text;        // point value of ghost; we put these into the
  62.     id  ghost2text;        // ghostText array for easier handling, but
  63.     id  ghost3text;        // we need these so that we can make the
  64.     id  ghost4text;        // connections in IB (it doesn't parse arrays of ids.)
  65.  
  66.     // various actors that get rendered in our view.
  67.     id  maze;
  68.     id  fruit;
  69.     id  player;
  70.     id  ghost[4];
  71.     id  ghostText[4];
  72.     id  gameOver;
  73.     
  74.     int begin;                // used as a counter for state transitions
  75.     BOOL dotEat;            // flag to be sure to erase eaten dots
  76.     BOOL erasePwr;            // erase power dot?
  77.     int fruitCount;            // counter to decide when to do fruit stuff
  78.     int timeToFruit;        // when to put next fruit up
  79.     int fruitOn;            // if fruit is out there...YES, NO, DRAW, or ERASE.
  80.     int numFruits;            // how many fruits put up in current level
  81.     int fruitPointCount, ftx, fty;
  82.     int ghostPointCount[4], gtx[4], gty[4];
  83.     NXPoint mazePos, myorigin;
  84.     NXRect eraseRect, textEraseRect;
  85.     NXSize gameOverSize;
  86. }
  87.  
  88. - initFrame:(const NXRect *)frm;    // initialize instance
  89. - loadPix;                    // gameBrain calls this from appDidInit
  90. - ghost:(int)i;                // return ghost #i
  91. - autoUpdate:sender;        // sent by timer
  92.  
  93. - updateSelf:(NXRect *)rects :(int)rectCount;  //used by internals for speed
  94. - drawSelf:(NXRect *)rects :(int)rectCount;  // standard rendering method
  95. - keyDown:(NXEvent *)myevent;        // handle keyDown events.
  96. - setUpScreen;    // sets up screen from level start, calls -startScreen below.
  97. - startScreen;    // sets up screen without refilling all eaten dots.
  98. - restartGame;    // start game over.
  99.  
  100. // puts up specific background images
  101. - back1:sender;
  102. - back2:sender;
  103. - back3:sender;
  104.  
  105. @end
  106.