Frustrating Input
August 19, 2008 04:54AM
I've made a small black Jack game a while ago for a console window, and I'm having some problems with recieving input. One of the functions:

{
cout << m_Name << ", do you want a hit? (Y/N): ";
char response;
cin >> response;
return (response == 'y' || response == 'Y');
}

I'm having some trouble with. Basically I tried replacing it with this:

bool Player::IsHitting() const
{
cout << m_Name << ", do you want a hit? Yes (A)/NO (b): ";
char response;

u32 pressed, oldPressing;

while (response != 'y' || response !='n') {

WPAD_ScanPads();
pressed = WPAD_ButtonsHeld(WPAD_CHAN_0);

if(pressed & WPAD_BUTTON_A != oldPressing)
response = 'y';

if(pressed & WPAD_BUTTON_B != oldPressing)
response = 'n';

oldPressing = pressed;
}

return (response == 'y');
}

But this still doesn't work. The main problem with the nature of the wii input compared with cin, is that the program will wait at cin, but not at if (pressed & stuff etc). I thought I could get around that problem with the oldPressing variable, but it has so far failed. If you press a button, it will be held over a lot of loops even if you only tap it quickly, so I need something that says "you pressed A last loop, therefore, I will wait until you have released before recieving input again".
Re: Frustrating Input
August 19, 2008 05:33AM
If you're looking for single button presses, there's a WPAD_ButtonsDown() function.

-Santa
Re: Frustrating Input
August 19, 2008 05:35AM
Ok, thanks :)

EDIT: argh, so many edits, anyways, would this do the job?

while (response != 'y' && response != 'n') {
PAD_ScanPads();
WPAD_ScanPads();

if(WPAD_ButtonsDown(0)&WPAD_BUTTON_A)
response = 'y';

if(WPAD_ButtonsDown(0)&WPAD_BUTTON_B)
response = 'n';
}



Edited 3 time(s). Last edit at 08/19/2008 05:50AM by WiiPhlex.
Re: Frustrating Input
August 19, 2008 06:03AM
Yes, that looks like it would work. Here's how I would approach it:

bool Player::IsHitting() const
{
  u32 button;
  cout << m_Name << ", do you want a hit? Yes (A)/NO (b): ";

  while (1) {
    WPAD_ScanPads();
    button = WPAD_ButtonsDown(WPAD_CHAN_0);
    if (button & (WPAD_BUTTON_A | WPAD_BUTTON_B))
	break;
   //usually there's some delay at this point, like a video sync
  }

  return (button & WPAD_BUTTON_A);
}

Sorry, only registered users may post in this forum.

Click here to login