Example #1
0
void UpdateCursorPosition (int pad, int &pos_x, int &pos_y)
{
	#define SCOPEPADCAL 20

	// gc left joystick
	signed char pad_x = PAD_StickX (pad);
	signed char pad_y = PAD_StickY (pad);

	if (pad_x > SCOPEPADCAL){
		pos_x += (pad_x*1.0)/SCOPEPADCAL;
		if (pos_x > 256) pos_x = 256;
	}
	if (pad_x < -SCOPEPADCAL){
		pos_x -= (pad_x*-1.0)/SCOPEPADCAL;
		if (pos_x < 0) pos_x = 0;
	}

	if (pad_y < -SCOPEPADCAL){
		pos_y += (pad_y*-1.0)/SCOPEPADCAL;
		if (pos_y > 224) pos_y = 224;
	}
	if (pad_y > SCOPEPADCAL){
		pos_y -= (pad_y*1.0)/SCOPEPADCAL;
		if (pos_y < 0) pos_y = 0;
	}

#ifdef HW_RVL
	struct ir_t ir;		// wiimote ir
	WPAD_IR(pad, &ir);
	if (ir.valid)
	{
		pos_x = (ir.x * 256) / 640;
		pos_y = (ir.y * 224) / 480;
	}
	else
	{
		signed char wm_ax = WPAD_StickX (pad, 0);
		signed char wm_ay = WPAD_StickY (pad, 0);

		if (wm_ax > SCOPEPADCAL){
			pos_x += (wm_ax*1.0)/SCOPEPADCAL;
			if (pos_x > 256) pos_x = 256;
		}
		if (wm_ax < -SCOPEPADCAL){
			pos_x -= (wm_ax*-1.0)/SCOPEPADCAL;
			if (pos_x < 0) pos_x = 0;
		}

		if (wm_ay < -SCOPEPADCAL){
			pos_y += (wm_ay*-1.0)/SCOPEPADCAL;
			if (pos_y > 224) pos_y = 224;
		}
		if (wm_ay > SCOPEPADCAL){
			pos_y -= (wm_ay*1.0)/SCOPEPADCAL;
			if (pos_y < 0) pos_y = 0;
		}
	}
#endif

}
Example #2
0
void grlib_DrawIRCursor (void)
	{
	ir_t ir;
	static u8 alphadec = 255;
	static s16 alpha = 0; // Start with cursor hidden
	static u32 cursorActivity = 0;
	
	static u32 startms = 0;
	u32 ms = ticks_to_millisecs(gettime());
	
	WPAD_IR (0, &ir);
	
	if (ms > startms)
		{
		if (cursorActivity == grlibSettings.cursorActivity)
			{
			alpha -= alphadec;
			if (alpha < 0) alpha = 0;
			}
		else
			{
			alpha = 255;
			alphadec = 5;
			cursorActivity = grlibSettings.cursorActivity;
			}
		
		startms = ms+100;
		}
	
	if (ir.valid)
		{
		grlib_irPos.x = ir.x;
		grlib_irPos.y = ir.y;
		grlib_irPos.valid = 1;
		alpha = 255;
		}
	else
		{
		grlib_irPos.valid = 0;
		}

	GRRLIB_DrawImg( grlib_irPos.x, 
					grlib_irPos.y, 
					grlibSettings.pointer[0], 0, 1, 1, RGBA(255, 255, 255, alpha) ); 
	}
Example #3
0
/*
 * Stores the current location of the Wiimote (IR)
 */
static void wii_atari_update_wiimote_ir()
{
  // Necessary as the SDL seems to keep resetting the resolution
  WPAD_SetVRes(WPAD_CHAN_0, 640, 480);

  ir_t ir;
  WPAD_IR(WPAD_CHAN_0, &ir);

  if( ir.valid )
  {
    wii_ir_x = ir.x;
    wii_ir_y = ir.y; 
  }
  else
  {
    wii_ir_x = -100;
    wii_ir_y = -100;
  }
}
Example #4
0
void InputDevices::ScanButtons(void)
{
    m_mutex.Lock();

#ifdef WII
    keyboard_event kbdEvent;

    // Scan PAD/WPAD
    WPAD_ScanPads();
    PAD_ScanPads();

    // Process WPAD IR
    ir_t ir;
    WPAD_IR(WPAD_CHAN_0, &ir);
    if( !ir.state || !ir.smooth_valid ) {
        WPAD_IR(WPAD_CHAN_1, &ir);
    }
    if( !ir.state || !ir.smooth_valid ) {
        m_mouse_active = false;
    }else{
        m_mouse_x = (int)(((ir.sx - (500-200)) * GameWindow::GetWidth()) / 400);
        m_mouse_y = (int)(((ir.sy - (500-150)) * GameWindow::GetHeight()) / 300);
        m_mouse_angle = ir.angle;
        m_mouse_active = true;
    }

    // Process PAD/WPAD buttons
    for(int btn = BTN_JOY_FIRST; btn < BTN_LAST; btn++) {
        m_btnstatus[KEYIDX_NEW][btn] = false;
    }
    PADCODE *p = wpad_default;
    for(int i = 0; i < 2; i++) {
        m_wpad[0] = GetPadButtonStatus(WPAD_CHAN_0);
        m_wpad[1] = GetPadButtonStatus(WPAD_CHAN_1);
        while(p->key_a != BTN_NONE)  {
            if( (m_wpad[0] & p->code) != 0  ) {
                m_btnstatus[KEYIDX_NEW][p->key_a] = true;
            }
            if( (m_wpad[1] & p->code) != 0  ) {
                m_btnstatus[KEYIDX_NEW][p->key_b] = true;
            }
            p++;
        }
        if( m_wpad_orientation == WPADO_HORIZONTAL ) {
            p = wpad_horizontal;
        }else{
            p = wpad_vertical;
        }
    }

    // Handle USB keyboard
    while( KEYBOARD_GetEvent(&kbdEvent) ) {
        switch( kbdEvent.type ) {
            case KEYBOARD_PRESSED:
                for(int i = 0; syms[i].key != BTN_NONE; i++)  {
                    if( kbdEvent.symbol == syms[i].code_a || kbdEvent.symbol == syms[i].code_b ) {
                        m_btnstatus[KEYIDX_NEW][syms[i].key] = true;
                    }
                }
                break;
            case KEYBOARD_RELEASED:
                for(int i = 0; syms[i].key != BTN_NONE; i++)  {
                    if( kbdEvent.symbol == syms[i].code_a || kbdEvent.symbol == syms[i].code_b ) {
                        m_btnstatus[KEYIDX_NEW][syms[i].key] = true;
                    }
                }
                break;
            case KEYBOARD_DISCONNECTED:
                memset(m_btnstatus, 0, sizeof(m_btnstatus));
                m_connected--;
                break;
            case KEYBOARD_CONNECTED:
                m_connected++;
                break;
        }
    }

    // Handle leds
    int led = ledGetCapslock();
    if( m_leds != led ) {
        KEYBOARD_SetLed(KEYBOARD_LEDCAPS, led);
        m_leds = led;
    }
#else
    // Process mouse
    float x, y;
    g_hge->Input_GetMousePos(&x, &y);
    m_mouse_active = g_hge->Input_IsMouseOver();
    m_mouse_x = (int)x;
    m_mouse_y = (int)y;

    // Process key events
    hgeInputEvent event;
    while( g_hge->Input_GetEvent(&event) ) {
      switch( event.type ) {
        case INPUT_KEYDOWN:
          if( event.key == HGEK_F9 ) {
            GameWindow::ToggleFullScreen();
            break;
          }
        case INPUT_MBUTTONDOWN:
          for(int i = 0; syms[i].key != BTN_NONE; i++)  {
            if( syms[i].code_a == event.key ) {
              m_btnstatus[KEYIDX_NEW][syms[i].key] = true;
            }
          }
          break;
        case INPUT_KEYUP:
        case INPUT_MBUTTONUP:
          for(int i = 0; syms[i].key != BTN_NONE; i++)  {
            if( syms[i].code_a == event.key ) {
              m_btnstatus[KEYIDX_NEW][syms[i].key] = false;
            }
          }
          break;
      }
    }
#endif

    m_mutex.Unlock();
}
Example #5
0
qboolean IN_GetWmoteCursorPos(incursorcoords_t* p)
{
	ir_t w;
	int wx;
	float l;
	float r;
	float t;
	float b;
	float m;

	WPAD_IR(WPAD_CHAN_0, &w);
	if(w.valid)
	{
		wmote_prev_x = wmote_curr_x;
		wmote_prev_y = wmote_curr_y;
		wmote_curr_x = w.x;
		wmote_curr_y = w.y;
		if(wmote_validcount == 0)
		{
			IN_SetWmoteCursorPos (window_center_x, window_center_y);
		};
		wmote_validcount++;
	} else
	{
		if(wmote_validcount == 1)
		{
			if(w.smooth_valid)
			{
				wx = wmote_curr_x + wmote_curr_x - w.sx;
			} else
			{
				if(wmote_curr_x != wmote_prev_x)
				{
					l = (float)(-wmote_curr_x) / (float)(wmote_prev_x - wmote_curr_x);
					r = (float)(sys_rmode->viWidth - 1 - wmote_curr_x) / (float)(wmote_prev_x - wmote_curr_x);
				} else
				{
					l = -1;
					r = -1;
				};
				if(wmote_curr_y != wmote_prev_y)
				{
					t = (float)(-wmote_curr_y) / (float)(wmote_prev_y - wmote_curr_y);
					b = (float)(sys_rmode->viHeight - 1 - wmote_curr_y) / (float)(wmote_prev_y - wmote_curr_y);
				} else
				{
					t = -1;
					b = -1;
				};
				if(l >= 0)
				{
					m = l;
				} else
				{
					m = t;
				};
				if((l >= 0) && (m > l))
				{
					m = l;
				};
				if((r >= 0) && (m > r))
				{
					m = r;
				};
				if((t >= 0) && (m > t))
				{
					m = t;
				};
				if((b >= 0) && (m > b))
				{
					m = b;
				};
				wx = wmote_curr_x + (int)(m * (float)(wmote_prev_y - wmote_curr_y));
			};
		} else
		{
			wx = wmote_curr_x + wmote_curr_x - wmote_prev_x;
		};
		wmote_prev_x = wmote_curr_x;
		wmote_prev_y = wmote_curr_y;
		wmote_curr_x = wx;
		wmote_validcount = 0;
	};
	if((((in_wlook->value != 0)&&(wmotelookbinv->value == 0))
	  ||((in_wlook->value == 0)&&(wmotelookbinv->value != 0)))
	  &&(in_osk->value == 0))
	{
		p->x = wmote_curr_x - wmote_adjust_x;
		p->y = wmote_curr_y - wmote_adjust_y;
		return true;
	};
	return false;
}
Example #6
0
int hogansnewalley(Sprite *Aim, Sprite *Health, Sprite *Background, int rumble, int maxtime, int diff, GameWindow *gwd){
  
  checkbadguys = false;
  
  gametime = 0;
  
  curalleytime = 200;

  Ghealth = 3;
  
  Grumble = rumble;
  
  Gscore = 0;
  
  switch(diff){
  
  case 1:
  resetalleytime = 90;
  grid = false;
  Alley1->SetPosition(70, 190);
  Alley2->SetPosition(260, 190);
  Alley3->SetPosition(450, 190);
  break;
  
  case 2:
  resetalleytime = 90;
  grid = true;
  //Alley1->SetPosition(70, 190);
  //Alley2->SetPosition(260, 190);
  //Alley3->SetPosition(450, 190);
  break;
  
  case 3:
  resetalleytime = 55;
  grid = false;
  Alley1->SetPosition(70, 190);
  Alley2->SetPosition(260, 190);
  Alley3->SetPosition(450, 190);
  break;
  
  case 4:
  resetalleytime = 55;
  grid = true;
  break;
  
  }
  
  alive[0] = false;
  alive[1] = false;
  alive[2] = false;

  good1->LoadImage("/apps/WiiShootingGallery/data/good1.png");
  good2->LoadImage("/apps/WiiShootingGallery/data/good2.png");
  good3->LoadImage("/apps/WiiShootingGallery/data/good3.png");
  bad1->LoadImage("/apps/WiiShootingGallery/data/bad1.png");
  bad2->LoadImage("/apps/WiiShootingGallery/data/bad2.png");
  bad3->LoadImage("/apps/WiiShootingGallery/data/bad3.png");
  
  quitcheck = false;

 while(true){//Game Loop
 
   WPAD_ScanPads();
   if(dontcheck)
   dontcheck = false;
   
   Music();

   if(curalleytime >= resetalleytime)
   resetalley();

   Background->Draw();
   
   if(alive[0] == true)
   Alley1->Draw();
   
   if(alive[1] == true)
   Alley2->Draw();
   
   if(alive[2] == true)
   Alley3->Draw();
   
    // Infrared calculation - The X and Y of the wiimote sprite
    ir_t ir; // The struct for infrared
	WPAD_IR(WPAD_CHAN_0, &ir); // Let's get our infrared data
	// Give our sprite the positions and the angle.
	Aim->SetPosition(ir.sx-WSP_POINTER_CORRECTION_X, ir.sy-WSP_POINTER_CORRECTION_Y); // We use these constants to translate the position correctly to the screen
	Aim->Move(-((f32)Aim->GetWidth()/2), -((f32)Aim->GetHeight()/2)); // And these to make our image appear at the center of this position.
	Aim->SetRotation(ir.angle/2); // Set angle/2 to translate correctly
   
   Aim->Draw();
   
   DrawHealth(Health, Ghealth);
   
   if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_PLUS){
	InMenu(gwd, false, Ghealth, Gscore);
	dontcheck = true;
	if(Ghealth > 3)
	Ghealth = 3;
	}
		
	if(quitcheck == true)
	break;
   
   if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME)
   homemenu(gwd);
   
   if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_B){
   if(!dontcheck)
   HCheckForHit(Aim);
   }
   
   if(hrumblecounter == 7){
   WPAD_Rumble(WPAD_CHAN_0, 0);
   hrumblecounter = 0;
   }

   if(hrumblecounter != 0)
   hrumblecounter++;
   
   if(gametime > maxtime)
   break;
   
   if(maxtime > 0)
   gametime++;
   
   curalleytime++;
   
   if(Ghealth <= 0) 
   break;
   
   if(shutdown == true)
   SYS_ResetSystem(SYS_POWEROFF, 0, 0);
   
   gwd->Flush();



}//End Game Loop

WPAD_Rumble(WPAD_CHAN_0, 0);

return Gscore;

}
Example #7
0
u16 ogc_input__getMenuButtons(void)
{
  /* slowdown input updates */
  VIDEO_WaitVSync();

  /* get gamepad inputs */
  PAD_ScanPads();
  u16 p = PAD_ButtonsDown(0);
  s8 x  = PAD_StickX(0);
  s8 y  = PAD_StickY(0);
  if (x > 70) p |= PAD_BUTTON_RIGHT;
  else if (x < -70) p |= PAD_BUTTON_LEFT;
	if (y > 60) p |= PAD_BUTTON_UP;
  else if (y < -60) p |= PAD_BUTTON_DOWN;

#ifdef HW_RVL
  /* get wiimote + expansions inputs */
  WPAD_ScanPads();
  u32 q = WPAD_ButtonsDown(0);
  u32 h = WPAD_ButtonsHeld(0);
  x = WPAD_StickX(0, 0);
  y = WPAD_StickY(0, 0);

  /* is Wiimote directed toward screen (horizontal/vertical orientation) ? */
  struct ir_t ir;
  WPAD_IR(0, &ir);

  /* wiimote directions */
  if (q & WPAD_BUTTON_UP)         p |= ir.valid ? PAD_BUTTON_UP : PAD_BUTTON_LEFT;
  else if (q & WPAD_BUTTON_DOWN)  p |= ir.valid ? PAD_BUTTON_DOWN : PAD_BUTTON_RIGHT;
  else if (q & WPAD_BUTTON_LEFT)  p |= ir.valid ? PAD_BUTTON_LEFT : PAD_BUTTON_DOWN;
  else if (q & WPAD_BUTTON_RIGHT) p |= ir.valid ? PAD_BUTTON_RIGHT : PAD_BUTTON_UP;
  
  if (h & WPAD_BUTTON_UP)
  {
    held_cnt ++;
    if (held_cnt == MAX_HELD_CNT)
    {
      held_cnt = MAX_HELD_CNT - 2;
      p |= ir.valid ? PAD_BUTTON_UP : PAD_BUTTON_LEFT;
    }
  }
  else if (h & WPAD_BUTTON_DOWN)
  {
    held_cnt ++;
    if (held_cnt == MAX_HELD_CNT)
    {
      held_cnt = MAX_HELD_CNT - 2;
      p |= ir.valid ? PAD_BUTTON_DOWN : PAD_BUTTON_RIGHT;
    }
  }
  else if (h & WPAD_BUTTON_LEFT)
  {
    held_cnt ++;
    if (held_cnt == MAX_HELD_CNT)
    {
      held_cnt = MAX_HELD_CNT - 2;
      p |= ir.valid ? PAD_BUTTON_LEFT : PAD_BUTTON_DOWN;
    }
  }
  else if (h & WPAD_BUTTON_RIGHT)
  {
    held_cnt ++;
    if (held_cnt == MAX_HELD_CNT)
    {
      held_cnt = MAX_HELD_CNT - 2;
      p |= ir.valid ? PAD_BUTTON_RIGHT : PAD_BUTTON_UP;
    }
  }
  else
  {
    held_cnt = 0;
  }

  /* analog sticks */
  if (y > 70)       p |= PAD_BUTTON_UP;
  else if (y < -70) p |= PAD_BUTTON_DOWN;
  if (x < -60)      p |= PAD_BUTTON_LEFT;
  else if (x > 60)  p |= PAD_BUTTON_RIGHT;

  /* classic controller directions */
  if (q & WPAD_CLASSIC_BUTTON_UP)         p |= PAD_BUTTON_UP;
  else if (q & WPAD_CLASSIC_BUTTON_DOWN)  p |= PAD_BUTTON_DOWN;
  if (q & WPAD_CLASSIC_BUTTON_LEFT)       p |= PAD_BUTTON_LEFT;
  else if (q & WPAD_CLASSIC_BUTTON_RIGHT) p |= PAD_BUTTON_RIGHT;

  /* wiimote keys */
  if (q & WPAD_BUTTON_MINUS)  p |= PAD_TRIGGER_L;
  if (q & WPAD_BUTTON_PLUS)   p |= PAD_TRIGGER_R;
  if (q & WPAD_BUTTON_A)      p |= PAD_BUTTON_A;
  if (q & WPAD_BUTTON_B)      p |= PAD_BUTTON_B;
  if (q & WPAD_BUTTON_2)      p |= PAD_BUTTON_A;
  if (q & WPAD_BUTTON_1)      p |= PAD_BUTTON_B;
  if (q & WPAD_BUTTON_HOME)   p |= PAD_TRIGGER_Z;

  /* classic controller keys */
  if (q & WPAD_CLASSIC_BUTTON_FULL_L) p |= PAD_TRIGGER_L;
  if (q & WPAD_CLASSIC_BUTTON_FULL_R) p |= PAD_TRIGGER_R;
  if (q & WPAD_CLASSIC_BUTTON_A)      p |= PAD_BUTTON_A;
  if (q & WPAD_CLASSIC_BUTTON_B)      p |= PAD_BUTTON_B;
  if (q & WPAD_CLASSIC_BUTTON_HOME)   p |= PAD_TRIGGER_Z;

 #endif

  return p;
}
Example #8
0
static void wpad_update(s8 num, u8 i, u32 exp)
{
  /* get buttons status */
  u32 p = WPAD_ButtonsHeld(num);

  /* get analog sticks values */
  u8 sensitivity = 30;
  s8 x = 0;
  s8 y = 0;
  if (exp != WPAD_EXP_NONE)
  {
    x = WPAD_StickX(num,0);
    y = WPAD_StickY(num,0);
  }

  /* retrieve current key mapping */
  u32 *wpad_keymap = config.wpad_keymap[exp + (3 * num)];

  /* BUTTONS */
  if (p & wpad_keymap[KEY_BUTTONA]) input.pad[i]  |= INPUT_A;
  if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i]  |= INPUT_B;
  if (p & wpad_keymap[KEY_BUTTONC]) input.pad[i]  |= INPUT_C;
  if (p & wpad_keymap[KEY_BUTTONX]) input.pad[i]  |= INPUT_X;
  if (p & wpad_keymap[KEY_BUTTONY]) input.pad[i]  |= INPUT_Y;
  if (p & wpad_keymap[KEY_BUTTONZ]) input.pad[i]  |= INPUT_Z;
  if (p & wpad_keymap[KEY_START])   input.pad[i]  |= INPUT_START;

  /* MODE Button (FIXED) */
  if (((exp == WPAD_EXP_CLASSIC) && (p & WPAD_CLASSIC_BUTTON_MINUS)) ||
      ((exp != WPAD_EXP_CLASSIC) && (p & WPAD_BUTTON_MINUS)))
    input.pad[i]  |= INPUT_MODE;

  /* LIGHTGUN screen position (X,Y) */
  if (input.dev[i] == DEVICE_LIGHTGUN)
  {
    if (x || y)
    {
      /* analog stick */
      input.analog[i-4][0] += x / sensitivity;
      input.analog[i-4][1] -= y / sensitivity;
      if (input.analog[i-4][0] < 0) input.analog[i-4][0] = 0;
      else if (input.analog[i-4][0] > bitmap.viewport.w) input.analog[i-4][0] = bitmap.viewport.w;
      if (input.analog[i-4][1] < 0) input.analog[i-4][1] = 0;
      else if (input.analog[i-4][1] > bitmap.viewport.h) input.analog[i-4][1] = bitmap.viewport.h;
    }

    if (exp != WPAD_EXP_CLASSIC)
    {
      /* wiimote IR */
      struct ir_t ir;
      WPAD_IR(num, &ir);
      if (ir.valid)
      {
        input.analog[i-4][0] = (ir.x * bitmap.viewport.w) / 640;
        input.analog[i-4][1] = (ir.y * bitmap.viewport.h) / 480;
        if (p & WPAD_BUTTON_B) input.pad[i]  |= INPUT_B;
      }
    }
  }

  /* PEN tablet position (x,y) */
  else if ((system_hw == SYSTEM_PICO) && (i == 0))
  {
    if (x || y)
    {
      /* analog stick */
      input.analog[0][0] += x / sensitivity;
      input.analog[0][1] -= y / sensitivity;
      if (input.analog[0][0] < 0x17c) input.analog[0][0] = 0x17c;
      else if (input.analog[0][0] > 0x3c) input.analog[0][0] = 0x3c;
      if (input.analog[0][1] < 0x1fc) input.analog[0][1] = 0x1fc;
      else if (input.analog[0][1] > 0x3f3) input.analog[0][1] = 0x3f3;
    }

    if (exp != WPAD_EXP_CLASSIC)
    {
      /* wiimote IR */
      struct ir_t ir;
      WPAD_IR(num, &ir);
      if (ir.valid)
      {
        input.analog[0][0] = 0x3c  + (ir.x * (0x17c - 0x3c  + 1)) / 640;
        input.analog[0][1] = 0x1fc + (ir.y * (0x3f3 - 0x1fc + 1)) / 480;
        if (p & WPAD_BUTTON_B) input.pad[i]  |= INPUT_B;
      }
    }
  }

  /* MOUSE quantity of movement (-256,256) */
  else if (input.dev[i] == DEVICE_MOUSE)
  {
    /* analog stick */
    input.analog[2][0] = x * 2 / sensitivity;
    input.analog[2][1] = 0 - y * 2 / sensitivity;
 
    if (exp != WPAD_EXP_CLASSIC)
    {
      /* wiimote IR */
      struct ir_t ir;
      WPAD_IR(num, &ir);
      if (ir.valid)
      {
        input.analog[2][0] = ir.x - old_x;
        if (input.analog[2][0] > 256)
        {
          input.analog[2][0] = 256;
          old_x += 256;
        }
        else if (input.analog[2][0] < -256)
        {
          input.analog[2][0] = -256;
          old_x -= 256;
        }
        else
        {
          old_x = ir.x;
        }

        input.analog[2][1] = ir.y - old_y;
        if (input.analog[2][1] > 256)
        {
          input.analog[2][1] = 256;
          old_y += 256;
        }
        else if (input.analog[2][1] < -256)
        {
          input.analog[2][1] = -256;
          old_y -= 256;
        }
        else
        {
          old_y = ir.y;
        }

        if (p & WPAD_BUTTON_B) input.pad[i]  |= INPUT_B;
      }
      else
      {
        old_x += input.analog[2][0];
        old_y += input.analog[2][1];
      }
    }

    if (!config.invert_mouse) input.analog[2][1] = 0 - input.analog[2][1];

  }

  /* GAMEPAD directional buttons */
  else
  {
    if ((p & wpad_dirmap[exp][PAD_UP])          || (y >  sensitivity)) input.pad[i] |= INPUT_UP;
    else if ((p & wpad_dirmap[exp][PAD_DOWN])   || (y < -sensitivity)) input.pad[i] |= INPUT_DOWN;
    if ((p & wpad_dirmap[exp][PAD_LEFT])        || (x < -sensitivity)) input.pad[i] |= INPUT_LEFT;
    else if ((p & wpad_dirmap[exp][PAD_RIGHT])  || (x >  sensitivity)) input.pad[i] |= INPUT_RIGHT;
  }

  /* SOFTRESET */
  if (((p & WPAD_CLASSIC_BUTTON_PLUS) && (p & WPAD_CLASSIC_BUTTON_MINUS)) ||
      ((p & WPAD_BUTTON_PLUS) && (p & WPAD_BUTTON_MINUS)))
  {
    set_softreset();
  }

  /* MENU */
  if (p & wpad_keymap[KEY_MENU])
  {
    ConfigRequested = 1;
  }
}
Example #9
0
int main() {

    // Initializing GRRLIB
    GRRLIB_Init();

    // Initializing Wiimotes
    WPAD_Init();
    // IR init
    rmode = VIDEO_GetPreferredMode(NULL);
    GXRModeObj *rmode = IR_Init();
    WPAD_SetVRes(WPAD_CHAN_ALL,rmode->fbWidth,rmode->xfbHeight);
    WPAD_SetDataFormat(WPAD_CHAN_0,WPAD_FMT_BTNS_ACC_IR);

    //IR pointer
    ir_t irPointer;

    // Data textures
    GRRLIB_texImg * texFont = GRRLIB_LoadTexture(font_png);
    GRRLIB_InitTileSet(texFont, 8, 16, 0);
    GRRLIB_texImg* pointer = GRRLIB_LoadTexture(pointer_png);
    GRRLIB_SetMidHandle(pointer,true);

    // Objects
    Button left;
    left.initButton(0, maxY/2, 15, 60);
    Button right;
    right.initButton(maxX-15, maxY/2, 15, 60);	
    Circle move;
    move.initCircle(maxX/2, maxY/2, 10);

    // Globals variables
    bool finProgramme = false;	
    int pass = 0;
    float b=0.0;
    float speed = 3;
    int scoreL = 0;
    int scoreR = 0;

    while (!finProgramme){


        WPAD_ScanPads();  //Scan wiimotes
        WPAD_IR(WPAD_CHAN_0, &irPointer);

        if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) finProgramme = true;

        //==================== DRAW START ========================
        GRRLIB_Rectangle(left.x, left.y, left.width, left.height, 0xFF0000FF, 1);
        GRRLIB_Rectangle(right.x, right.y, right.width, right.height, 0x00FF00FF, 1);
        GRRLIB_Circle(move.x, move.y, move.radius, CLR_WHITE, 2);	  
        //GRRLIB_DrawImg(irPointer.x, irPointer.y, pointer, 0, 1, 1, CLR_WHITE);

        //GRRLIB_DrawImg(0,0,titlescreen,0,1,1,CLR_UNKNOW);
        char* posX =(char*)malloc(sizeof(char));
        char* posY =(char*)malloc(sizeof(char));
        char* showScoreL = (char*)malloc(sizeof(char));
        char* showScoreR = (char*)malloc(sizeof(char));
        sprintf(posX,"%.3f",irPointer.x);
        sprintf(posY,"%.3f",irPointer.y);
        sprintf(showScoreL, "%d", scoreL);
        sprintf(showScoreR, "%d", scoreR);
        GRRLIB_Printf(20 + 15, 16 + 15, texFont, CLR_WHITE, 2, posX);
        GRRLIB_Printf(20 + 15, 16 + 60, texFont, CLR_WHITE, 2, posY);
        GRRLIB_Printf(300, 50, texFont, 0xFF0000FF, 2, showScoreL);
        GRRLIB_Printf(340, 50, texFont, 0x00FF00FF, 2, showScoreR);
        free(posX);
        free(posY);
        free(showScoreL);
        free(showScoreR);
        GRRLIB_Render();
        //================== DRAW END ==============================

        // Calculate the new positions, speeds, etc…
        isMoving(move, right, left, pass, speed, b);

        // Move the player's pointer
        bMove(right, irPointer);
        // Move the IA player
        ia(left, move, speed);

        // If the ball reaches one side of the screen,
        // Start a new game and count the points !
        if(move.x - move.radius > maxX) {
            scoreL += 1;
            move.x = maxX/2;
            move.y = maxY/2;
            b = 0.0;
            pass = 0;
            speed = 3;
        }
        if (move.x + move.radius < 0) {
            scoreR += 1;
            move.x = maxX/2;
            move.y = maxY/2;
            b = 0.0;
            pass = 0;
            speed = 3;
        }
    }

    // Clean memory
    GRRLIB_Exit();

    exit(0);
}
Example #10
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;
}
Example #11
0
cui_menu menu_play(cui_game* p_game)
{
	cui_menu next_state = CUI_MENU_MAIN;
	bool done=false;
	
	GRRLIB_texImg *tex_pieces = GRRLIB_LoadTexture(chess_classic_png);
	GRRLIB_texImg *tex_tile = GRRLIB_LoadTexture(keyboard_key_png);	
	GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); 
	bool is_debug = false;

	char coords[5];
	char calculated_coords[5];
	
	strcpy(coords, "d2d20");
	strcpy(calculated_coords, "d2d20");
	
	while(!done){
		WPAD_IR(0, &ir);
		WPAD_ScanPads();
		
		u32 pressed = WPAD_ButtonsDown(0);
		u32 released = WPAD_ButtonsUp(0);
		
		if(egg_check_s1_code(pressed, released)){
			is_debug = true;
			p_game->board->tile_color1 = 0xc66300FF;
			p_game->board->tile_color2 = 0x632100FF;
			p_game->board->piece_color1 = 0x4242CCFF;
			p_game->board->piece_color2 = 0x444411FF;
			cui_board_init(p_game->board);
			if(voice) AESND_PlayVoice(voice, VOICE_STEREO8, warp, warp_size, VOICE_FREQ32KHZ, 1, false);
		}

		if ( pressed & WPAD_BUTTON_HOME ){
			if(!p_game->is_mute)AESND_Pause(true);
			if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;}	
			if(!p_game->is_mute)AESND_Pause(false);
		}
		
		if ( pressed & WPAD_BUTTON_MINUS){
			switch(menu_option(p_game)){
				case CUI_MENU_OPTION_GFX:menu_option_gfx(p_game);break;
				case CUI_MENU_OPTION_SND:menu_option_snd(p_game);break;
				default:break;
			}
		}
		
		int index_offset_x = (p_game->cursor->hotspot_x - 40 / 2)/ 40 - 140 / 40;
		int index_offset_y = p_game->cursor->hotspot_y / 40 - 80 / 40;
		
		if (pressed & WPAD_BUTTON_B) {
			p_game->cursor->is_grabbing = true;
			
			if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){
				coords[0] = 'a' + index_offset_x;
				coords[1] = '8' - index_offset_y;
			}
				
		}
		else if(released & WPAD_BUTTON_B){
			p_game->cursor->is_grabbing = false;

			if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){
				coords[2] = 'a' + index_offset_x;
				coords[3] = '8' - index_offset_y;
				coords[4] = 0;

				if(voice) AESND_PlayVoice(voice, VOICE_STEREO16, move_pcm, move_pcm_size, VOICE_FREQ48KHZ, 1, false);
				
				if(calculate_coords(coords, calculated_coords, p_game->engine)){
					cui_board_read_core(p_game->board, p_game->engine);
				}
				
			}
		}
		
		cui_cursor_update(p_game->cursor, ir.x, ir.y, ir.angle);
		
		
		if(p_game->tex_wallpaper)GRRLIB_DrawImg(0, -50, p_game->tex_wallpaper, 1, 1, 1, 0XFFFFFFFF);
		
		cui_board_display(p_game->board, tex_pieces, tex_tile, font, index_offset_x, index_offset_y);
		cui_cursor_display(p_game->cursor);
		
		if(is_debug){
			GRRLIB_PrintfTTF (20, 00, font, coords, 16, 0x424242FF);
			GRRLIB_PrintfTTF2 (20, 20, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x, ir.y);
			GRRLIB_PrintfTTF2 (20, 40, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x/40, ir.y/40);
			GRRLIB_PrintfTTF2 (20, 60, font, 16, 0xFFFFFFFF, "x:%d y:%d", index_offset_x, index_offset_y);
			GRRLIB_PrintfTTF (20, 80, font, p_game->cursor->is_grabbing?"GRAB":"POINT", 16, 0xFFFFFFFF);
			
			GRRLIB_Rectangle(p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, 4, 4, 0xFF4242FF, 1);
		}
	
		GRRLIB_Render();
	}
	
	GRRLIB_FreeTexture(tex_pieces);
	GRRLIB_FreeTexture(tex_tile);
	GRRLIB_FreeTTF(font);
		
	return next_state;
}
Example #12
0
static void wpad_update(void)
{
  int i,use_wpad;
  u32 exp;
  u32 p;
  s8 x,y;
  struct ir_t ir;

  /* update WPAD data */
  WPAD_ScanPads();

  for (i=0; i<2; i++)
  {
    /* check WPAD status */
    if ((WPAD_Probe(i, &exp) == WPAD_ERR_NONE))
    {
      p = WPAD_ButtonsHeld(i);
      x = WPAD_StickX(i, 0);
      y = WPAD_StickY(i, 0);

      if ((i == 0) && (exp == WPAD_EXP_CLASSIC)) use_wpad = 1;
      else use_wpad = 0;

      /* retrieve current key mapping */
      u8 index = exp + (3 * i);
   
      /* MENU */
      if ((p & wpad_keymap[index][KEY_MENU]) || (p & WPAD_BUTTON_HOME))
      {
        ConfigRequested = 1;
        return;
      }

      /* PAUSE & START */
      if (p & wpad_keymap[index][KEY_PAUSE])
        input.system |= (sms.console == CONSOLE_GG) ? INPUT_START : INPUT_PAUSE;

      /* RESET */
      if (((p & WPAD_CLASSIC_BUTTON_PLUS) && (p & WPAD_CLASSIC_BUTTON_MINUS)) ||
          ((p & WPAD_BUTTON_PLUS) && (p & WPAD_BUTTON_MINUS)) || softreset)
      {
        input.system |= INPUT_RESET;
        softreset = 0;
        SYS_SetResetCallback(set_softreset);
      }
      
      /* BUTTON 1 */
      if (p & wpad_keymap[index][KEY_BUTTON1])
        input.pad[i] |= INPUT_BUTTON1;
      if (use_wpad && (p & wpad_keymap[0][KEY_BUTTON1]))
        input.pad[1] |= INPUT_BUTTON1;

      /* BUTTON 2 */
      if (p & wpad_keymap[index][KEY_BUTTON2])
        input.pad[i] |= INPUT_BUTTON2;
      if (use_wpad && (p & wpad_keymap[0][KEY_BUTTON2]))
        input.pad[1] |= INPUT_BUTTON2;

      /* check emulated device type */
      switch (sms.device[i])
      {
        /* digital gamepad */
        case DEVICE_PAD2B:

          /* directional buttons */
          if ((p & wpad_dirmap[exp][PAD_UP])    || (y >  70)) input.pad[i] |= INPUT_UP;
          else if ((p & wpad_dirmap[exp][PAD_DOWN])  || (y < -70)) input.pad[i] |= INPUT_DOWN;
          if ((p & wpad_dirmap[exp][PAD_LEFT])  || (x < -60)) input.pad[i] |= INPUT_LEFT;
          else if ((p & wpad_dirmap[exp][PAD_RIGHT]) || (x >  60)) input.pad[i] |= INPUT_RIGHT;

          if (use_wpad)
          {
            if ((p & wpad_dirmap[0][PAD_UP])    || (y >  70)) input.pad[1] |= INPUT_UP;
            else if ((p & wpad_dirmap[0][PAD_DOWN])  || (y < -70)) input.pad[1] |= INPUT_DOWN;
            if ((p & wpad_dirmap[0][PAD_LEFT])  || (x < -60)) input.pad[1] |= INPUT_LEFT;
            else if ((p & wpad_dirmap[0][PAD_RIGHT]) || (x >  60)) input.pad[1] |= INPUT_RIGHT;
          }
          break;

        /* analog devices */
        case DEVICE_LIGHTGUN:
        case DEVICE_SPORTSPAD:
        case DEVICE_PADDLE:

          /* X position */
          if (p & wpad_dirmap[exp][PAD_LEFT]) input.analog[i][0] --;
          else if (p & wpad_dirmap[exp][PAD_RIGHT]) input.analog[i][0] ++;
          else if (x) input.analog[i][0] = (u8)(x + 128);

          /* Y position */
          if (p & wpad_dirmap[exp][PAD_UP]) input.analog[i][1] --;
          else if (p & wpad_dirmap[exp][PAD_DOWN]) input.analog[i][1] ++;
          else if (y) input.analog[i][1] = (u8)(128 - y);

          /* by default, use IR pointing */
          WPAD_IR(i, &ir);
          if (ir.valid)
          {
            input.analog[i][0] = (ir.x * 4) / 10;
            input.analog[i][1] = ir.y / 2;
            if (p & WPAD_BUTTON_A) input.pad[i] |= INPUT_BUTTON1;
          }

          /* limiter */
          if (input.analog[i][0] < 0) input.analog[i][0] = 0;
          else if (input.analog[i][0] > 0xFF) input.analog[i][0] = 0xFF;
          if (input.analog[i][1] < 0) input.analog[i][1] = 0;
          else if (input.analog[i][1] > 0xFF) input.analog[i][1] = 0xFF;

          break;
      
        /* none */
        default:
          break;
      }

      /* Colecovision keypad support */
      if (sms.console == CONSOLE_COLECO)
      {
        u32 pad;
        u32 d = WPAD_ButtonsDown(i);

        input.system = 0;
        if (d & WPAD_CLASSIC_BUTTON_PLUS)
        {
          pad = (coleco.keypad[i] & 0x0f) + 1;
          if (pad > 11) pad = 0;
          if (pad == 11)
            sprintf(osd.msg,"KeyPad(%d) #",i+1);
          else if (pad == 10) 
            sprintf(osd.msg,"KeyPad(%d) *",i+1);
          else  sprintf(osd.msg,"KeyPad(%d) %d",i+1,pad);
          osd.frames = 60;
          coleco.keypad[i] = (coleco.keypad[i] & 0xf0) | pad;
        }

        if (p & WPAD_CLASSIC_BUTTON_MINUS)
          coleco.keypad[i] &= 0x0f;

        if (use_wpad)
        {
          if (d & WPAD_BUTTON_PLUS)
          {
            pad = (coleco.keypad[1] & 0x0f) + 1;
            if (pad > 11) pad = 0;
            if (pad == 11)
              sprintf(osd.msg,"KeyPad(2) #");
            else if (pad == 10) 
              sprintf(osd.msg,"KeyPad(2) *");
            else
              sprintf(osd.msg,"KeyPad(2) %d",pad);
            osd.frames = 60;
            coleco.keypad[1] = (coleco.keypad[1] & 0xf0) | pad;
          }

          if (p & WPAD_BUTTON_MINUS)
            coleco.keypad[1] &= 0x0f;
        }
        else
        {
          if (d & WPAD_BUTTON_PLUS)
          {
            pad = (coleco.keypad[i] & 0x0f) + 1;
            if (pad > 11) pad = 0;
            if (pad == 11)
              sprintf(osd.msg,"KeyPad(%d) #",i+1);
            else if (pad == 10) 
              sprintf(osd.msg,"KeyPad(%d) *",i+1);
            else  sprintf(osd.msg,"KeyPad(%d) %d",i+1,pad);
            osd.frames = 30;
            coleco.keypad[i] = (coleco.keypad[i] & 0xf0) | pad;
          }

          if (p & WPAD_BUTTON_MINUS)
            coleco.keypad[i] &= 0x0f;
        }
      }
    }
  }
}