/** * Entry point of program. */ int main(int argc, char ** argv) { init(); while(true) // Keep app running { setupGame(); while(game.lives) // New Round { setupRound(); while(!game.gameover) // Neither player missed the ball { getInput(); processAI(); moveBall(); displayOutput(); // Sleep PA_CheckLid(); PA_WaitForVBL(); } postRound(); } postGame(); } return 0; }
void postRound() { if(ball.vy > 0) game.lives--; if(game.lives) { if(ball.vy > 0) // I lose { PA_OutputSimpleText(SCREEN_TOP,0,6,"YOU LOSE THIS ROUND"); if(game.lives>1) PA_OutputText(SCREEN_TOP,0,7,"ONLY %d BALLS LEFT!", game.lives); else PA_OutputSimpleText(SCREEN_TOP,0,7,"LAST BALL"); }else{ // They lose game.score++; if(game.lives<5) game.lives++; PA_OutputSimpleText(SCREEN_TOP,0,6,"YOU WIN THIS ROUND"); if(game.score>1) PA_OutputText(SCREEN_TOP,0,7,"YOU HAVE %d POINTS!", game.score); else PA_OutputSimpleText(SCREEN_TOP,0,7,"YOU EARNED A POINT & A BALL!"); } PA_OutputSimpleText(SCREEN_TOP,0,12,"Press A to Play Again"); while(!Pad.Newpress.A && !Stylus.Newpress) { if(Pad.Newpress.X) PA_SetDSLBrightness(0); if(Pad.Newpress.Y) PA_SetDSLBrightness(1); if(Pad.Newpress.B) PA_SetDSLBrightness(2); if(Pad.Newpress.Start) PA_SetDSLBrightness(3); // Sleep PA_CheckLid(); PA_WaitForVBL(); } } }
void postGame() { PA_PauseMod(1); bool submitted = false; while(!Pad.Newpress.Start && !Stylus.DblClick && !submitted) { PA_ClearTextBg(SCREEN_TOP); PA_OutputSimpleText(SCREEN_TOP,0,0,"GAME OVER"); PA_OutputText(SCREEN_TOP,0,1,"YOUR SCORE: %d", game.score); if(game.score<highscore.points) { PA_OutputText(SCREEN_TOP,0,2,"%s's High Score: %d", highscore.name, highscore.points); PA_OutputSimpleText(SCREEN_TOP,0,4,"Press Start to Play Again"); }else{ PA_OutputText(SCREEN_TOP,0,2,"NEW HIGH SCORE!!!"); highscore.points=game.score; highscore.name=(char*)PA_UserInfo.Name; PA_OutputSimpleText(SCREEN_TOP,0,3,"Press Y To submit score online."); PA_OutputSimpleText(SCREEN_TOP,0,4,"Press Start to Play Again"); if(Pad.Newpress.Y) { PA_OutputSimpleText(SCREEN_TOP,0,5,"Ranking globally..."); // Init Network PA_InitWifi(); if(PA_ConnectWifiWFC()) { submitScore(); getHighScores(); submitted=true; Wifi_DisconnectAP(); }else{ PA_OutputSimpleText(SCREEN_TOP,0,6,"Wifi Connection Failed."); } Wifi_DisableWifi(); } } // Sleep PA_CheckLid(); PA_WaitForVBL(); } }
int main(int argc, char *argv[]) { /* Quickly enable the ANSI console */ consoleDemoInit(); int nb_a = 0; int nb_b = 0; int nb_x = 0; int nb_y = 0; int nb_l = 0; int nb_r = 0; int nb_up = 0; int nb_down = 0; int nb_left = 0; int nb_right = 0; volatile int frame = 0; while(1) { frame++; scanKeys(); // Clear screen iprintf("\x1b[2J"); printf("Frame:%d\n", frame); { printf("Pressed:\n"); int keys = keysHeld(); printf("A:%d B:%d X:%d Y:%d L:%d R:%d \n", bool(keys & KEY_A), bool(keys & KEY_B), bool(keys & KEY_X), bool(keys & KEY_Y), bool(keys & KEY_L), bool(keys & KEY_R) ); printf("^:%d v:%d <:%d >:%d \n", bool(keys & KEY_UP), bool(keys & KEY_DOWN), bool(keys & KEY_LEFT), bool(keys & KEY_RIGHT) ); } { printf("Counter:\n"); int keys = keysDown(); nb_a += bool(keys & KEY_A); nb_b += bool(keys & KEY_B); nb_x += bool(keys & KEY_X); nb_y += bool(keys & KEY_Y); nb_r += bool(keys & KEY_R); nb_l += bool(keys & KEY_L); printf("A:%d B:%d X:%d Y:%d L:%d R:%d\n", nb_a, nb_b, nb_x, nb_y, nb_l, nb_r ); nb_up += bool(keys & KEY_UP); nb_down += bool(keys & KEY_DOWN); nb_left += bool(keys & KEY_LEFT); nb_right += bool(keys & KEY_RIGHT); printf("^:%d v:%d <:%d >:%d \n", nb_up, nb_down, nb_left, nb_right ); } PA_CheckLid(); swiWaitForVBlank(); } return 0; }
int main() { PA_Init(); // Initialisation de la PALib PA_InitVBL(); // Initialisation de l'affichage splash(); // Initialisation du texte, de la palette et du son PA_LoadDefaultText(0, 0); //bas PA_LoadDefaultText(1, 0); //haut PA_SetTextTileCol(1, TEXT_BLACK); // texte en noir (haut) PA_SetTextTileCol(0, TEXT_BLACK); // texte en noir (bas) PA_LoadSpritePal(0, 1, (void*)feu_Pal); // palette du feu PA_LoadSpritePal(0, 2, (void*)mario_Pal); //palette pour mario PA_LoadSpritePal(0, 3, (void*)boite_Pal); //palette pour la boite PA_LoadSpritePal(0, 4, (void*)piece_Pal); //palette pour la piece AS_Init(AS_MODE_16CH); //son AS_SetDefaultSettings(AS_PCM_8BIT, 8000, 0); //son (type,rate) AS_SoundDefaultPlay(fond_smgboss1, fond_smgboss1_size, 50, 64, true, 0); //musique de fond en boucle //Accueil accueil: fonduentree(); //fondu d'entrée PA_LoadBackground(0, 1, &jeu); PA_LoadBackground(1, 1, &titre); if(PA_UserInfo.Language == 2) { PA_OutputText(0, 3, 6, "Le but est d'appuyer"); PA_OutputText(0, 3, 7, "sur les boutons le"); PA_OutputText(0, 3, 8, "plus vite possible."); PA_OutputText(0, 3, 9, "Quand vous appuyez sur"); PA_OutputText(0, 3, 10, "un bouton, votre score"); PA_OutputText(0, 3, 11, "augmente de un."); PA_OutputText(0, 3, 16, "Appuyez sur un bouton"); PA_OutputText(0, 3, 17, "pour commencer !"); } else { PA_OutputText(0, 3, 6, "The aim is to press the"); PA_OutputText(0, 3, 7, "buttons as fast as you can."); PA_OutputText(0, 3, 8, "When a button is pressed,"); PA_OutputText(0, 3, 9, "it add 1 point to"); PA_OutputText(0, 3, 10, "your score."); PA_OutputText(0, 3, 16, "Press any button to start !"); } PA_WaitFor(Pad.Newpress.Anykey || Stylus.Newpress); //Variables u32 coups = 0; //A vos marques, pret, partez ! PA_ClearTextBg(0); //efface tout le texte du bas PA_VBLCounterStart(0); // compteur //A vos marques AS_SoundQuickPlay(un); PA_CreateSprite(0, 0, (void*)feu_Sprite, OBJ_SIZE_32X64, 1, 1, 200, 30); //feu, sprite 0 if(PA_UserInfo.Language == 2) { PA_OutputText(0, 3, 6, "A vos marques..."); } else { PA_OutputText(0, 3, 6, "Ready ?"); } PA_WaitFor(PA_VBLCounter[0]/60 == 2); //Pret AS_SoundQuickPlay(deux); PA_SetSpriteAnim(0, 0, 2); if(PA_UserInfo.Language == 2) { PA_OutputText(0, 3, 8, "Prêt ?"); } else { PA_OutputText(0, 3, 8, "Steady..."); } PA_WaitFor(PA_VBLCounter[0]/60 == 4); //Partez AS_SoundQuickPlay(trois); PA_SetSpriteAnim(0, 0, 1); if(PA_UserInfo.Language == 2) { PA_OutputText(0, 3, 10, "Partez !"); } else { PA_OutputText(0, 3, 10, "Go !"); } PA_WaitFor(PA_VBLCounter[0]/60 == 6); PA_ClearTextBg(0); //efface tout le texte du bas PA_DeleteSprite(0, 0); PA_CreateSprite(0, 1, (void*)mario_Sprite, OBJ_SIZE_32X32, 1, 2, 100, 100); //mario, sprite 1 avec palette 2 PA_CreateSprite(0, 2, (void*)boite_Sprite, OBJ_SIZE_16X16, 1, 3, 110, 84); //boite, sprite 2 avec palette 3 PA_CreateSprite(0, 3, (void*)piece_Sprite, OBJ_SIZE_8X16, 1, 4, 114, 68); //boite, sprite 2 avec palette 3 PA_VBLCounterStart(1); //compteur pour la partie à venir while(1) { PA_OutputText(0, 3, 7, "Score : %d", coups); if(PA_UserInfo.Language == 2) { PA_OutputText(0, 3, 6, "Partie en cours..."); PA_OutputText(0, 3, 8, "Temps : %d ", 20-(PA_VBLCounter[1]/60)); } else { PA_OutputText(0, 3, 6, "Game in progress..."); PA_OutputText(0, 3, 8, "Time : %d ", 20-(PA_VBLCounter[1]/60)); } //Incrémentation du score si la partie n'est pas fini if((Pad.Newpress.A || Pad.Newpress.B || Pad.Newpress.X || Pad.Newpress.Y || Pad.Newpress.L || Pad.Newpress.R || Stylus.Newpress || Pad.Newpress.Left || Pad.Newpress.Right || Pad.Newpress.Up || Pad.Newpress.Down) && PA_VBLCounter[1]/60 < 20) { PA_SetSpriteAnim(0, 1, 1); //fait sauter mario PA_SetSpriteAnim(0, 3, 1); //fait apparaitre une piece coups++; } //Lors du relachement des touches/stylet, les sprites reviennent a la normale if(Pad.Released.Anykey || Stylus.Released) { PA_SetSpriteAnim(0, 1, 0);//mario revient au sol PA_SetSpriteAnim(0, 3, 0); //et la piece disparait } //Fin de la partie if(PA_VBLCounter[1]/60 == 20) { //On efface le txt et les sprites PA_ClearTextBg(0); PA_DeleteSprite(0, 1); PA_DeleteSprite(0, 2); PA_DeleteSprite(0, 3); if(PA_UserInfo.Language == 2) { PA_OutputText(0, 3, 6, "Partie terminée !"); PA_OutputText(0, 3, 7, "Votre score : %d", coups); PA_OutputText(0, 3, 9, "Appuyez sur une touche"); PA_OutputText(0, 3, 10, "pour rejouer..."); } else { PA_OutputText(0, 3, 6, "End of the game !"); PA_OutputText(0, 3, 7, "Your score : %d", coups); PA_OutputText(0, 3, 9, "Press a button to"); PA_OutputText(0, 3, 10, "replay..."); } PA_WaitFor(PA_VBLCounter[1]/60 == 22); PA_WaitFor(Pad.Newpress.Anykey || Stylus.Newpress); goto accueil; } PA_CheckLid(); PA_WaitForVBL(); } return 0; }