int main(int argc, char** argv) { InitWiimotes(); bool bLoop = true; float fRatio = -1.0; float fScale = -1.0; while(bLoop) { int n; if(wiiuse_poll(WMTable, nConnectedWM)) { for (n=0 ; n>nConnectedWM; n++); { switch(WMTable[n]->event) { case WIIUSE_NONE: break; case WIIUSE_CONNECT: printf("Wiimote connectee\n");break; case WIIUSE_DISCONNECT: printf("Wiimote deconnectee\n");break; case WIIUSE_UNEXPECTED_DISCONNECT: printf("Wiimote deconnectee a la bourrin\n");break; case WIIUSE_EVENT: if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_A)) { /* //Recherche des deux sources infrarouges for(int i=0 ; i<4 && (dot0==0 && dot1==0) ; i++) { if(WMTable[n]->ir.dot[i].visible) { if(dot0==0) dot0 = &WMTable[n]->ir.dot[i]; else dot1 = &WMTable[n]->ir.dot[i]; } }*/ dot0=&WMTable[n]->ir.dot[0]; dot1=&WMTable[n]->ir.dot[1]; if(dot0->visible && dot1->visible) { //Calibration ! float fDistDotToDot = GetDistanceBetweenDots(); fRatio = DIST_DOT2WM_MM*fDistDotToDot; //TESTS ONLY : fRatio = DIST_DOT2WM_MM*273.1; fScale = DIST_DOT2DOT_MM/fDistDotToDot; //TESTS ONLY fScale = DIST_DOT2DOT_MM/273.1; printf("Wiimote calibree !\n"); } else { printf("La calibration requiers deux sources infrarouges\n"); } } break; case WIIUSE_STATUS: printf("Wiimote status\n"); printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", WMTable[n]->unid); printf("leds: %i %i %i %i\n", WIIUSE_IS_LED_SET(WMTable[n], 1), WIIUSE_IS_LED_SET(WMTable[n], 2), WIIUSE_IS_LED_SET(WMTable[n], 3), WIIUSE_IS_LED_SET(WMTable[n], 4)); printf("battery: %.1f %%\n", 100*WMTable[n]->battery_level); printf("\n\nWIIMOTE NON CALIBREE ! Appuyez sur A une fois les sources placees a %dmm de la wiimote\n", DIST_DOT2WM_MM); break; case WIIUSE_READ_DATA: printf("Wiimote read\n"); break; case WIIUSE_NUNCHUK_INSERTED: printf("Nunchuk insere\n");break; case WIIUSE_NUNCHUK_REMOVED: printf("Nunchuk enleve\n");break; case WIIUSE_CLASSIC_CTRL_INSERTED: case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED: case WIIUSE_CLASSIC_CTRL_REMOVED: case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: break; } } } #define ARROW_SPEED 3 #define SCREEN_WIDTH 1920 #define SCREEN_HEIGHT 1080 struct coord posA, posB, posC; for (n=0 ; n>nConnectedWM; n++); { } if(fRatio!=-1.0 && fScale!=-1.0) { printf("\n\nPosition :\n"); if(dot0->visible && dot1->visible) { //Positon des dots posA.x = dot0->x; posA.y = 768-dot0->y; posB.x = dot1->x; posB.y = 768-dot1->y; //Position du centre posC.x = (posA.x+posB.x)/2; posC.y = (posA.y+posB.y)/2; //Calcul de la sistance en px séparant les dots float fDistDotToDot = sqrt( (dot0->x-dot1->x)*(dot0->x-dot1->x)+(dot0->y-dot1->y)*(dot0->y-dot1->y) ); //Distance suivant z //float fZ = fRatio/fDistDotToDot; //printf("x=%.2fmm y=%.2fmm z=%.2fmm\n", (posC.x-512)*fScale*fZ/DIST_DOT2WM_MM, (posC.y-384)*fScale*fZ/DIST_DOT2WM_MM, fZ); float fY=-fRatio/fDistDotToDot; float fX=-(posC.x-512)*fScale*fY/DIST_DOT2WM_MM; float fZ=(posC.y-384)*fScale*fY/DIST_DOT2WM_MM; printf("x=%.2fmm y=%.2fmm z=%.2fmm\n", fX, fY, fZ); } else printf("Sources IR hors du champ de vision\n"); } //SDL_Flip(oApp); } EndWiimotes(); return 0; }
int main(int argc, char** argv) { InitWiimotes(); bool bLoop = true; int nCursorControl = CUR_CTRL_ARROWS; float fMouseSpeedX=0; float fMouseSpeedY=0; int nPrecX, nPrecY; while(bLoop) { int n; if(wiiuse_poll(WMTable, nConnectedWM)) { for (n=0 ; n>nConnectedWM; n++); { switch(WMTable[n]->event) { case WIIUSE_NONE: break; case WIIUSE_CONNECT: printf("Wiimote connectee\n");break; case WIIUSE_DISCONNECT: printf("Wiimote deconnectee\n");break; case WIIUSE_UNEXPECTED_DISCONNECT: printf("Wiimote deconnectee a la bourrin\n");break; case WIIUSE_EVENT: if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_TWO)) printf("2 NON SUPPORTE\n"); //Touche combo ! while(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_ONE) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_ONE)) { while(wiiuse_poll(WMTable, nConnectedWM)) { if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_B)) { printf("Controle du curseur par pointage\n"); nPrecX=-1; nPrecY=-1; nCursorControl = CUR_CTRL_MOTPOINT; break; } else if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_A)) { printf("Controle du curseur en manette\n"); nPrecX=-1; nPrecY=-1; nCursorControl = CUR_CTRL_MOTPAD; break; } else if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_HOME)) { printf("Controle du curseur via IR\n"); nPrecX=-1; nPrecY=-1; nCursorControl = CUR_CTRL_IR; break; } else if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_UP) || IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_DOWN) || IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_RIGHT) || IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_LEFT)) { printf("Controle du curseur avec les fleches\n"); nPrecX=-1; nPrecY=-1; nCursorControl = CUR_CTRL_ARROWS; break; } } } //Souris . Clic gauche = B if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_B)) mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0); if(IS_RELEASED(WMTable[n], WIIMOTE_BUTTON_B)) mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); // //Souris . molette haut if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_MINUS)) mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 120, 0); // //Souris . Bouton milieu = HOME if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_HOME)) mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0); if(IS_RELEASED(WMTable[n], WIIMOTE_BUTTON_HOME)) mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0); // //Souris . molette bas if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_PLUS)) mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -120, 0); // //Souris . Clic droit = A if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_A)) mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); if(IS_RELEASED(WMTable[n], WIIMOTE_BUTTON_A)) mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // break; case WIIUSE_STATUS: printf("Wiimote status\n"); printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", WMTable[n]->unid); printf("leds: %i %i %i %i\n", WIIUSE_IS_LED_SET(WMTable[n], 1), WIIUSE_IS_LED_SET(WMTable[n], 2), WIIUSE_IS_LED_SET(WMTable[n], 3), WIIUSE_IS_LED_SET(WMTable[n], 4)); printf("battery: %.1f %%\n", 100*WMTable[n]->battery_level); break; case WIIUSE_READ_DATA: printf("Wiimote read\n"); break; case WIIUSE_NUNCHUK_INSERTED: printf("Nunchuk insere\n");break; case WIIUSE_NUNCHUK_REMOVED: printf("Nunchuk enleve\n");break; case WIIUSE_CLASSIC_CTRL_INSERTED: case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED: case WIIUSE_CLASSIC_CTRL_REMOVED: case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: break; } } } //else//Pas d'event { for (n=0 ; n>nConnectedWM; n++); { //Déplacement de la souris tagPOINT CursorPos; if(nCursorControl==CUR_CTRL_MOTPOINT || nCursorControl==CUR_CTRL_MOTPAD) { //Décélération permanente if(fMouseSpeedX<0) { if(fMouseSpeedX+ABSOLUTE_DECEL>0)fMouseSpeedX=0; else fMouseSpeedX+=ABSOLUTE_DECEL; } else if(fMouseSpeedX>0) { if(fMouseSpeedX-ABSOLUTE_DECEL<0)fMouseSpeedX=0; else fMouseSpeedX-=ABSOLUTE_DECEL; } if(fMouseSpeedY<0) { if(fMouseSpeedY+ABSOLUTE_DECEL>0)fMouseSpeedY=0; else fMouseSpeedY+=ABSOLUTE_DECEL; } else if(fMouseSpeedY>0) { if(fMouseSpeedY-ABSOLUTE_DECEL<0)fMouseSpeedY=0; else fMouseSpeedY-=ABSOLUTE_DECEL; } //Calcul des coordonnées sur l'écran du point donné par la wiimote int nWiimoteX; int nWiimoteY; if(nCursorControl==CUR_CTRL_MOTPOINT) { nWiimoteX = ((WMTable[0]->orient.roll+45)/90)*SCREEN_WIDTH; nWiimoteY = ((WMTable[0]->orient.pitch+60)/90)*SCREEN_HEIGHT; } else if(nCursorControl==CUR_CTRL_MOTPAD) { nWiimoteX = ((WMTable[0]->orient.pitch+45)/90)*SCREEN_WIDTH; nWiimoteY = ((-WMTable[0]->orient.roll+45)/90)*SCREEN_HEIGHT; } //Calcul de la vitesse du curseur GetCursorPos(&CursorPos); //Elimination des valeurs parasites //if((abs(nWiimoteX-nPrecX)<10 && abs(nWiimoteY-nPrecY)<10) || (nPrecX==-1 && nPrecY==-1)) { fMouseSpeedX = (nWiimoteX - CursorPos.x)/RELATIVE_ACCEL_RATIO; fMouseSpeedY = (nWiimoteY - CursorPos.y)/RELATIVE_ACCEL_RATIO; } /*else { fMouseSpeedX = (nPrecX - CursorPos.x)/RELATIVE_ACCEL_RATIO; fMouseSpeedY = (nPrecY - CursorPos.y)/RELATIVE_ACCEL_RATIO; }*/ // SetCursorPos(CursorPos.x+fMouseSpeedX, CursorPos.y+fMouseSpeedY); nPrecX=nWiimoteX; nPrecY=nWiimoteY; } else if(nCursorControl==CUR_CTRL_IR) { int nSommeX=0, nSommeY=0, nDots=0; for(int i=0 ; i<4 ; i++) { if(WMTable[n]->ir.dot[i].visible) { nDots++; nSommeX+=WMTable[n]->ir.dot[i].x; nSommeY+=WMTable[n]->ir.dot[i].y; } } float fCenterX=-1.0, fCenterY=-1.0; if(nDots!=0) { fCenterX=nSommeX/nDots; fCenterY=nSommeY/nDots; } if(fCenterX!=-1.0 && fCenterY!=-1.0) { int nWiimoteX = (fCenterX/1024)*(SCREEN_WIDTH+512)-256; int nWiimoteY = (fCenterY/768)*(SCREEN_HEIGHT+384)-192; SetCursorPos(nWiimoteX, nWiimoteY); } } else { if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_UP) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_UP)) { GetCursorPos(&CursorPos); SetCursorPos(CursorPos.x, CursorPos.y-ARROW_SPEED); } if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_DOWN) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_DOWN)) { tagPOINT CursorPos; GetCursorPos(&CursorPos); SetCursorPos(CursorPos.x, CursorPos.y+ARROW_SPEED); } if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_LEFT) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_LEFT)) { tagPOINT CursorPos; GetCursorPos(&CursorPos); SetCursorPos(CursorPos.x-ARROW_SPEED, CursorPos.y); } if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_RIGHT) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_RIGHT)) { tagPOINT CursorPos; GetCursorPos(&CursorPos); SetCursorPos(CursorPos.x+ARROW_SPEED, CursorPos.y); } } } } } EndWiimotes(); }
// Main function int main() { // Init and load stuff init(); bool plotPressed=false; bool killPressed=false; bool exitPressed=false; bool doParticle=false; bool doneMusicPlay=false; float endCount=0; short explosion=0; // Put first cirra sprite putCirra(gdl::ScreenCenterX, gdl::ScreenCenterY, 100); // Main loop while(1) { // Get player input doPlayerInput(); if (ending == false) { // Drop a Cirra into the field if (playerInput.mouseLB) { if (plotPressed==false) { putCirra(playerInput.pointerX, playerInput.pointerY, 100); //plotPressed=true; } } else { plotPressed=false; } // Kill a Cirra if (playerInput.mouseRB) { if (killPressed==false) { // Simple bounding box search, too lazy to add sorting but it works for (int s=0; s<numCirras; s++) { if (onSprite(playerInput.pointerX, playerInput.pointerY, cirra[s].x, cirra[s].y, sprites.SpriteInfo(CIRRA_DOWN))) { sound[1].Play2D(1.f + ((0.6f*((float)rand()/RAND_MAX))-0.2f), 100.f, cirra[s].x-gdl::ScreenCenterX, cirra[s].y-gdl::ScreenCenterY); killCirra(s); break; } } //killPressed=true; } } else { killPressed=false; } } // Initiate end sequence (blowing up all Cirras :) ) #ifdef PLATFORM_PC if ((playerInput.exitGame) || gdl::pc::WindowShouldClose()) { #else if (playerInput.exitGame) { #endif if (exitPressed == false) { if (ending == false) { sound[2].Play(1.f, 100.f); tnt.active = true; tnt.x = gdl::ScreenCenterX; tnt.y = gdl::ScreenCenterY; tnt.a = 100; tnt.aMove = 0; tnt.duration = 0; ending = true; #ifdef PLATFORM_PC glfwSetWindowShouldClose(gdl::pc::WindowContext, false); #endif } else { #ifdef PLATFORM_PC break; #else gdl::wii::Exit(); #endif } } exitPressed = true; } else { exitPressed = false; } // Prepare to draw stuff gdl::PrepDisplay(); // Reset sprite entry count and clear ordering table numSpriteEntries=0; memset(spriteOT, 0x00, sizeof(void*)*OT_LENGTH); // Do TNT animation if (tnt.active) { if (tnt.a > 0) { tnt.aMove += - (0.2f*gdl::Delta); tnt.a += (tnt.aMove*gdl::Delta); if (tnt.a <= 0) tnt.a = 0; } else { tnt.a = 0; } addSprite(tnt.x, tnt.y-1, 0, SHADOW); addSprite(tnt.x, tnt.y, tnt.a, TNT); doParticle ^= 1; if (doParticle) { putFireParticle(tnt.x, tnt.y, tnt.a+13); putFireParticle(tnt.x+1, tnt.y, tnt.a+13); } tnt.duration += (1.f*gdl::Delta); // Detonate! if (tnt.duration > 240) { // Kill all cirras when the TNT explodes while(numCirras) killCirra(0); sound[3].Play(1.f, 100.f); explosion = 2; endCount = 1; tnt.active = false; } } // Do Cirra entities doCirras(); doEffects(); // Draw sprites inside ordering table drawSpriteOT(); // Draw pointer (only on Wii platform) #ifdef PLATFORM_WII if ((ending == false) && (playerInput.pointerOnScreen)) { pointer.Put(playerInput.pointerX, playerInput.pointerY, gdl::Color::White, 4, 0, 1, Wiimote[0].data.ir.angle); } #endif // Draw instruction text if (ending == false) { #ifdef GDL_PLATFORM_WII font.Printf(9, 17, 1.f, gdl::Color::Black, "Press A to plot, B to kill."); font.Printf(8, 16, 1.f, gdl::Color::White, "Press A to plot, B to kill."); font.Printf(9, 33, 1.f, gdl::Color::Black, "Press Home or Reset to exit..."); font.Printf(8, 32, 1.f, gdl::Color::White, "Press Home or Reset to exit..."); #else font.Printf(9, 7, 1.f, gdl::Color::Black, "Press LMB to plot, RMB to kill."); font.Printf(8, 6, 1.f, gdl::Color::White, "Press LMB to plot, RMB to kill."); font.Printf(9, 23, 1.f, gdl::Color::Black, "Press Escape or Close to exit..."); font.Printf(8, 22, 1.f, gdl::Color::White, "Press Escape or Close to exit..."); #endif // GDL_PLATFORM_WII } // Do TNT sequence if (endCount) { if ((endCount > 10) && (doneMusicPlay == false)) { // Play 'gameover' music gdl::PlayMusic("testdata/gameover.ogg", false); doneMusicPlay = true; } if (endCount > 60) { //sprites.PutX(gdl::ScreenCenterX, gdl::ScreenCenterY, GAMEOVER, gdl::Pivot, gdl::Pivot, 0, 4, gdl::Color::White); sprites.Put(gdl::ScreenCenterX, gdl::ScreenCenterY, GAMEOVER, gdl::Color::White, gdl::Pivot, gdl::Pivot, 4.f); #ifdef GDL_PLATFORM_WII font.Printf(gdl::Centered, gdl::ScreenYres-69, 1.f, gdl::Color::Black, "Press Home or Reset again to exit"); font.Printf(gdl::Centered, gdl::ScreenYres-70, 1.f, gdl::Color::White, "Press Home or Reset again to exit"); #else font.Printf(gdl::Centered, gdl::ScreenYres-69, 1.f, gdl::Color::Black, "Press Escape or Close again to exit"); font.Printf(gdl::Centered, gdl::ScreenYres-70, 1.f, gdl::Color::White, "Press Escape or Close again to exit"); #endif } if (endCount <= 60) endCount += 1.f*gdl::Delta; } // Simple flash effect for the TNT explosion if (explosion) { gdl::DrawBoxF(0, 0, gdl::ScreenXres-1, gdl::ScreenYres-1, gdl::Color::White); explosion--; } // Display stuff gdl::Display(); } } // Init function void init() { #ifdef GDL_PLATFORM_WII // Init code for Wii fatInitDefault(); gdl::InitSystem(gdl::ModeAuto, gdl::AspectAuto, gdl::LowRes); WPAD_Init(); InitWiimotes(1); #else // Init code for PC gdl::Init("Whack-a-Cirra", 427, 240, 32, 0, 0, 2); #endif // Set clear color gdl::SetClearColor(0, 63, 127, 255); #ifdef GDL_PLATFORM_WII // Set console mode and load pointer image gdl::ConsoleMode(); if (!pointer.LoadImage("testdata/pointer.png", gdl::Nearest, gdl::RGB5A3)) exit(0); #else // Step back a directory on PC chdir("../.."); #endif // Load font if (!fontImage.LoadImage("testdata/font8x16.png", gdl::Nearest, gdl::RGB5A3)) exit(0); font.BindSheet(fontImage, 8, 16); // Load sprites if (!sprites.LoadSprites("testdata/test_sprites.tsm", "testdata/", gdl::Nearest, gdl::RGB5A3)) exit(0); // Load sound effects if (!sound[0].LoadSound("testdata/hitfloor.wav")) exit(0); if (!sound[1].LoadSound("testdata/smack.wav")) exit(0); if (!sound[2].LoadSound("testdata/fuse.wav")) exit(0); if (!sound[3].LoadSound("testdata/explode.wav")) exit(0); }