Welcome! Log In Create A New Profile

Advanced

Multi WiiMote support

Posted by wplaat 
Multi WiiMote support
February 04, 2009 01:08PM
Hello everybody,

Who have a c source code example to control two WiiMotes with the standard libogc library.
I would like to add multi player mode to Pong2 but do not know how? Looking forward to your reactions.

wplaat
Re: Multi WiiMote support
February 04, 2009 03:33PM
Hello,

supply another channel to the WPAD_XXX functions to read from another controller connected to the wii.

e.g.
WPAD_ScanPads();
u32 btn = WPAD_ButtonsDown(WPAD_CHAN_1);
Re: Multi WiiMote support
February 04, 2009 05:46PM
Just change WPAD_CHAN_0 to WPAD_CHAN_1 to look for controller input from a second controller.

EDIT: Oh and you'll still need your WPAD_CHAN_0 code too. WPAD_CHAN_1 only looks for input from the second wiimote.



Edited 1 time(s). Last edit at 02/04/2009 05:47PM by Arikado.
Re: Multi WiiMote support
February 04, 2009 06:18PM
You'll also need to make sure you're setup to read that additional Wiimote. In your init line, make sure you have WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
Re: Multi WiiMote support
February 04, 2009 10:10PM
Hello everybody,

I have added the lines, but still my second WiiMote will not sync (Blue leds keep blinking and after 30 second go out) here is my main loop. Wait do i wrong?

int main()
{
// Init main variables
int x1=0, y1=0, x2=0, y2=0;

// Init video layer
VIDEO_Init();

// Init wiimote layer
WPAD_Init();
WPAD_SetIdleTimeout(60); // Wiimote is shutdown after 60 seconds of innactivity.
//WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR); // enable accelerometers and IR
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);

// Set Shutdown Callbacks.
SYS_SetPowerCallback( doPowerOff );
WPAD_SetPowerButtonCallback( doPadPowerOff );

// Obtain the preferred video mode from the system
// This will correspond to the settings in the Wii menu
rmode = VIDEO_GetPreferredMode(NULL);

// allocate framebuffer (Needed for JPG welcome images)
frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));

// Initialise the console, required for printf
console_init(frameBuffer[0],20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

// Set up the video registers with the chosen mode
VIDEO_Configure(rmode);

if (rmode->xfbHeight==528)
{
// TV mode PAL 50Hz
yOffset = 25;
yjpegOffset = 25;
}
else
{
// TV mode PAL 60Hz
yOffset = 25;
yjpegOffset = 0;
}

// Tell the video hardware where our display memory is
VIDEO_SetNextFramebuffer(frameBuffer[0]);

// Make the display visible
VIDEO_SetBlack(FALSE);

// Flush the video register changes to the hardware
VIDEO_Flush();

// Init Fat
fatInitDefault();

// Load highscore from SD card
loadLocalHighScoreFile(HIGHSCORE_FILENAME);

// Load setting from SD card
loadSettingFile(SETTING_FILENAME);

// Init Http thread
initThreads();

// Init game variables
initImages();
initGame();
initSound();
initGameBoard();
initBest();

// Init FreeType font engine
GRRLIB_InitFreetype();

// Show Intro screens
drawIntroScreen(0);
drawIntroScreen(1);
drawIntroScreen(2);

// Init GRRLib graphics library
GRRLIB_InitVideo();
GRRLIB_Start();

// Make screen black
GRRLIB_FillScreen(0xFFFFFF);
GRRLIB_Render();

// Repeat forever
while(!bPowerOff )
{
// icon angle
if (++angle>=MAX_ANGLE) angle=0;

// Init StateMachine
initStateMachine();

// Draw game board and other items (buttons, bubbles, etc...)
drawScreen(x1+40, y1+40);

// Scan for button events
WPAD_SetVRes(0, 640, 480);
WPAD_ScanPads();
u32 wpaddown = WPAD_ButtonsDown(WPAD_CHAN_0);
u32 wpadup = WPAD_ButtonsDown(WPAD_CHAN_0);
u32 wpadheld = WPAD_ButtonsHeld(WPAD_CHAN_0);

// Scan for ir events
ir_t ir1;
WPAD_IR(WPAD_CHAN_0, &ir1);
x1=ir1.sx-WSP_POINTER_X;
y1=ir1.sy-WSP_POINTER_Y;

// Scan for ir events
ir_t ir2;
WPAD_IR(WPAD_CHAN_1, &ir2);
x2=ir2.sx-WSP_POINTER_X;
y2=ir2.sy-WSP_POINTER_Y;

// Scan for button events
if (wpadheld & BUTTON_A) buttonScroll(x1+40,y1+40);

if (wpaddown & BUTTON_A) buttonA(x1+40,y1+40);
if (wpadup & BUTTON_A) selectedA=false;

if (wpaddown & BUTTON_HOME) buttonExit(0);

if (wpaddown & BUTTON_1 ) button1x();
if (wpadup & BUTTON_1) selected1=false;

if (wpaddown & BUTTON_2 ) button2y();
if (wpadup & BUTTON_2) selected2=false;

// Draw wiiremote ir pointer
GRRLIB_DrawImg( x1, y1, 96, 96, images.pointer, ir1.angle, 1, 1, 255 );
GRRLIB_DrawImg( x2, y2, 96, 96, images.pointer, ir2.angle, 1, 1, 255 );
GRRLIB_Render();
}

// Shut the system down.
if ( bPowerOff )
{
SYS_ResetSystem( SYS_POWEROFF, 0, 0 );
}

return 0;
}



Edited 1 time(s). Last edit at 02/05/2009 03:16PM by wplaat.
Re: Multi WiiMote support
February 04, 2009 10:19PM
Theres nothing wrong (although I barely skimmed the code), you just dont know how to sync the wiimote to your Wii XD

No worries though, I'll tell you how: Press the sync button on your wii next to your SD slot. After five seconds press the sync button on your second wiimote (orange button underneath the wiimotes battery cover).

EDIT: I take that all back. There are a ton problems with your code.
Try this:

u32 wpaddown = WPAD_ButtonsDown(WPAD_CHAN_0);
u32 wpadup = WPAD_ButtonsDown(WPAD_CHAN_0);
u32 wpadheld = WPAD_ButtonsHeld(WPAD_CHAN_0);
u32 wpaddown1 = WPAD_ButtonsDown(WPAD_CHAN_1);
u32 wpadup1 = WPAD_ButtonsDown(WPAD_CHAN_1);
u32 wpadheld1 = WPAD_ButtonsHeld(WPAD_CHAN_1);


// Scan for button events
if (wpadheld & BUTTON_A) buttonScroll(x1+40,y1+40);

if (wpaddown & BUTTON_A) buttonA(x1+40,y1+40);
if (wpadup & BUTTON_A) selectedA=false;

if (wpaddown & BUTTON_HOME) buttonExit(0);

if (wpaddown & BUTTON_1 ) button1x();
if (wpadup & BUTTON_1) selected1=false;

if (wpaddown & BUTTON_2 ) button2y();
if (wpadup & BUTTON_2) selected2=false;

if (wpadheld1 & BUTTON_A) buttonScroll(x1+40,y1+40);

if (wpaddown1 & BUTTON_A) buttonA(x1+40,y1+40);
if (wpadup1 & BUTTON_A) selectedA=false;

if (wpaddown1 & BUTTON_HOME) buttonExit(0);

if (wpaddown1 & BUTTON_1 ) button1x();
if (wpadup1 & BUTTON_1) selected1=false;

if (wpaddown1 & BUTTON_2 ) button2y();
if (wpadup1 & BUTTON_2) selected2=false;

Do you see what I did there? You have to check for each individual channel you cant just check for the first channel. Also, there are probably similiar problems in your buttonA(), button1x(), button2y(), and buttonScroll() functions.



Edited 6 time(s). Last edit at 02/04/2009 10:38PM by Arikado.
Re: Multi WiiMote support
February 05, 2009 03:19PM
Hi Arikado, Thanks for you fast reply. I will try this evening and let you known if this is solving my problem. Best regards...
Re: Multi WiiMote support
February 05, 2009 05:35PM
No problem wplaat, I hope I was clear enough. Its redundant, but just remember you have to check input for each channel and then change the variables for each paddle accordingly. I wrote a small game called battle pong (look for the link to the source in the topic "making a head to head online game" (sorry I'm on a psp so I cant link now )). It has two player support so its (extremely simple) source may help you out.



Edited 1 time(s). Last edit at 02/05/2009 05:36PM by Arikado.
Re: Multi WiiMote support
February 05, 2009 08:54PM
Hi Arikado,

It is working. Great!!! I did not know that you could sync the WiiRemote by this hidden button on the Wii Console.
Wants again many thanks now i can build a multi player version of Pong2 and other game i created. bye!

wplaat
Re: Multi WiiMote support
February 05, 2009 09:21PM
Your welcome. Good luck on your projects :)
Sorry, only registered users may post in this forum.

Click here to login