home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / GameKit / Examples / NX_Invaders / NXISaucer.m < prev    next >
Encoding:
Text File  |  1994-06-07  |  1.4 KB  |  62 lines

  1.  
  2. #import <libc.h>
  3. #import "NXISaucer.h"
  4. #import "NXIGameBrain.h"
  5. #import "NXIPlayer.h"
  6.  
  7.  
  8. @implementation NXISaucer
  9.  
  10. - init
  11. {
  12.     id ret = [super init];
  13.     renderedImage = [NXImage findImageNamed:"Saucer.tiff"];
  14.     NX_HEIGHT(&boundingBox) = SAUCER_WIDTH;
  15.     NX_WIDTH(&boundingBox) = SAUCER_HEIGHT;
  16.     maxFrames[0] = SAUCER_FRAMES;
  17.     nextTime = SAUCER_DELAY;
  18.     return ret;
  19. }
  20.  
  21. - setStage:aStage
  22. {
  23.     id ret = [super setStage:aStage];
  24.     NXRect bounds;
  25.     [[aStage bufferType:GK_SCREEN_BUFFER] getBounds:&bounds];
  26.     screenWidth = NX_WIDTH(&bounds);
  27.     screenHeight = NX_HEIGHT(&bounds);
  28.     return ret;
  29. }
  30.  
  31. - collidedWith:anActor    // called when it is detected that we hit something
  32. {
  33.     // ***** need to remove us from the stage if hit by
  34.     // one of the player's bullets and award points, and make sound
  35.     return self;
  36. }
  37.  
  38. - move:sender        // move one frame
  39. {
  40.     if (state == SAUCER_INACTIVE) {
  41.         // decide whether or not to activate
  42.         if (!nextTime--) {
  43.             state = SAUCER_ACTIVE;
  44.             nextTime = SAUCER_DELAY;
  45.             GK_SET_VECTOR(&nextLocation, -SAUCER_WIDTH,
  46.                 screenHeight - SAUCER_HEIGHT - 4);
  47.         }
  48.         return self;
  49.     }
  50.     GK_VECTOR_X(&nextLocation) += SAUCER_MOVE_SPEED;
  51.     // all collisions are handles by collision detection machinery
  52.     if (GK_VECTOR_X(&nextLocation) >= screenWidth) {
  53.         // take saucer off of screen
  54.         state = SAUCER_INACTIVE;
  55.         nextTime = SAUCER_DELAY;
  56.     }
  57.     // ***** play "saucer on screen" sound
  58.     return self;
  59. }
  60.  
  61. @end
  62.