home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / apilot.lha / APilot / APilot_Opt / input.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-03  |  2.5 KB  |  105 lines

  1. /*
  2.  * input.c -- Functions handling the input from the user to the program
  3.  *
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <intuition/intuition.h>    /* Intuition data strucutres, etc.    */
  8. #include <libraries/dos.h>          /* Official return codes defined here */
  9.  
  10. #ifdef LATTICE
  11.   #include <proto/exec.h>
  12. #else
  13.   #include <clib/exec_protos.h>
  14. #endif
  15.  
  16. #include "points_protos.h"
  17.  
  18. #include "common.h"
  19. #include "defs.h"
  20.  
  21. #include "input.h"
  22.  
  23. /*
  24.  * handleIDCMP -- Reads keyboard events and does what the user tells it
  25.  *                to do.
  26.  */
  27.  
  28. BOOL handleIDCMP( struct Window *win, AShip *aShip, 
  29.                     struct timerequest *iRB, ULONG oldrd )
  30. {
  31.   BOOL done = FALSE;
  32.   BOOL keyup;
  33.   struct IntuiMessage *message;    
  34.   ULONG class;
  35.   USHORT code;
  36.   USHORT qual;
  37.  
  38.   /* Examine pending messages */
  39.   while( message = (struct IntuiMessage *)GetMsg(win->UserPort) )
  40.   {
  41.     class = message->Class;  /* get all data we need from message */
  42.     code  = message->Code;
  43.     qual  = message->Qualifier;
  44.  
  45.     /* When we're through with a message, reply */
  46.     ReplyMsg( (struct Message *)message);
  47.  
  48.     /* See what events occurred */
  49.     keyup = (code & 0x80);
  50.  
  51.     switch( class ) {
  52.       case IDCMP_RAWKEY:
  53.         if(qual & IEQUALIFIER_RSHIFT)
  54.           aShip->thrusting = TRUE;
  55.         else
  56.           aShip->thrusting = FALSE;
  57.  
  58.         switch( 0x7F & code )
  59.         {
  60.           case RAWKEY_A:
  61.             if (keyup)
  62.               aShip->rotspeed = 0;
  63.             else
  64.               aShip->rotspeed = -ROT_SPEED;
  65.             break;
  66.           case RAWKEY_S:
  67.             if (keyup)
  68.               aShip->rotspeed = 0;
  69.             else
  70.               aShip->rotspeed = ROT_SPEED;
  71.             break;
  72.           case RAWKEY_ENTER:
  73.             if (!keyup)
  74.               aShip->fireing = TRUE;
  75.             break;
  76.           case RAWKEY_T:
  77.             if (!keyup)
  78.               add_explosion( 320, 256 );
  79.             break;
  80.           case RAWKEY_Q:  
  81.             iRB->tr_time.tv_secs = oldrd;
  82.             DoIO((struct IORequest *) iRB);
  83.             done = TRUE;
  84.             break;
  85.           default:
  86.             break;
  87.         }
  88.         break;
  89.       case IDCMP_ACTIVEWINDOW:
  90.         iRB->tr_time.tv_secs = 1000;  /* Should be enough to prevent */
  91.                                               /* repeat.                     */
  92.         DoIO((struct IORequest *) iRB);
  93.         break;
  94.       case IDCMP_INACTIVEWINDOW:
  95.         iRB->tr_time.tv_secs = oldrd;
  96.         DoIO((struct IORequest *) iRB);
  97.         break;
  98.       default:
  99.          break;
  100.     }
  101.   }
  102.   return(done);
  103. }
  104.  
  105.