JoySticks [ USB ]

Status
Niet open voor verdere reacties.

blua tigro

Gebruiker
Lid geworden
21 apr 2009
Berichten
48
zo moet t in <windows.h>
Code:
//GameEngine.cpp

#include <mmsystem.h>

int mouse_x ;
int mouse_y ;
bool mouse_left ;
bool mouse_midle ;
bool mouse_right ;
bool key_alt ;
bool key_capital ;
char key_char ;
bool key_control ;
bool key_shift ;
bool key[ 256 ] ;
int joystickid1 ;
long joy1_x ;
long joy1_y ;
long joy1_button ;
int joystickid2 ;
long joy2_x ;
long joy2_y ;
long joy2_button ;
int frame ;

bool joyInit( int joymax = 1 )
{
  UINT joynomax ;
  if ( joynomax == 0 ) return false ;
  JOYINFO joyinfo ;
  if ( joyGetPos( JOYSTICKID1 , &joyinfo )
  != JOYERR_UNPLUGGED )
  {
    joystickid1 = JOYSTICKID1 ;
  }
  else return false ;
  if ( joymax == 2 )
  {
    if ( joyGetPos( JOYSTICKID2 , &joyinfo )
    != JOYERR_UNPLUGGED )
    {
      joystickid2 = JOYSTICKID2 ;
    }
    else return false ;
  } 
}

void readJoystick()
{
  JOYCAPS jc1 , jc2 ;
  JOYINFO ji1 , ji2 ;
  if ( joyGetPos( joystickid1 , &ji1 )
  != JOYERR_UNPLUGGED )
  {
    joy1_x = ( ji1.wXpos 
    - ( jc1.wXmin + jc1.wXmax ) / 2 ) 
    / jc1.wXmax * 200 ;
    joy1_y = ( ji1.wYpos 
    - ( jc1.wYmin + jc1.wYmax ) / 2 ) 
    / jc1.wYmax * 200 ; 
    joy1_button = ji1.wButtons ;   
  }
  if ( joyGetPos( joystickid2 , &ji2 )
  != JOYERR_UNPLUGGED )
  {
    joy2_x = ( ji2.wXpos 
    - ( jc2.wXmin + jc2.wXmax ) / 2 ) 
    / jc2.wXmax * 200 ;
    joy2_y = ( ji2.wYpos 
    - ( jc2.wYmin + jc2.wYmax ) / 2 ) 
    / jc2.wYmax * 200 ;    
    joy2_button = ji2.wButtons ;
  }
}
void gameInit()
{}
void gameStart()
{
  int i ;
  frame = -100 ;
  mouse_left = false ;
  mouse_midle = false ;
  mouse_right = false ;
  key_alt = false ;
  key_capital = false ;
  key_control = false ;
  key_shift = false ;
  for ( i = 0 ; i < 256 ; i++ )
  {
      key[ i ] = false ;
  }
}
void gameUpdate()
{
  int i ;
  //read input and
  //update world
  readJoystick() ;
  frame++ ;
  //reset
  mouse_left = false ;
  mouse_midle = false ;
  mouse_right = false ;
  key_alt = false ;
  key_capital = false ;
  key_control = false ;
  key_shift = false ;
  for ( i = 0 ; i < 256 ; i++ )
  {
      key[ i ] = false ;
  }
}  
void gameDraw(){}
void gameEnd(){}
void gameQuit(){}
maar dan heb ik maar 2 assen en 4 knoppen per joystick
[ en maar 2 joysticks ]
hoe maak ik DirectX Input
actief in devc++ en msc++ 2008 ?
dan heb ik 6 assen en 32 knoppen per joystick
[ en ?? joysticks ]
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan