Exemplo n.º 1
0
u32 InputDevices::GetPadButtonStatus(int channel)
{
    u32 extensions;
    WPADData data;
    u32 buttons, gcbuttons;
    PAD2WPAD *p2w;
    joystick_t padjoy;

    // Check standard buttons
    buttons = WPAD_ButtonsHeld(channel);

    // Add GameCube buttons
    gcbuttons = PAD_ButtonsHeld(channel);
    p2w = pad2wpad;
    while( p2w->pad ) {
        if( gcbuttons & p2w->pad ) {
            buttons |= p2w->wpad;
        }
        p2w++;
    }

    // Key translations for default WiiMote buttons
    ProcessWPadButtons(channel, wpad_default);

    // Check extensions
    WPAD_Probe(channel, &extensions);
    if( extensions == WPAD_EXP_NUNCHUK ) {
      // Nunchuk stick
      WPAD_Expansion(channel, &data.exp);
      buttons |= GetJoystickDirection(&data.exp.nunchuk.js);
      // Nunchuck key translations
      ProcessWPadButtons(channel, wpad_nunchuk);
    } else if( extensions == WPAD_EXP_CLASSIC ) {
      // Both classic controller sticks
      WPAD_Expansion(channel, &data.exp);
      buttons |= GetJoystickDirection(&data.exp.classic.ljs);
      buttons |= GetJoystickDirection(&data.exp.classic.rjs);
      // Classic controller key translations
      ProcessWPadButtons(channel, wpad_classic);
    }

    // Scan GameCube sticks
    padjoy.min.x = 0;
    padjoy.min.y = 0;
    padjoy.max.x = 255;
    padjoy.max.y = 255;
    padjoy.center.x = 128;
    padjoy.center.y = 128;

    padjoy.pos.x = (int)PAD_StickX(channel) + 128;
    padjoy.pos.y = (int)PAD_StickY(channel) + 128;
    buttons |= GetJoystickDirection(&padjoy);

    padjoy.pos.x = (int)PAD_SubStickX(channel) + 128;
    padjoy.pos.y = (int)PAD_SubStickY(channel) + 128;
    buttons |= GetJoystickDirection(&padjoy);

    return buttons;
}
Exemplo n.º 2
0
    void TProfanationGame::updateInputController()
    {
	  struct expansion_t stick;
	  bool sleft=false,sright=false,sup=false,sdown=false,nun_C=false,nun_Z=false;
	  
	  WPAD_ScanPads();
	  WPAD_Expansion(WPAD_CHAN_0, &stick);
 
	  u16 buttonsHeld = WPAD_ButtonsHeld(0);
	  u16 buttonsDown = WPAD_ButtonsDown(0);
		
	  if(stick.type == WPAD_EXP_NUNCHUK)
	  {
		float diffx = stick.nunchuk.js.pos.x - stick.nunchuk.js.center.x; 
		float diffy = stick.nunchuk.js.pos.y - stick.nunchuk.js.center.y; 
		
        if(fabs(diffx)>SENSIBILITY)  
        { 
		  sright = (stick.nunchuk.js.pos.x > stick.nunchuk.js.center.x);
		  sleft = (stick.nunchuk.js.pos.x < stick.nunchuk.js.center.x);
		} 
    
        if(fabs(diffy)>SENSIBILITY)  
        { 
		  sup = (stick.nunchuk.js.pos.y > stick.nunchuk.js.center.y);
		  sdown = (stick.nunchuk.js.pos.y < stick.nunchuk.js.center.y);
		} 

		nun_C = stick.nunchuk.btns_held & NUNCHUK_BUTTON_C;
		nun_Z = stick.nunchuk.btns_held & NUNCHUK_BUTTON_Z;
		
		inputController.setStatus(GKEY_LEFT, sleft ||  (buttonsHeld & WPAD_BUTTON_LEFT));
		inputController.setStatus(GKEY_RIGHT,sright || (buttonsHeld & WPAD_BUTTON_RIGHT));
		inputController.setStatus(GKEY_UP,   sup ||    (buttonsHeld & WPAD_BUTTON_UP));
		inputController.setStatus(GKEY_DOWN, sdown ||  (buttonsHeld & WPAD_BUTTON_DOWN));
        
		inputController.setStatus(GKEY_LONG_JUMP, nun_C || (buttonsDown & WPAD_BUTTON_1));
		inputController.setStatus(GKEY_SHORT_JUMP, nun_Z || (buttonsDown & WPAD_BUTTON_2));
	  }
	  else
	  {      
	    inputController.setStatus(GKEY_LEFT, (buttonsHeld & WPAD_BUTTON_UP));
        inputController.setStatus(GKEY_RIGHT,(buttonsHeld & WPAD_BUTTON_DOWN));
        inputController.setStatus(GKEY_UP,   (buttonsHeld & WPAD_BUTTON_RIGHT));
        inputController.setStatus(GKEY_DOWN, (buttonsHeld & WPAD_BUTTON_LEFT));
        
        inputController.setStatus(GKEY_LONG_JUMP, (buttonsDown & WPAD_BUTTON_1));
        inputController.setStatus(GKEY_SHORT_JUMP,(buttonsDown & WPAD_BUTTON_2));
      }
    
      inputController.setStatus(GKEY_SELECT,(buttonsDown & WPAD_BUTTON_A));
      inputController.setStatus(GKEY_ABORT,(buttonsDown & WPAD_BUTTON_HOME));

      inputController.setStatus(GKEY_SCR_PLUS,(buttonsDown & WPAD_BUTTON_PLUS));
      inputController.setStatus(GKEY_SCR_MINUS,(buttonsDown & WPAD_BUTTON_MINUS));
    }
Exemplo n.º 3
0
u32 GetCtlType(int ctl) {
	struct expansion_t ext;
	u32 devtype;
	u32 ret;
	u32 type;
	ret=WPAD_Probe(WPAD_CHAN_0, &type);
	WPAD_Expansion(ctl, &ext);
	devtype=ext.type;
	if (devtype == WPAD_EXP_NONE) return 0;
	if (devtype == WPAD_EXP_NUNCHUK) {printf("\x1b[20;0HNunchuk X: %d\n Nunchuk Y: %d\n", ext.nunchuk.js.pos.x, ext.nunchuk.js.pos.y); return 1;}
	if (devtype == WPAD_EXP_CLASSIC) return 2;
	return devtype;
}
Exemplo n.º 4
0
qboolean IN_GetClsCtCursorPos(incursorcoords_t* p)
{
	expansion_t e;

	WPAD_Expansion(WPAD_CHAN_0, &e);
	if(e.type != WPAD_EXP_CLASSIC)
		return false;		

	p->x = window_center_x + (e.classic.rjs.pos.x - e.classic.rjs.center.x);
	p->y = window_center_y + (e.classic.rjs.pos.y - e.classic.rjs.center.y);
	if((p->x == window_center_x)&&(p->y == window_center_y))
		return false;

	return true;
}
Exemplo n.º 5
0
void IN_ClsCtLeftStickMove (usercmd_t *cmd)
{
	expansion_t e;
	int cx;
	int cy;

	WPAD_Expansion(WPAD_CHAN_0, &e);
	if(e.type != WPAD_EXP_CLASSIC)
		return;

	cx = e.classic.ljs.pos.x - e.classic.ljs.center.x;
	cy = e.classic.ljs.pos.y - e.classic.ljs.center.y;
	if((cx > -in_clsctmovmin->value)&&(cx < in_clsctmovmin->value))
		cx = 0;
	if((cy > -in_clsctmovmin->value)&&(cy < in_clsctmovmin->value))
		cy = 0;
	if((cx == 0)&&(cy == 0))
		return;

	cmd->sidemove += m_side->value * cx * in_clsctmovscale->value;
	cmd->forwardmove += m_forward->value * cy * in_clsctmovscale->value;
}
Exemplo n.º 6
0
void IN_NunchukMove (usercmd_t *cmd)
{
	expansion_t e;
	int nx;
	int ny;

	WPAD_Expansion(WPAD_CHAN_0, &e);
	if(e.type != WPAD_EXP_NUNCHUK)
		return;

	nx = e.nunchuk.js.pos.x - e.nunchuk.js.center.x;
	ny = e.nunchuk.js.pos.y - e.nunchuk.js.center.y;
	if((nx > -in_wmotemovmin->value)&&(nx < in_wmotemovmin->value))
		nx = 0;
	if((ny > -in_wmotemovmin->value)&&(ny < in_wmotemovmin->value))
		ny = 0;
	if((nx == 0)&&(ny == 0))
		return;

	cmd->sidemove += m_side->value * nx * in_wmotemovscale->value;
	cmd->forwardmove += m_forward->value * ny * in_wmotemovscale->value;
}
Exemplo n.º 7
0
/*
 * Pause and wait for input. Usually used when debugging.
 */
void wii_pause()
{
  int done = 0;
  while( !done )
  {		
    WPAD_ScanPads();
    PAD_ScanPads();

    expansion_t exp;
    WPAD_Expansion( 0, &exp );        
    bool isClassic = ( exp.type == WPAD_EXP_CLASSIC );

    u32 down = WPAD_ButtonsDown(0);
    u32 gcDown = PAD_ButtonsDown(0);

    if( ( down & ( WII_BUTTON_A | 
          ( isClassic ? 
            WII_CLASSIC_BUTTON_A : WII_NUNCHUK_BUTTON_A ) ) ) || 
        ( gcDown & GC_BUTTON_A ) )
    {	
      done = 1;
    }
  }
}
Exemplo n.º 8
0
int grlib_GetUserInput (void)
	{
	u32  wbtn, gcbtn, cbtn;
	s8  gcX, gcY;
	int nX, nY;
	int cX, cY;
	
	static float g[MAXG];
	static int gidx = -1;
	static u32 gestureDisable = 0;
	
	u32 ms = ticks_to_millisecs(gettime());
	u32 mstout = ms+200;
		
	struct expansion_t e; //nunchuk
	
	if (gidx == -1)
		{
		memset (&g, 0, sizeof(g));
		gidx = 0;
		}
	
	WPAD_ScanPads();  // Scan the Wiimotes
	wbtn = WPAD_ButtonsDown(0);

	if (grlibSettings.usesGestures && ms > gestureDisable)
		{
		WPADData *wp = WPAD_Data (0);
		g[gidx] = wp->gforce.x;
		/*
		int gidx2 = gidx - 10;
		int gidx3 = gidx - 20;
		if (gidx2 < 0) gidx2 = (MAXG-1) - gidx2;
		if (gidx3 < 0) gidx3 = (MAXG-1) - gidx3;
		
		if (g[gidx2] < -2.0 && g[gidx] > -1.5 && g[gidx3] > -1.5)
			{
			memset (&g, 0, sizeof(g));
			return WPAD_BUTTON_MINUS;
			//Debug ("left");
			}
		if (g[gidx2] > 2.0 && g[gidx] < 1.5 && g[gidx3] < 1.5)
			{
			memset (&g, 0, sizeof(g));
			return WPAD_BUTTON_PLUS;
			//Debug ("right");
			}
		*/
		int i;
		float mean = 0;
		for (i = 0; i < MAXG; i++)
			mean+=g[i];
		mean /= (float) MAXG;
		
		// gprintf ("%.2f\n", mean);

		if (mean < -1.5)
			{
			memset (&g, 0, sizeof(g));
			gestureDisable = ms+1000;
			return WPAD_BUTTON_MINUS;
			}
		if (mean > 1.5)
			{
			memset (&g, 0, sizeof(g));
			gestureDisable = ms+1000;
			return WPAD_BUTTON_PLUS;
			}
		
		if (++gidx >= MAXG) gidx = 0;
		}
	
	//Debug ("wm = %.1f,%.1f,%.1f", wp->gforce.x,wp->gforce.y,wp->gforce.z);
	//Debug ("wm = %.1f,%.1f,%.1f", wp->orient.roll,wp->orient.pitch,wp->orient.yaw);
	
	
	WPAD_Expansion( 0, &e );
	
	if (e.type != WPAD_EXP_NUNCHUK)
		{
		nX = 0;
		nY = 0;
		}
	else
		{
		nX = e.nunchuk.js.pos.x - e.nunchuk.js.center.x;
		nY = e.nunchuk.js.pos.y - e.nunchuk.js.center.y;
		}

	if (e.type != WPAD_EXP_CLASSIC)
		{
		cX = 0;
		cY = 0;
		cbtn = 0;
		}
	else
		{
		cX = e.classic.ljs.pos.x - e.classic.ljs.center.x;
		cY = e.classic.ljs.pos.y - e.classic.ljs.center.y;
		cbtn = e.classic.btns;
		}
	
	PAD_ScanPads();
	gcX = PAD_StickX(0);
	gcY = PAD_StickY(0);
	gcbtn = PAD_ButtonsDown(0);
	
	// sticks
	if (abs (nX) > 10) {grlib_irPos.x += (nX / 16); grlibSettings.cursorActivity++;}
	if (abs (nY) > 10) {grlib_irPos.y -= (nY / 16); grlibSettings.cursorActivity++;}
	
	if (abs (gcX) > 10) {grlib_irPos.x += (gcX / 16); grlibSettings.cursorActivity++;}
	if (abs (gcY) > 10) {grlib_irPos.y -= (gcY / 16); grlibSettings.cursorActivity++;}
	
	if (abs (cX) > 10) {grlib_irPos.x += (cX / 4); grlibSettings.cursorActivity++;}
	if (abs (cY) > 10) {grlib_irPos.y -= (cY / 4); grlibSettings.cursorActivity++;}
	
	// Check limits
	if (grlib_irPos.x < 0) grlib_irPos.x = 0;
	if (grlib_irPos.x > 640) grlib_irPos.x = 640;
	
	if (grlib_irPos.y < 0) grlib_irPos.y = 0;
	if (grlib_irPos.y > 480) grlib_irPos.y = 480;
	
	// As usual wiimotes will have priority
	if (wbtn)
		{
		grlibSettings.buttonActivity ++;
		// Wait until button is released
		
		while (WPAD_ButtonsDown(0) && ticks_to_millisecs(gettime()) < mstout) WPAD_ScanPads();
		return wbtn;
		}

	// Then gc
	if (gcbtn)
		{
		grlibSettings.buttonActivity ++;
		
		// Wait until button is released
		
		while (PAD_ButtonsDown(0) && ticks_to_millisecs(gettime()) < mstout) PAD_ScanPads();
		
		// Convert to wiimote values
		if (gcbtn & PAD_TRIGGER_R) return WPAD_BUTTON_PLUS;
		if (gcbtn & PAD_TRIGGER_L) return WPAD_BUTTON_MINUS;

		if (gcbtn & PAD_BUTTON_A) return WPAD_BUTTON_A;
		if (gcbtn & PAD_BUTTON_B) return WPAD_BUTTON_B;
		if (gcbtn & PAD_BUTTON_X) return WPAD_BUTTON_1;
		if (gcbtn & PAD_BUTTON_Y) return WPAD_BUTTON_2;
		if (gcbtn & PAD_BUTTON_MENU) return WPAD_BUTTON_HOME;
		if (gcbtn & PAD_BUTTON_UP) return WPAD_BUTTON_UP;
		if (gcbtn & PAD_BUTTON_LEFT) return WPAD_BUTTON_LEFT;
		if (gcbtn & PAD_BUTTON_DOWN) return WPAD_BUTTON_DOWN;
		if (gcbtn & PAD_BUTTON_RIGHT) return WPAD_BUTTON_RIGHT;
		}
		
	// Classic
	if (cbtn)
		{
		grlibSettings.buttonActivity ++;
		
		while (e.classic.btns && ticks_to_millisecs(gettime()) < mstout)
			{
			WPAD_ScanPads();  // Scan the Wiimotes
			WPAD_Expansion( 0, &e );
			}
		
		// Convert to wiimote values
		if (cbtn & CLASSIC_CTRL_BUTTON_ZR) return WPAD_BUTTON_PLUS;
		if (cbtn & CLASSIC_CTRL_BUTTON_ZL) return WPAD_BUTTON_MINUS;
		
		if (cbtn & CLASSIC_CTRL_BUTTON_PLUS) return WPAD_BUTTON_PLUS;
		if (cbtn & CLASSIC_CTRL_BUTTON_MINUS) return WPAD_BUTTON_MINUS;

		if (cbtn & CLASSIC_CTRL_BUTTON_A) return WPAD_BUTTON_A;
		if (cbtn & CLASSIC_CTRL_BUTTON_B) return WPAD_BUTTON_B;
		if (cbtn & CLASSIC_CTRL_BUTTON_X) return WPAD_BUTTON_1;
		if (cbtn & CLASSIC_CTRL_BUTTON_Y) return WPAD_BUTTON_2;
		if (cbtn & CLASSIC_CTRL_BUTTON_HOME) return WPAD_BUTTON_HOME;
		}
	
	
	return 0;
	}
Exemplo n.º 9
0
/*
 * Updates the joystick state
 *
 * joyIndex         The joystick index
 * keyboard_data    The keyboard (controls) state
 */
static void wii_atari_update_joystick( int joyIndex, unsigned char keyboard_data[19] )
{
  // Check the state of the controllers
  u32 down = WPAD_ButtonsDown( joyIndex );
  u32 held = WPAD_ButtonsHeld( joyIndex );
  u32 gcDown = PAD_ButtonsDown( joyIndex );
  u32 gcHeld = PAD_ButtonsHeld( joyIndex );

  // Check to see if the lightgun is enabled (lightgun only works for
  // joystick index 0).
  bool lightgun = ( lightgun_enabled && ( joyIndex == 0 ) );

  if( lightgun )
  {
    // Determine the Y offset of the lightgun location
    int yoffset = ( cartridge_region == REGION_NTSC ? 
      ( NTSC_ATARI_BLIT_TOP_Y ) : ( PAL_ATARI_BLIT_TOP_Y - 28 ) );

    // The number of scanlines for the current cartridge
    int scanlines = ( cartridge_region == REGION_NTSC ? 
                        NTSC_ATARI_HEIGHT : PAL_ATARI_HEIGHT );
    wii_dbg_scanlines = scanlines;

    // We track the first time the lightgun is fired due to the fact that
    // when a catridge is launched (via the Wii7800 menu) the state of the
    // fire button (down) is used to determine whether the console has a
    // joystick or lightgun plugged in.
    if( lightgun_first_fire )
    {
      if( !( held & ( WPAD_BUTTON_B | WPAD_BUTTON_A ) ) )
      {
        // The button is not down, enable lightgun firing.
        lightgun_first_fire = false;
      }            
      keyboard_data[3] = true;
    }
    else
    {
      keyboard_data[3] = !( held & ( WPAD_BUTTON_B | WPAD_BUTTON_A ) );
    }

    //
    // TODO: These values should be cached
    //
    float yratio = ( (float)scanlines / (float)WII_HEIGHT );
    float xratio = ( (float)LG_CYCLES_PER_SCANLINE / (float)WII_WIDTH );
    lightgun_scanline = ( ( (float)wii_ir_y * yratio ) + 
      ( maria_visibleArea.top - maria_displayArea.top + 1 ) + yoffset );
    lightgun_cycle = ( HBLANK_CYCLES + LG_CYCLES_INDENT + 
      ( (float)wii_ir_x * xratio ) );
    if( lightgun_cycle > CYCLES_PER_SCANLINE )
    {
      lightgun_scanline++;
      lightgun_cycle -= CYCLES_PER_SCANLINE; 
    }
  }
  else
  {
    expansion_t exp;
    WPAD_Expansion( joyIndex, &exp );
    bool isClassic = ( exp.type == WPAD_EXP_CLASSIC );

    float expX = wii_exp_analog_val( &exp, TRUE, FALSE );
    float expY = wii_exp_analog_val( &exp, FALSE, FALSE );
    s8 gcX = PAD_StickX( joyIndex );
    s8 gcY = PAD_StickY( joyIndex );

    float expRjsX = 0, expRjsY = 0;
    s8 gcRjsX = 0, gcRjsY = 0;

    // Dual analog support
    if( cartridge_dualanalog && joyIndex == 1  )
    {
      expansion_t exp0;
      WPAD_Expansion( 0, &exp0 );
      if( exp0.type == WPAD_EXP_CLASSIC  )
      {
        expRjsX = wii_exp_analog_val( &exp0, TRUE, TRUE );
        expRjsY = wii_exp_analog_val( &exp0, FALSE, TRUE );
      }

      gcRjsX = PAD_SubStickX( 0 );
      gcRjsY = PAD_SubStickY( 0 );
    }

    int offset = ( joyIndex == 0 ? 0 : 6 );

    // | 00 06     | Joystick 1 2 | Right
    keyboard_data[0 + offset] = 
      ( held & WII_BUTTON_ATARI_RIGHT || gcHeld & GC_BUTTON_ATARI_RIGHT ||
      wii_analog_right( expX, gcX ) || wii_analog_right( expRjsX, gcRjsX ) );
    // | 01 07     | Joystick 1 2 | Left
    keyboard_data[1 + offset] = 
      ( held & ( WII_BUTTON_ATARI_LEFT | ( isClassic ? WII_CLASSIC_ATARI_LEFT : 0 ) ) || 
      gcHeld & GC_BUTTON_ATARI_LEFT || wii_analog_left( expX, gcX ) ||
      wii_analog_left( expRjsX, gcRjsX ) );
    // | 02 08     | Joystick 1 2 | Down
    keyboard_data[2 + offset] = 
      ( held & WII_BUTTON_ATARI_DOWN || gcHeld & GC_BUTTON_ATARI_DOWN || 
      wii_analog_down( expY, gcY ) || wii_analog_down( expRjsY, gcRjsY ) );
    // | 03 09     | Joystick 1 2 | Up
    keyboard_data[3 + offset] = 
      ( held & ( WII_BUTTON_ATARI_UP | ( isClassic ? WII_CLASSIC_ATARI_UP : 0 ) ) || 
      gcHeld & GC_BUTTON_ATARI_UP || wii_analog_up( expY, gcY ) ||
      wii_analog_up( expRjsY, gcRjsY ) );
    // | 04 10     | Joystick 1 2 | Button 1
    keyboard_data[wii_swap_buttons ? 4 + offset : 5 + offset] = 
      ( held & ( WII_BUTTON_ATARI_FIRE | 
      ( isClassic ? WII_CLASSIC_ATARI_FIRE : WII_NUNCHECK_ATARI_FIRE ) ) || 
      gcHeld & GC_BUTTON_ATARI_FIRE );
    // | 05 11     | Joystick 1 2 | Button 2
    keyboard_data[wii_swap_buttons ? 5 + offset : 4 + offset] = 
      ( held & ( WII_BUTTON_ATARI_FIRE_2 | 
      ( isClassic ? WII_CLASSIC_ATARI_FIRE_2 : WII_NUNCHECK_ATARI_FIRE_2 ) ) || 
      gcHeld & GC_BUTTON_ATARI_FIRE_2 );
  }

  if( joyIndex == 0 )
  {
    // | 12       | Console      | Reset
    keyboard_data[12] = ( held & WII_BUTTON_ATARI_RESET || gcHeld & GC_BUTTON_ATARI_RESET );
    // | 13       | Console      | Select
    keyboard_data[13] = ( held & WII_BUTTON_ATARI_SELECT || gcHeld & GC_BUTTON_ATARI_SELECT );
    // | 14       | Console      | Pause               
    keyboard_data[14] = ( held & WII_BUTTON_ATARI_PAUSE || gcHeld & GC_BUTTON_ATARI_PAUSE );

    if( wii_diff_switch_enabled )
    {
      // | 15       | Console      | Left Difficulty
      if( ( diff_wait_count == 0 ) && 
        ( ( gcDown & GC_BUTTON_ATARI_DIFFICULTY_LEFT ) ||
        ( ( !lightgun && ( down & WII_BUTTON_ATARI_DIFFICULTY_LEFT ) ) ||
        ( lightgun && ( down & WII_BUTTON_ATARI_DIFFICULTY_LEFT_LG ) ) ) ) )
      {
        if( !left_difficulty_down )
        {
          keyboard_data[15] = !keyboard_data[15];
          left_difficulty_down = true;   
          diff_display_count = prosystem_frequency * DIFF_DISPLAY_LENGTH;
        }
      }
      else
      {
        left_difficulty_down = false;
      }
      // | 16       | Console      | Right Difficulty        
      if( ( diff_wait_count == 0 ) && 
        ( ( gcDown & GC_BUTTON_ATARI_DIFFICULTY_RIGHT ) ||
        ( ( !lightgun && ( down & WII_BUTTON_ATARI_DIFFICULTY_RIGHT ) ) ||
        ( lightgun && ( down & WII_BUTTON_ATARI_DIFFICULTY_RIGHT_LG ) ) ) ) )                  
      {
        if( !right_difficulty_down )
        {
          keyboard_data[16] = !keyboard_data[16];
          right_difficulty_down = true;    
          diff_display_count = prosystem_frequency * DIFF_DISPLAY_LENGTH;
        }
      }
      else
      {
        right_difficulty_down = false;
      }
    }

    if( ( down & WII_BUTTON_HOME ) || ( gcDown & GC_BUTTON_HOME ) || wii_hw_button )
    {
      wii_atari_pause( true );
    }
  }    
}
Exemplo n.º 10
0
void getClassicControllerPadInput() 
{
   u32 pressed;
   int dpadPressed=0;
   int virtualJoyIndex=0;
   int physicalJoyIndex=0;
   SDL_Event keyDownEvent[MAX_EVENTS_PER_CYCLE];
   
   //************************************************
   // Buttons PRESSED
   //************************************************
   for (virtualJoyIndex=0; virtualJoyIndex<2; virtualJoyIndex++)
   {
      if (joyClassicUsed[virtualJoyIndex]==0) continue;
      physicalJoyIndex = virtualJoyIndex;
      if (joyGcUsed[0]==1)
      {
         physicalJoyIndex=0;
      }
      pressed = buttonsDown[physicalJoyIndex];
      int keyDownIndex=0;
      
      if (pressed & WPAD_CLASSIC_BUTTON_A)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_09;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_Y)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_10;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_X)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_11;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_B)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_12;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_PLUS)
      {
         keyDownEvent[keyDownIndex].key.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].key.type=SDL_KEYDOWN;
         keyDownEvent[keyDownIndex].key.keysym.sym=SDLK_F12;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_HOME)
      {
         keyDownEvent[keyDownIndex].key.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].key.type=SDL_KEYDOWN;
         keyDownEvent[keyDownIndex].key.keysym.sym=SDLK_F1;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_MINUS)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_13;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);	  
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_ZR)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_02;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_FULL_R)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);  
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_ZL)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_01;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_FULL_L)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      //************************************************
      // Buttons PRESSED --> D-Pads
      //************************************************
     
      if (pressed & WPAD_CLASSIC_BUTTON_RIGHT)
      {
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 0;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_DOWN)
      {
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 1;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;      
      }
       
      if (pressed & WPAD_CLASSIC_BUTTON_LEFT)
      {
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 0;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;      
      }
       
      if (pressed & WPAD_CLASSIC_BUTTON_UP)
      {
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 1;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;      
      }
     
      //************************************************
      // Buttons Held --> D-Pads
      //************************************************
      
      pressed = buttonsHeld[physicalJoyIndex];
      int keyHeldIndex=0;
      SDL_Event keyHeldEvent[MAX_EVENTS_PER_CYCLE];
      
      if (pressed & WPAD_CLASSIC_BUTTON_RIGHT)
      {
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 0;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);  
         dpadPressed=1;
      }
    
      if (pressed & WPAD_CLASSIC_BUTTON_DOWN)
      {
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 1;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);
         dpadPressed=1;
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_LEFT)
      {
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 0;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);
         dpadPressed=1;         
      }
    
      if (pressed & WPAD_CLASSIC_BUTTON_UP)
      {
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 1;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);
         dpadPressed=1;         
      }
      
      //************************************************
      // Buttons RELEASED
      //************************************************
      
      pressed = buttonsUp[physicalJoyIndex];
      int keyUpIndex=0;
      SDL_Event keyUpEvent[MAX_EVENTS_PER_CYCLE];
      
      if (pressed & WPAD_CLASSIC_BUTTON_A)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_09;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_Y)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_10;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_X)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_11;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_B)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_12;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_PLUS)
      {
         keyUpEvent[keyUpIndex].key.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].key.type=SDL_KEYUP;
         keyUpEvent[keyUpIndex].key.keysym.sym=SDLK_F12;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_HOME)
      {
         keyUpEvent[keyUpIndex].key.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].key.type=SDL_KEYUP;
         keyUpEvent[keyUpIndex].key.keysym.sym=SDLK_F1;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_MINUS)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_13;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);	  
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_ZR)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_02;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_FULL_R )
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_ZL)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_01;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
      }
      
      if (pressed & WPAD_CLASSIC_BUTTON_FULL_L)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);  
      }
      
      //************************************************
      // Buttons RELEASED --> D-Pads
      //************************************************
      
      if (pressed & WPAD_CLASSIC_BUTTON_RIGHT)
      {
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 0;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
    
      if (pressed & WPAD_CLASSIC_BUTTON_DOWN)
      {
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 1;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
    
      if (pressed & WPAD_CLASSIC_BUTTON_LEFT)
      {
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 0;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
    
      if (pressed & WPAD_CLASSIC_BUTTON_UP)
      {
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 1;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }

      //************************************************
      // Left stick --> JoyAXIS
      //************************************************
      int x=0;
      int y=0;
      struct expansion_t ext;
      int angleIndex = 0;
      WPAD_Expansion(physicalJoyIndex, &ext);
      
      if (!dpadPressed)
      {
         x = ext.classic.ljs.pos.x-DEFAULT_CLASSIC_LEFT_X_CENTER;
         y = ext.classic.ljs.pos.y-DEFAULT_CLASSIC_LEFT_Y_CENTER;
         angleIndex = getAngleIndex(x,y);
        
         SDL_Event xevent;
         xevent.type = SDL_JOYAXISMOTION;
         xevent.jaxis.which=virtualJoyIndex;
         xevent.jaxis.axis = 0;
         
         SDL_Event yevent;
         yevent.type = SDL_JOYAXISMOTION;
         yevent.jaxis.which=virtualJoyIndex;
         yevent.jaxis.axis = 1;
         
         getSDLJoyAxisEvent(&xevent, &yevent, angleIndex);
         
         if ( 
             (x < CLASSIC_LEFT_X_TOLERANCE) &&
             (x > -CLASSIC_LEFT_X_TOLERANCE)
             )
         {
            xevent.jaxis.value = 0;
         }
          
         if (
             (y < CLASSIC_LEFT_Y_TOLERANCE) &&
             (y > -CLASSIC_LEFT_Y_TOLERANCE)
            )
         {
            yevent.jaxis.value = 0;
         }
         if (ext.type & WPAD_EXP_CLASSIC)
         {
            SDL_PushEvent(&xevent); 
            SDL_PushEvent(&yevent);
         }           
      }
     
      
      //************************************************
      // Right stick --> HAT
      //************************************************
      
      x = ext.classic.rjs.pos.x-DEFAULT_CLASSIC_RIGHT_X_CENTER;
      y = ext.classic.rjs.pos.y-DEFAULT_CLASSIC_RIGHT_Y_CENTER;
      angleIndex = getAngleIndex(x,y);
      
      SDL_Event hatEvent;
      hatEvent.type = SDL_JOYHATMOTION;
      hatEvent.jhat.which=virtualJoyIndex;
      hatEvent.jhat.hat = 0;
      hatEvent.jhat.value = SDL_HAT_CENTERED;
     
      if ( 
          (x > CLASSIC_RIGHT_X_TOLERANCE) ||
          (x < -CLASSIC_RIGHT_X_TOLERANCE)||
          (y > CLASSIC_RIGHT_Y_TOLERANCE) ||
          (y < -CLASSIC_RIGHT_Y_TOLERANCE)
         )
      {
          getHatEvent(&hatEvent, angleIndex);
      }
      if (lastHatSent[hatEvent.jhat.which] != hatEvent.jhat.value)
      {
        SDL_PushEvent(&hatEvent);
        lastHatSent[hatEvent.jhat.which] = hatEvent.jhat.value;
      }
   }
}
Exemplo n.º 11
0
void getWiimoteAndNunchukPadInput()
{
   u32 pressed;
   int virtualJoyIndex=0;
   int physicalJoyIndex=0;
   SDL_Event keyDownEvent[MAX_EVENTS_PER_CYCLE];
   
   //************************************************
   // Buttons PRESSED
   //************************************************
   for (virtualJoyIndex=0; virtualJoyIndex<2; virtualJoyIndex++)
   {
      if (joyNunchukUsed[virtualJoyIndex]==0) continue;
      physicalJoyIndex = virtualJoyIndex;
      if (joyGcUsed[0]==1)
      {
         physicalJoyIndex=0;
      }
      pressed = buttonsDown[physicalJoyIndex];
      int keyDownIndex=0;
      
      if (pressed & WPAD_BUTTON_2)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_09;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_BUTTON_1)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_10;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_BUTTON_A)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_11;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
      }
      
      if (pressed & WPAD_BUTTON_PLUS)
      {
         keyDownEvent[keyDownIndex].key.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].key.type=SDL_KEYDOWN;
         keyDownEvent[keyDownIndex].key.keysym.sym=SDLK_F12;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_BUTTON_HOME)
      {
         keyDownEvent[keyDownIndex].key.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].key.type=SDL_KEYDOWN;
         keyDownEvent[keyDownIndex].key.keysym.sym=SDLK_F1;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_BUTTON_MINUS)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_13;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);	  
      }
      
      if (pressed & WPAD_BUTTON_B)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_02;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & WPAD_NUNCHUK_BUTTON_C)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);  
      }
      
      if (pressed & WPAD_NUNCHUK_BUTTON_Z)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_01;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      //************************************************
      // Buttons PRESSED --> D-Pads
      //************************************************
      /*
      int x=0;
      int y=0;
      int angleIndex=0;
      
      if (pressed & WPAD_BUTTON_RIGHT)y=1000;
      if (pressed & WPAD_BUTTON_DOWN) x=1000;
      if (pressed & WPAD_BUTTON_LEFT) y=-1000;
      if (pressed & WPAD_BUTTON_UP)   x=-1000;
         
      angleIndex = getAngleIndex(x,y);
      
      SDL_Event hatEvent;
      hatEvent.type = SDL_JOYHATMOTION;
      hatEvent.jhat.which=virtualJoyIndex;
      hatEvent.jhat.hat = 0;
      hatEvent.jhat.value = SDL_HAT_CENTERED;
     
      if ((x!=0) || (y!=0))
      {
          getHatEvent(&hatEvent, angleIndex);
      }
      if (lastHatSent[virtualJoyIndex] != hatEvent.jhat.value)
      {
        SDL_PushEvent(&hatEvent);
        lastHatSent[virtualJoyIndex] = hatEvent.jhat.value;
      }
      */
      //************************************************
      // Buttons HELD --> D-Pads
      //************************************************
      
      pressed = buttonsHeld[physicalJoyIndex];
      int x=0;
      int y=0;
      int angleIndex=0;
      
      if (pressed & WPAD_BUTTON_RIGHT)y=1000;
      if (pressed & WPAD_BUTTON_DOWN) x=1000;
      if (pressed & WPAD_BUTTON_LEFT) y=-1000;
      if (pressed & WPAD_BUTTON_UP)   x=-1000;
         
      angleIndex = getAngleIndex(x,y);
      
      SDL_Event hatEvent;
      hatEvent.type = SDL_JOYHATMOTION;
      hatEvent.jhat.which=virtualJoyIndex;
      hatEvent.jhat.hat = 0;
      hatEvent.jhat.value = SDL_HAT_CENTERED;
     
      if ((x!=0) || (y!=0))
      {
          getHatEvent(&hatEvent, angleIndex);
      }
      if (lastHatSent[virtualJoyIndex] != hatEvent.jhat.value)
      {
        SDL_PushEvent(&hatEvent);
        lastHatSent[virtualJoyIndex] = hatEvent.jhat.value;
      }
      
      //************************************************
      // Buttons RELEASED
      //************************************************
      
      pressed = buttonsUp[physicalJoyIndex];
      int keyUpIndex=0;
      SDL_Event keyUpEvent[MAX_EVENTS_PER_CYCLE];
      
      if (pressed & WPAD_BUTTON_2)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_09;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_BUTTON_1)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_10;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_BUTTON_A)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_11;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
      }
      
      if (pressed & WPAD_BUTTON_PLUS)
      {
         keyUpEvent[keyUpIndex].key.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].key.type=SDL_KEYUP;
         keyUpEvent[keyUpIndex].key.keysym.sym=SDLK_F12;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_BUTTON_HOME)
      {
         keyUpEvent[keyUpIndex].key.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].key.type=SDL_KEYUP;
         keyUpEvent[keyUpIndex].key.keysym.sym=SDLK_F1;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_BUTTON_MINUS)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_13;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);	  
      }
      
      if (pressed & WPAD_BUTTON_B)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_02;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_NUNCHUK_BUTTON_C )
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & WPAD_NUNCHUK_BUTTON_Z)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_01;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
      }
      
      //************************************************
      // Stick --> JoyAXIS
      //************************************************
      
      struct expansion_t ext;
      WPAD_Expansion(physicalJoyIndex, &ext);
      
      x = ext.nunchuk.js.pos.x-ext.nunchuk.js.center.x;
      y = ext.nunchuk.js.pos.y-ext.nunchuk.js.center.y;
      angleIndex = getAngleIndex(x,y);
        
      SDL_Event xevent;
      xevent.type = SDL_JOYAXISMOTION;
      xevent.jaxis.which=virtualJoyIndex;
      xevent.jaxis.axis=0;
      
      SDL_Event yevent;
      yevent.type = SDL_JOYAXISMOTION;
      yevent.jaxis.which=virtualJoyIndex;
      yevent.jaxis.axis = 1;
      
      getSDLJoyAxisEvent(&xevent, &yevent, angleIndex);
      
      if ( 
          (x < NUNCHUK_X_TOLERANCE) &&
          (x > -NUNCHUK_X_TOLERANCE)
         )
      {
         xevent.jaxis.value = 0;
      }
       
      if (
          (y < NUNCHUK_Y_TOLERANCE) &&
          (y > -NUNCHUK_Y_TOLERANCE)
         )
      {
         yevent.jaxis.value = 0;
      }
      if (ext.type & WPAD_EXP_NUNCHUK)
      {
        SDL_PushEvent(&xevent); 
        SDL_PushEvent(&yevent);
      }      
   }
}
Exemplo n.º 12
0
void IN_Commands (void)
{
	// Fetch the pad state.
	PAD_ScanPads();
	WPAD_ScanPads();

	keyboard_event KB_event;

	while(KEYBOARD_GetEvent(&KB_event) > 0)
	{
		switch(KB_event.type)
		{
			case KEYBOARD_CONNECTED:
				keyboard_connected = TRUE;
				break;

			case KEYBOARD_DISCONNECTED:
				keyboard_connected = FALSE;
				break;
	
			case KEYBOARD_PRESSED:
				if(!keyboard_shifted)
					Key_Event(keycode_normal[KB_event.keycode], TRUE);

				else
					Key_Event(keycode_shifted[KB_event.keycode], TRUE);

				if(keycode_normal[KB_event.keycode] == K_LSHIFT || keycode_normal[KB_event.keycode] == K_RSHIFT)
					keyboard_shifted = TRUE;

				break;

			case KEYBOARD_RELEASED:
				if(!keyboard_shifted)
					Key_Event(keycode_normal[KB_event.keycode], FALSE);

				else
					Key_Event(keycode_shifted[KB_event.keycode], FALSE);

				if(keycode_normal[KB_event.keycode] == K_LSHIFT || keycode_normal[KB_event.keycode] == K_RSHIFT)
					keyboard_shifted = FALSE;

				break;
		}
	}

	u32 exp_type;
	if ( WPAD_Probe(WPAD_CHAN_0, &exp_type) != 0 )
		exp_type = WPAD_EXP_NONE;

	if(exp_type == WPAD_EXP_NUNCHUK)
	{
		if(!nunchuk_connected)
			wpad_previous_keys = 0x0000;

		nunchuk_connected = TRUE;
		classic_connected = FALSE;
		wpad_keys = WPAD_ButtonsHeld(WPAD_CHAN_0);
		pad_keys = 0x0000;
		pad_previous_keys = 0x0000;
	}

	else if(exp_type == WPAD_EXP_CLASSIC)
	{
		if(!classic_connected)
			wpad_previous_keys = 0x0000;

		nunchuk_connected = FALSE;
		classic_connected = TRUE;
		wpad_keys = WPAD_ButtonsHeld(WPAD_CHAN_0);
		pad_keys = 0x0000;
		pad_previous_keys = 0x0000;
	}

	else
	{
		if(classic_connected || nunchuk_connected)
			wpad_previous_keys = 0x0000;

		nunchuk_connected = FALSE;
		classic_connected = FALSE;
		pad_keys = PAD_ButtonsHeld(PAD_CHAN0);
		wpad_keys = WPAD_ButtonsHeld(WPAD_CHAN_0);
	}

	WPAD_IR(WPAD_CHAN_0, &pointer);
	WPAD_Orientation(WPAD_CHAN_0, &orientation);
	WPAD_Expansion(WPAD_CHAN_0, &expansion);

	if (wiimote_connected && (wpad_keys & WPAD_BUTTON_MINUS))
	{
		// ELUTODO: we are using the previous frame wiimote position... FIX IT
		in_osk = 1;
		int line = (last_iry - OSK_YSTART) / (osk_line_size * (osk_line_size / osk_charsize)) - 1;
		int col = (last_irx - OSK_XSTART) / (osk_col_size * (osk_col_size / osk_charsize)) - 1;

		osk_coords[0] = last_irx;
		osk_coords[1] = last_iry;

		line = clamp(line, 0, osk_num_lines);
		col = clamp(col, 0, osk_num_col);

		if (nunchuk_connected && (wpad_keys & WPAD_NUNCHUK_BUTTON_Z))
			osk_set = osk_shifted;
		else
			osk_set = osk_normal;

		osk_selected = osk_set[line * osk_num_col + col];

		if ((wpad_keys & WPAD_BUTTON_B) && osk_selected && (Sys_FloatTime() >= osk_last_press_time + osk_repeat_delay.value || osk_selected != osk_last_selected))
		{
			Key_Event((osk_selected), TRUE);
			Key_Event((osk_selected), FALSE);
			osk_last_selected = osk_selected;
			osk_last_press_time = Sys_FloatTime();
		}
	}
	else
	{
		// TODO: go back to the old method with buton mappings. The code was a lot cleaner that way
		in_osk = 0;

		if(classic_connected)
		{
			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_LEFT) != (wpad_keys & WPAD_CLASSIC_BUTTON_LEFT))
			{
				// Send a press event.
				Key_Event(K_LEFTARROW, ((wpad_keys & WPAD_CLASSIC_BUTTON_LEFT) == WPAD_CLASSIC_BUTTON_LEFT));
			}
	
			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_RIGHT) != (wpad_keys & WPAD_CLASSIC_BUTTON_RIGHT))
			{
				// Send a press event.
				Key_Event(K_RIGHTARROW, ((wpad_keys & WPAD_CLASSIC_BUTTON_RIGHT) == WPAD_CLASSIC_BUTTON_RIGHT));
			}
	
			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_DOWN) != (wpad_keys & WPAD_CLASSIC_BUTTON_DOWN))
			{
				// Send a press event.
				Key_Event(K_DOWNARROW, ((wpad_keys & WPAD_CLASSIC_BUTTON_DOWN) == WPAD_CLASSIC_BUTTON_DOWN));
			}
	
			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_UP) != (wpad_keys & WPAD_CLASSIC_BUTTON_UP))
			{
				// Send a press event.
				Key_Event(K_UPARROW, ((wpad_keys & WPAD_CLASSIC_BUTTON_UP) == WPAD_CLASSIC_BUTTON_UP));
			}
	
			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_PLUS) != (wpad_keys & WPAD_CLASSIC_BUTTON_PLUS))
			{
				// Send a press event.
				Key_Event(K_ESCAPE, ((wpad_keys & WPAD_CLASSIC_BUTTON_PLUS) == WPAD_CLASSIC_BUTTON_PLUS));
			}
	
			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_A) != (wpad_keys & WPAD_CLASSIC_BUTTON_A))
			{
				// Send a press event.
				Key_Event(K_JOY8, ((wpad_keys & WPAD_CLASSIC_BUTTON_A) == WPAD_CLASSIC_BUTTON_A));
			}
	
			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_B) != (wpad_keys & WPAD_CLASSIC_BUTTON_B))
			{
				// Send a press event.
				Key_Event(K_JOY9, ((wpad_keys & WPAD_CLASSIC_BUTTON_B) == WPAD_CLASSIC_BUTTON_B));
			}
	
			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_MINUS) != (wpad_keys & WPAD_CLASSIC_BUTTON_MINUS))
			{
				// Send a press event.
				Key_Event(K_JOY10, ((wpad_keys & WPAD_CLASSIC_BUTTON_MINUS) == WPAD_CLASSIC_BUTTON_MINUS));
			}

			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_X) != (wpad_keys & WPAD_CLASSIC_BUTTON_X))
			{
				// Send a press event.
				Key_Event(K_JOY13, ((wpad_keys & WPAD_CLASSIC_BUTTON_X) == WPAD_CLASSIC_BUTTON_X));
			}
	
			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_Y) != (wpad_keys & WPAD_CLASSIC_BUTTON_Y))
			{
				// Send a press event.
				Key_Event(K_JOY14, ((wpad_keys & WPAD_CLASSIC_BUTTON_Y) == WPAD_CLASSIC_BUTTON_Y));
			}

			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_LEFT) != (wpad_keys & WPAD_CLASSIC_BUTTON_LEFT))
			{
				// Send a press event.
				Key_Event(K_JOY15, ((wpad_keys & WPAD_CLASSIC_BUTTON_LEFT) == WPAD_CLASSIC_BUTTON_LEFT));
			}

			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_RIGHT) != (wpad_keys & WPAD_CLASSIC_BUTTON_RIGHT))
			{
				// Send a press event.
				Key_Event(K_JOY16, ((wpad_keys & WPAD_CLASSIC_BUTTON_RIGHT) == WPAD_CLASSIC_BUTTON_RIGHT));
			}

			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_ZL) != (wpad_keys & WPAD_CLASSIC_BUTTON_ZL))
			{
				// Send a press event.
				Key_Event(K_JOY17, ((wpad_keys & WPAD_CLASSIC_BUTTON_ZL) == WPAD_CLASSIC_BUTTON_ZL));
			}

			if ((wpad_previous_keys & WPAD_CLASSIC_BUTTON_ZR) != (wpad_keys & WPAD_CLASSIC_BUTTON_ZR))
			{
				// Send a press event.
				Key_Event(K_JOY18, ((wpad_keys & WPAD_CLASSIC_BUTTON_ZR) == WPAD_CLASSIC_BUTTON_ZR));
			}
		}

		else
		{
			if ((wpad_previous_keys & WPAD_BUTTON_LEFT) != (wpad_keys & WPAD_BUTTON_LEFT))
			{
				// Send a press event.
				Key_Event(K_LEFTARROW, ((wpad_keys & WPAD_BUTTON_LEFT) == WPAD_BUTTON_LEFT));
			}
	
			if ((wpad_previous_keys & WPAD_BUTTON_RIGHT) != (wpad_keys & WPAD_BUTTON_RIGHT))
			{
				// Send a press event.
				Key_Event(K_RIGHTARROW, ((wpad_keys & WPAD_BUTTON_RIGHT) == WPAD_BUTTON_RIGHT));
			}
	
			if ((wpad_previous_keys & WPAD_BUTTON_DOWN) != (wpad_keys & WPAD_BUTTON_DOWN))
			{
				// Send a press event.
				Key_Event(K_DOWNARROW, ((wpad_keys & WPAD_BUTTON_DOWN) == WPAD_BUTTON_DOWN));
			}
	
			if ((wpad_previous_keys & WPAD_BUTTON_UP) != (wpad_keys & WPAD_BUTTON_UP))
			{
				// Send a press event.
				Key_Event(K_UPARROW, ((wpad_keys & WPAD_BUTTON_UP) == WPAD_BUTTON_UP));
			}
	
			if ((wpad_previous_keys & WPAD_BUTTON_PLUS) != (wpad_keys & WPAD_BUTTON_PLUS))
			{
				// Send a press event.
				Key_Event(K_ESCAPE, ((wpad_keys & WPAD_BUTTON_PLUS) == WPAD_BUTTON_PLUS));
			}
	
			if ((wpad_previous_keys & WPAD_BUTTON_A) != (wpad_keys & WPAD_BUTTON_A))
			{
				// Send a press event.
				Key_Event(K_JOY8, ((wpad_keys & WPAD_BUTTON_A) == WPAD_BUTTON_A));
			}
	
			if ((wpad_previous_keys & WPAD_BUTTON_B) != (wpad_keys & WPAD_BUTTON_B))
			{
				// Send a press event.
				Key_Event(K_JOY9, ((wpad_keys & WPAD_BUTTON_B) == WPAD_BUTTON_B));
			}
	
			if ((wpad_previous_keys & WPAD_BUTTON_MINUS) != (wpad_keys & WPAD_BUTTON_MINUS))
			{
				// Send a press event.
				Key_Event(K_JOY10, ((wpad_keys & WPAD_BUTTON_MINUS) == WPAD_BUTTON_MINUS));
			}
	
			if ((wpad_previous_keys & WPAD_BUTTON_1) != (wpad_keys & WPAD_BUTTON_1))
			{
				// Send a press event.
				Key_Event(K_JOY11, ((wpad_keys & WPAD_BUTTON_1) == WPAD_BUTTON_1));
			}
	
			if ((wpad_previous_keys & WPAD_BUTTON_2) != (wpad_keys & WPAD_BUTTON_2))
			{
				// Send a press event.
				Key_Event(K_JOY12, ((wpad_keys & WPAD_BUTTON_2) == WPAD_BUTTON_2));
			}
	
			if(nunchuk_connected)
			{
				if ((wpad_previous_keys & WPAD_NUNCHUK_BUTTON_C) != (wpad_keys & WPAD_NUNCHUK_BUTTON_C))
				{
					// Send a press event.
					Key_Event(K_JOY13, ((wpad_keys & WPAD_NUNCHUK_BUTTON_C) == WPAD_NUNCHUK_BUTTON_C));
				}
		
				if ((wpad_previous_keys & WPAD_NUNCHUK_BUTTON_Z) != (wpad_keys & WPAD_NUNCHUK_BUTTON_Z))
				{
					// Send a press event.
					Key_Event(K_JOY14, ((wpad_keys & WPAD_NUNCHUK_BUTTON_Z) == WPAD_NUNCHUK_BUTTON_Z));
				}
			}
		}
	
		if(!nunchuk_connected && !classic_connected)
		{
			if ((pad_previous_keys & PAD_BUTTON_LEFT) != (pad_keys & PAD_BUTTON_LEFT))
			{
				// Send a press event.
				Key_Event(K_LEFTARROW, ((pad_keys & PAD_BUTTON_LEFT) == PAD_BUTTON_LEFT));
			}
	
			if ((pad_previous_keys & PAD_BUTTON_RIGHT) != (pad_keys & PAD_BUTTON_RIGHT))
			{
				// Send a press event.
				Key_Event(K_RIGHTARROW, ((pad_keys & PAD_BUTTON_RIGHT) == PAD_BUTTON_RIGHT));
			}
	
			if ((pad_previous_keys & PAD_BUTTON_DOWN) != (pad_keys & PAD_BUTTON_DOWN))
			{
				// Send a press event.
				Key_Event(K_DOWNARROW, ((pad_keys & PAD_BUTTON_DOWN) == PAD_BUTTON_DOWN));
			}
			if ((pad_previous_keys & PAD_BUTTON_UP) != (pad_keys & PAD_BUTTON_UP))
			{
				// Send a press event.
				Key_Event(K_UPARROW, ((pad_keys & PAD_BUTTON_UP) == PAD_BUTTON_UP));
			}
	
			if ((pad_previous_keys & PAD_BUTTON_A) != (pad_keys & PAD_BUTTON_A))
			{
				// Send a press event.
				Key_Event(K_JOY8, ((pad_keys & PAD_BUTTON_A) == PAD_BUTTON_A));
			}
	
			if ((pad_previous_keys & PAD_BUTTON_B) != (pad_keys & PAD_BUTTON_B))
			{
				// Send a press event.
				Key_Event(K_JOY9, ((pad_keys & PAD_BUTTON_B) == PAD_BUTTON_B));
			}
	
			if ((pad_previous_keys & PAD_BUTTON_X) != (pad_keys & PAD_BUTTON_X))
			{
				// Send a press event.
				Key_Event(K_JOY10, ((pad_keys & PAD_BUTTON_X) == PAD_BUTTON_X));
			}
	
			if ((pad_previous_keys & PAD_BUTTON_Y) != (pad_keys & PAD_BUTTON_Y))
			{
				// Send a press event.
				Key_Event(K_JOY10, ((pad_keys & PAD_BUTTON_Y) == PAD_BUTTON_Y));
			}
	
			if ((pad_previous_keys & PAD_TRIGGER_R) != (pad_keys & PAD_TRIGGER_R))
			{
				// Send a press event.
				Key_Event(K_JOY11, ((pad_keys & PAD_TRIGGER_R) == PAD_TRIGGER_R));
			}
	
			if ((pad_previous_keys & PAD_TRIGGER_L) != (pad_keys & PAD_TRIGGER_L))
			{
				// Send a press event.
				Key_Event(K_JOY12, ((pad_keys & PAD_TRIGGER_L) == PAD_TRIGGER_L));
			}
	
			if ((pad_previous_keys & PAD_TRIGGER_Z) != (pad_keys & PAD_TRIGGER_Z))
			{
				// Send a press event.
				Key_Event(K_JOY13, ((pad_keys & PAD_TRIGGER_Z) == PAD_TRIGGER_Z));
			}
	
			if ((pad_previous_keys & PAD_BUTTON_START) != (pad_keys & PAD_BUTTON_START))
			{
				// Send a press event.
				Key_Event(K_ESCAPE, ((pad_keys & PAD_BUTTON_START) == PAD_BUTTON_START));
			}

			pad_previous_keys = pad_keys;
		}
	}

	wpad_previous_keys = wpad_keys;
}
Exemplo n.º 13
0
void changeColorBasedOnJoystick(){
	struct expansion_t data;
	WPAD_Expansion(WPAD_CHAN_0, &data); // Get expansion info from the first wiimote
	
	joystick_t joy_data = data.nunchuk.js;
	
	
	joy_x = data.nunchuk.js.pos.x - data.nunchuk.js.center.x;
	joy_y = data.nunchuk.js.pos.y - data.nunchuk.js.center.y;
	
	
	//printf("minimum X, Y:  %d, %d   C:  %d", data.nunchuk.js.min.x, data.nunchuk.js.min.y, data.nunchuk.js.center.x);
	//printf("Center X, Y:  %d, %d  DIST: %d", data.nunchuk.js.center.x, data.nunchuk.js.center.y, (int)getDistanceOfJoystickFromCenter(joy_data));
	//int count = 60;
	//while (count--) VIDEO_WaitVSync();
	
	int tolerance = 10;
	if (joyMovementNegligable(joy_x, joy_y, old_x, old_y, tolerance) && inDeadzone(joy_data)){ // if we're in the deadzone, ignore movement up to 10...
		
		flickerRoutine();
		
		return;
	}
	old_x = joy_x;
	old_y = joy_y;
	
	
	if (inDeadzone(joy_data)){
		background = (GXColor){0,0,0,0xff};
		GX_SetCopyClear(background, 0x00ffffff);
		return;
	}
	
	
	//printf("Maxes:  %d, %d  ", joy_data.max.x, joy_data.max.y);
	//int count = 60;
	//while(count--) VIDEO_WaitVSync();
	
	double degrees;
	degrees = convertJoyToDegrees(joy_x, joy_y);
	
	if(oldDegrees - degrees > 40){            // about this code:  Sometimes, at the begining of the game, the screen will flash to red for 1/60hz... this is annoying.  It's always the same red too I think.  I found out it was the actual joystick getting picked up as being down there... To resolve the problem, the player can swivel the joystick 360 degrees and the flickering usually stops
		printf("SPIKE DETECTED %f ", degrees); // I'm not 100% sure what the nature of this bug is, but perhaps it's registering (0,0) as it's values...  but it can't, it's minimums are well above that... 
	}                                         // I think just having this code here is lucky though... cause I don't get flickering anymore...
	
	if (degrees != -1){
		GXColor *careful_bg1;
		careful_bg1 = malloc(30 * sizeof(GXColor));
		
		
		
		*careful_bg1 = setBackgroundBasedOnDegrees(background, degrees);
		*careful_bg1 = darkenBackgroundBasedOnDistance(*careful_bg1, joy_data);
		background = *careful_bg1;
		GX_SetCopyClear(background, 0x00ffffff);
		
		free(careful_bg1);
		oldDegrees = degrees;
		
		printNameOfColor(degrees);
	}
}
Exemplo n.º 14
0
void update_player_actions(void)
{
	int tmp;

#ifndef WIN32
	struct expansion_t ext_data[4];
	int ext_but[4] = {0,0};
	WPAD_Expansion(WPAD_CHAN_0, &ext_data[0]);
	WPAD_Expansion(WPAD_CHAN_1, &ext_data[1]);
	WPAD_Expansion(WPAD_CHAN_2, &ext_data[2]);
	WPAD_Expansion(WPAD_CHAN_3, &ext_data[3]);
	for(tmp=0;tmp<4;tmp++)
	{
        switch(ext_data[tmp].type)
        {
        case WPAD_EXP_NUNCHUK:
            if (ext_data[tmp].nunchuk.js.pos.x < (ext_data[tmp].nunchuk.js.center.x + ext_data[tmp].nunchuk.js.min.x)/2)
                ext_but[tmp] |= 1;
            if (ext_data[tmp].nunchuk.js.pos.x > (ext_data[tmp].nunchuk.js.center.x + ext_data[tmp].nunchuk.js.max.x)/2)
                ext_but[tmp] |= 2;
            if (WPAD_ButtonsHeld(tmp) & (WPAD_NUNCHUK_BUTTON_Z | WPAD_NUNCHUK_BUTTON_C))
                ext_but[tmp] |= 4;
            break;
        case WPAD_EXP_CLASSIC:
            if (WPAD_ButtonsHeld(tmp) & (WPAD_CLASSIC_BUTTON_LEFT))
                ext_but[tmp] |= 1;
            if (WPAD_ButtonsHeld(tmp) & (WPAD_CLASSIC_BUTTON_RIGHT))
                ext_but[tmp] |= 2;
            if (WPAD_ButtonsHeld(tmp) & (WPAD_CLASSIC_BUTTON_A | WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_X | WPAD_CLASSIC_BUTTON_Y))
                ext_but[tmp] |= 4;
            break;
        case WPAD_EXP_GUITARHERO3:
            //Clueless right now... never seen one, no idea what would be nice.
            break;
        }
	}
#endif

	if (client_player_num < 0) {
		tmp = (key_pressed(KEY_PL1_LEFT) == 1) || JOY_LEFT(3) || WII_LEFT(0);
		if (tmp != player[0].action_left)
			tellServerPlayerMoved(0, MOVEMENT_LEFT, tmp);
		tmp = (key_pressed(KEY_PL1_RIGHT) == 1) || JOY_RIGHT(3) || WII_RIGHT(0);
		if (tmp != player[0].action_right)
			tellServerPlayerMoved(0, MOVEMENT_RIGHT, tmp);
		tmp = (key_pressed(KEY_PL1_JUMP) == 1) || JOY_JUMP(3) || WII_JUMP(0);
		if (tmp != player[0].action_up)
			tellServerPlayerMoved(0, MOVEMENT_UP, tmp);

		tmp = (key_pressed(KEY_PL2_LEFT) == 1) || JOY_LEFT(2) || WII_LEFT(1);
		if (tmp != player[1].action_left)
			tellServerPlayerMoved(1, MOVEMENT_LEFT, tmp);
		tmp = (key_pressed(KEY_PL2_RIGHT) == 1) || JOY_RIGHT(2) || WII_RIGHT(1);
		if (tmp != player[1].action_right)
			tellServerPlayerMoved(1, MOVEMENT_RIGHT, tmp);
		tmp = (key_pressed(KEY_PL2_JUMP) == 1) || JOY_JUMP(2) || WII_JUMP(1);
		if (tmp != player[1].action_up)
			tellServerPlayerMoved(1, MOVEMENT_UP, tmp);

		tmp = (key_pressed(KEY_PL3_LEFT) == 1) || JOY_LEFT(1) || WII_LEFT(2);
		if (tmp != player[2].action_left)
			tellServerPlayerMoved(2, MOVEMENT_LEFT, tmp);
		tmp = (key_pressed(KEY_PL3_RIGHT) == 1) || JOY_RIGHT(1) || WII_RIGHT(2);
		if (tmp != player[2].action_right)
			tellServerPlayerMoved(2, MOVEMENT_RIGHT, tmp);
		tmp = (key_pressed(KEY_PL3_JUMP) == 1) || JOY_JUMP(1) || WII_JUMP(2);
		if (tmp != player[2].action_up)
			tellServerPlayerMoved(2, MOVEMENT_UP, tmp);

		tmp = (key_pressed(KEY_PL4_LEFT) == 1) || JOY_LEFT(0) || WII_LEFT(3);
		if (tmp != player[3].action_left)
		tellServerPlayerMoved(3, MOVEMENT_LEFT, tmp);
		tmp = (key_pressed(KEY_PL4_RIGHT) == 1) || JOY_RIGHT(0) || WII_RIGHT(3);
		if (tmp != player[3].action_right)
		tellServerPlayerMoved(3, MOVEMENT_RIGHT, tmp);
		tmp = (key_pressed(KEY_PL4_JUMP) == 1) || JOY_JUMP(0) || WII_JUMP(3);
		if (tmp != player[3].action_up)
		tellServerPlayerMoved(3, MOVEMENT_UP, tmp);

		tmp = (key_pressed(KEY_PL5_LEFT) == 1) || WII_EXP_LEFT(0);
		if (tmp != player[4].action_left)
			tellServerPlayerMoved(4, MOVEMENT_LEFT, tmp);
		tmp = (key_pressed(KEY_PL5_RIGHT) == 1) || WII_EXP_RIGHT(0);
		if (tmp != player[4].action_right)
			tellServerPlayerMoved(4, MOVEMENT_RIGHT, tmp);
		tmp = (key_pressed(KEY_PL5_JUMP) == 1) || WII_EXP_JUMP(0);
		if (tmp != player[4].action_up)
			tellServerPlayerMoved(4, MOVEMENT_UP, tmp);

		tmp = (key_pressed(KEY_PL6_LEFT) == 1) || WII_EXP_LEFT(1);
		if (tmp != player[5].action_left)
			tellServerPlayerMoved(5, MOVEMENT_LEFT, tmp);
		tmp = (key_pressed(KEY_PL6_RIGHT) == 1) || WII_EXP_RIGHT(1);
		if (tmp != player[5].action_right)
			tellServerPlayerMoved(5, MOVEMENT_RIGHT, tmp);
		tmp = (key_pressed(KEY_PL6_JUMP) == 1) || WII_EXP_JUMP(1);
		if (tmp != player[5].action_up)
			tellServerPlayerMoved(5, MOVEMENT_UP, tmp);

		tmp = (key_pressed(KEY_PL7_LEFT) == 1) || WII_EXP_LEFT(2);
		if (tmp != player[6].action_left)
			tellServerPlayerMoved(6, MOVEMENT_LEFT, tmp);
		tmp = (key_pressed(KEY_PL7_RIGHT) == 1) || WII_EXP_RIGHT(2);
		if (tmp != player[6].action_right)
			tellServerPlayerMoved(6, MOVEMENT_RIGHT, tmp);
		tmp = (key_pressed(KEY_PL7_JUMP) == 1) || WII_EXP_JUMP(2);
		if (tmp != player[6].action_up)
			tellServerPlayerMoved(6, MOVEMENT_UP, tmp);

		tmp = (key_pressed(KEY_PL8_LEFT) == 1) || WII_EXP_LEFT(3);
		if (tmp != player[7].action_left)
			tellServerPlayerMoved(7, MOVEMENT_LEFT, tmp);
		tmp = (key_pressed(KEY_PL8_RIGHT) == 1) || WII_EXP_RIGHT(3);
		if (tmp != player[7].action_right)
			tellServerPlayerMoved(7, MOVEMENT_RIGHT, tmp);
		tmp = (key_pressed(KEY_PL8_JUMP) == 1) || WII_EXP_JUMP(3);
		if (tmp != player[7].action_up)
			tellServerPlayerMoved(7, MOVEMENT_UP, tmp);
	} else {
		tmp = (key_pressed(KEY_PL1_LEFT) == 1) || JOY_LEFT(0) || WII_LEFT(0);
		if (tmp != player[client_player_num].action_left)
			tellServerPlayerMoved(client_player_num, MOVEMENT_LEFT, tmp);
		tmp = (key_pressed(KEY_PL1_RIGHT) == 1) || JOY_RIGHT(0) || WII_RIGHT(0);
		if (tmp != player[client_player_num].action_right)
			tellServerPlayerMoved(client_player_num, MOVEMENT_RIGHT, tmp);
		tmp = (key_pressed(KEY_PL1_JUMP) == 1) || JOY_JUMP(0) || WII_JUMP(0);
		if (tmp != player[client_player_num].action_up)
			tellServerPlayerMoved(client_player_num, MOVEMENT_UP, tmp);
	}
}