home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / Examples / NX_Invaders / AnimTester / AnimView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.2 KB  |  98 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "AnimView.h"
  5. #import <appkit/NXImage.h>
  6. #import <appkit/Control.h>
  7. #import <appkit/Matrix.h>
  8. #import <dpsclient/psops.h>
  9.  
  10. @implementation AnimView
  11.  
  12. - initFrame:(const NXRect *)frm    // initialize instance
  13. {
  14.     [super initFrame:frm];
  15.     cycles = 0;
  16.     frameShown = 0;
  17.     position.y = 0.0;
  18.     position.x = 0.0;
  19.     return self;
  20. }
  21.  
  22. - loadPix                // gameBrain calls this from appDidInit
  23. {
  24.     [super loadPix];
  25.     runner = [NXImage findImageNamed:IMAGENAME];
  26.     return self;
  27. }
  28.  
  29. - autoUpdate:sender    // sent by timer
  30. {
  31.     int direction = GODIR;
  32.     int move = MOVEINC;
  33.     
  34.     [super autoUpdate:sender];
  35.     if (!(cycles % UPDATEFREQ)) {
  36.         frameShown++;
  37.         if (frameShown >= NUM_FRAMES) frameShown = 0;
  38.         if (GORIGHT) {
  39.             position.x = position.x + move;
  40.             if (position.x > NX_WIDTH(&bounds) + move) position.x = 0.0;
  41.         } else if (GOLEFT) {
  42.             position.x = position.x - move;
  43.             if (position.x < - (BLOCK_X + move)) position.x = NX_WIDTH(&bounds);
  44.         } else if (GOUP) {
  45.             position.y = position.y + move;
  46.             if (position.y > NX_HEIGHT(&bounds) + move) position.y = 0.0;
  47.         } else if (GODOWN) {
  48.             position.y = position.y - move;
  49.             if (position.y < - (BLOCK_Y + move)) position.y = NX_HEIGHT(&bounds);
  50.         } else {
  51.         }
  52.         [self updateSelf:&bounds :1]; 
  53.     }
  54.     return self;
  55. }
  56.  
  57. - drawSelf:(NXRect *)rects :(int)rectCount  //used by internals for speed
  58. {
  59.     NXRect from = {{frameShown * BLOCK_X, SERIES * BLOCK_Y},
  60.         {BLOCK_X, BLOCK_Y}};
  61.     
  62.     [super drawSelf:rects :rectCount];
  63.     PSsetgray(0.333);
  64.     NXRectFill(rects);
  65.     [runner composite:NX_SOVER fromRect:&from toPoint:&position];
  66.     return self;
  67. }
  68.  
  69. - updateSelf:(NXRect *)rects :(int)rectCount  //used by internals for speed
  70. {
  71.     int move = MOVEINC;
  72.     NXRect from = {{frameShown * BLOCK_X, SERIES * BLOCK_Y},
  73.         {BLOCK_X, BLOCK_Y}};
  74.     NXRect old = {{position.x  - move, position.y - move},
  75.         {BLOCK_X + move * 2, BLOCK_Y + move * 2}};
  76.     
  77.     [self lockFocus];
  78.     [super drawSelf:rects :rectCount];
  79.     PSsetgray(0.333);
  80.     NXRectFill(&old);
  81.     [runner composite:NX_SOVER fromRect:&from toPoint:&position];
  82.     [self unlockFocus];
  83.     [window flushWindow];
  84.     NXPing();
  85.     return self;
  86. }
  87.  
  88. - changeDist:sender
  89. {
  90.     int val = [sender intValue];
  91.     
  92.     [distText setIntValue:val];
  93.     if (sender != distSlider) [distSlider setIntValue:val];
  94.     return self;
  95. }
  96.  
  97. @end
  98.