home *** CD-ROM | disk | FTP | other *** search
/ Launch & Play / spustahrej2.iso / Egoboo / code / input.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-12-03  |  2.9 KB  |  120 lines

  1. // input.c
  2.  
  3. // Egoboo, Copyright (C) 2000 Aaron Bishop
  4.  
  5. #include "egoboo.h"
  6.  
  7. //--------------------------------------------------------------------------------------------
  8. void read_mouse()
  9. {
  10.   int x,y,b;
  11.   if (menuactive)
  12.       b = SDL_GetMouseState(&x,&y);
  13.   else
  14.       b = SDL_GetRelativeMouseState(&x,&y);
  15.   mousex = x; // mousex and mousey are the wrong type to use in above call
  16.   mousey = y;
  17.   mousebutton[0] = (b&SDL_BUTTON(1)) ? 1:0;
  18.   mousebutton[1] = (b&SDL_BUTTON(3)) ? 1:0; 
  19.   mousebutton[2] = (b&SDL_BUTTON(2)) ? 1:0; // Middle is 2 on SDL
  20.   mousebutton[3] = (b&SDL_BUTTON(4)) ? 1:0;
  21. }
  22.  
  23. //--------------------------------------------------------------------------------------------
  24. void read_key()
  25. {
  26.   sdlkeybuffer = SDL_GetKeyState(NULL);
  27. //  if(sdlkeybuffer[SDLK_RETURN]) exit(1); MN: this should no longer be necessary
  28. }
  29.  
  30. //--------------------------------------------------------------------------------------------
  31. void read_joystick()
  32. {
  33.   int button;
  34.  
  35.   if(joyaon) {
  36.     SDL_JoystickUpdate();
  37.     joyax = SDL_JoystickGetAxis(sdljoya,0) / 32;
  38.     if(joyax<100 && joyax>-100) joyax=0;
  39.       joyay = SDL_JoystickGetAxis(sdljoya,1) / 32;
  40.     if(joyay<100 && joyay>-100) joyay=0;
  41.     button = SDL_JoystickNumButtons(sdljoya);
  42.     while(button >= 0)
  43.     {
  44.       joyabutton[button] = SDL_JoystickGetButton(sdljoya, button);
  45.       button--;
  46.     }
  47.   }
  48.   if(joybon) {
  49.     SDL_JoystickUpdate();
  50.     joybx = SDL_JoystickGetAxis(sdljoyb,0) / 32;
  51.     if(joybx<100 && joybx>-100) joybx=0;
  52.       joyby = SDL_JoystickGetAxis(sdljoyb,1) / 32;
  53.     if(joyby<100 && joyby>-100) joyby=0;
  54.     button = SDL_JoystickNumButtons(sdljoyb);
  55.     while(button >= 0)
  56.     {
  57.       joybbutton[button] = SDL_JoystickGetButton(sdljoyb, button);
  58.       button--;
  59.     }
  60.   }
  61. }
  62.  
  63. //--------------------------------------------------------------------------------------------
  64. void reset_press()
  65. {
  66.     // ZZ> This function resets key press information
  67. /*PORT
  68.     int cnt;
  69.     cnt = 0;
  70.     while(cnt < 256)
  71.     {
  72.         keypress[cnt] = FALSE;
  73.         cnt++;
  74.     }
  75. */
  76. }
  77.  
  78. //--------------------------------------------------------------------------------------------
  79. void read_input()
  80. {
  81.     // ZZ> This function gets all the current player input states
  82.     int cnt;
  83.     SDL_Event ev;
  84.  
  85.     SDL_PumpEvents();
  86.     read_key();
  87.     read_mouse();
  88.     read_joystick();
  89.  
  90.     while(SDL_PollEvent(&ev))
  91.       {
  92.     switch(ev.type)
  93.       {
  94.       case SDL_MOUSEBUTTONDOWN:
  95.         pending_click = TRUE;
  96.         break;
  97.       }
  98.       }
  99.  
  100.     // Set up for button masks
  101.     jab = 0;
  102.     jbb = 0;
  103.     msb = 0;
  104.  
  105.  
  106.     // Joystick mask
  107.     cnt = 0;
  108.     while(cnt < JOYBUTTON)
  109.     {
  110.         jab |= (joyabutton[cnt]<<cnt);
  111.         jbb |= (joybbutton[cnt]<<cnt);
  112.         cnt++;
  113.     }
  114.  
  115.  
  116.     // Mouse mask
  117.     msb=(mousebutton[3]<<3)|(mousebutton[2]<<2)|(mousebutton[1]<<1)|(mousebutton[0]<<0);
  118. }
  119.  
  120.