void lose() { REG_DISPCTL = MODE4 | BG2_ENABLE; loadPalette(gameover_screenPal); drawBackgroundImage4(gameover_screenBitmap); while (1) { oldButtons = buttons; buttons = BUTTONS; if (BUTTON_PRESSED(BUTTON_A)) { init(); setupLevel(); state = GAME; return; } if (BUTTON_PRESSED(BUTTON_SELECT)) { playSoundB(menuSound, MENUSOUNDLEN, MENUSOUNDFREQ, 0); playSoundA(titleSong, TITLESONGLEN, TITLESONGFREQ, 1); state = SPLASH; return; } } }
void interruptHandler() { REG_IME = 0; if(REG_IF & INT_VBLANK) { // MODIFY THIS FUNCTION !!! // Add code to stop/repeat sounds here vbCountA++; if (vbCountA >= soundA.duration) { REG_TM0CNT = 0; dma[1].cnt = 0; if (soundA.loops) playSoundA(soundA.data, soundA.length, soundA.frequency, soundA.loops); } vbCountB++; if (vbCountB >= soundB.duration) { REG_TM1CNT = 0; dma[2].cnt = 0; if (soundB.loops) playSoundB(soundB.data, soundB.length, soundB.frequency, soundB.loops); } REG_IF = INT_VBLANK; } REG_IME = 1; }
void instructions() { REG_DISPCTL = MODE4 | BG2_ENABLE; loadPalette(instructionsPal); drawBackgroundImage4(instructionsBitmap); while(!BUTTON_HELD(BUTTON_B)); playSoundB(menuSound, MENUSOUNDLEN, MENUSOUNDFREQ, 0); state = SPLASH; }
void splash() { REG_DISPCTL = MODE4 | BG2_ENABLE; loadPalette(splash_screenPal); drawBackgroundImage4(splash_screenBitmap); while (1) { oldButtons = buttons; buttons = BUTTONS; if (BUTTON_PRESSED(BUTTON_START)) { init(); setupGame(); playSoundA(gameSong, GAMESONGLEN, GAMESONGFREQ, 1); playSoundB(menuSound, MENUSOUNDLEN, MENUSOUNDFREQ, 0); state = GAME; return; } if (BUTTON_PRESSED(BUTTON_SELECT)) { playSoundB(menuSound, MENUSOUNDLEN, MENUSOUNDFREQ, 0); state = INSTRUCTIONS; return; } } }
void winLevel() { REG_DISPCTL = MODE4 | BG2_ENABLE; loadPalette(win_level_screenPal); drawBackgroundImage4(win_level_screenBitmap); while (1) { oldButtons = buttons; buttons = BUTTONS; if (BUTTON_PRESSED(BUTTON_A)) { if (currentLevel + 1 <= NUMLEVELS) { currentLevel++; init(); setupLevel(); state = GAME; } else { state = GAMEEND; } return; } if (BUTTON_PRESSED(BUTTON_SELECT)) { playSoundB(menuSound, MENUSOUNDLEN, MENUSOUNDFREQ, 0); playSoundA(titleSong, TITLESONGLEN, TITLESONGFREQ, 1); state = SPLASH; return; } } }
void interruptHandler() { REG_IME = 0; if(REG_IF & INT_VBLANK) { if (soundA.isPlaying && vbCountA < soundA.duration) { // Continue vbCount until duration is reached vbCountA++; } // loop soundA else if (!soundA.isPlaying && soundA.loops) { playSoundA(soundA.data, soundA.length, soundA.frequency, soundA.loops); } else { // stop soundA soundA.isPlaying = 0; vbCountA = 0; REG_TM0CNT = 0; dma[1].cnt = 0; } if (soundB.isPlaying && vbCountB < soundB.duration) { vbCountB++; } // loop soundB else if (!soundB.isPlaying && soundB.loops) { playSoundB(soundB.data, soundB.length, soundB.frequency, soundB.loops); } else { // stop soundB soundB.isPlaying = 0; vbCountB = 0; REG_TM1CNT = 0; dma[2].cnt = 0; } REG_IF = INT_VBLANK; } REG_IME = 1; }
void interruptHandler() { REG_IME = 0; if(REG_IF & INT_VBLANK) { // MODIFY THIS FUNCTION !!! // Add code to stop/repeat sounds here vbCountA++; if(vbCountA>=soundA.duration){ REG_TM0CNT = 0; dma[1].cnt = 0; if(soundA.loops) { playSoundA(soundA.data, soundA.length, soundA.frequency, soundA.loops); } else { soundA.isPlaying = false; } } vbCountB++; if(vbCountB>=soundB.duration){ REG_TM1CNT = 0; dma[2].cnt = 0; if(soundB.loops && soundB.isPlaying) { playSoundB(soundB.data, soundB.length, soundB.frequency, soundB.loops); } else { soundB.isPlaying = false; } } REG_IF = INT_VBLANK; } // (╯°□°)╯︵ â”»â”â”» // ┬──┬ ノ( ã‚œ-゜ノ) REG_IME = 1; }
void game() { // Reset running motion in case user stops pressing arrow key player.isRunning = 0; // Running/moving speed if (player.frameCount % 4 == 0) { changeFrame(); } // Button Handling if (BUTTON_PRESSED(BUTTON_A)) { // Only jump if player is not already jumping if (canJump && checkCollision()) { canJump = 0; player.isJumping = 1; jumpFrameCounter = 30; playSoundB(jumpSound, JUMPSOUNDLEN, JUMPSOUNDFREQ, 0); jump(); } } if (BUTTON_PRESSED(BUTTON_B)) { vBlankCount = 100; prevSeason = season; playSoundB(warpSound, WARPSOUNDLEN, WARPSOUNDFREQ, 0); state = SEASONCHANGE; } if (BUTTON_PRESSED(BUTTON_START)) { REG_DISPCTL ^= BG0_ENABLE; pauseSound(); state = PAUSE; } // Change to neutral season - CHEAT MODE if (BUTTON_HELD(BUTTON_R) && BUTTON_HELD(BUTTON_L) && BUTTON_HELD(BUTTON_SELECT)) { vBlankCount = 100; prevSeason = -1; playSoundB(warpSound, WARPSOUNDLEN, WARPSOUNDFREQ, 0); state = SEASONCHANGE; } if (BUTTON_HELD(BUTTON_RIGHT)) { player.isRunning = 1; player.facing = 0; player.deltaCol = 1; if (hOff < 272 && player.col >= 120 - player.height / 2) { hOff += player.deltaCol; } else if (player.col < 240 - player.width) { player.col += player.deltaCol; } } if (BUTTON_HELD(BUTTON_LEFT)) { player.isRunning = 1; player.facing = 1; player.deltaCol = -1; if (hOff > 0 && player.col < 120 - player.width / 2) { hOff += player.deltaCol; } else if (player.col > 0) { player.col += player.deltaCol; } } // End of button handling // Jump handling if (player.isJumping) { jump(); } /* if (!canJump && hOff < 272) { player.col += player.deltaCol; } */ // Gravity and Collision if (!checkCollision() || player.isJumping) { player.isRunning = 0; // Stop running animation /*if (vOff <= 96 && player.row >= 80 - player.height / 2) { */ vOff += player.deltaRow; //} if (player.row < 160) { player.row += player.deltaRow; } else { state = LOSE; } } else { canJump = 1; player.deltaCol = 0; } // Gem collision detection - player wins current level if (checkWinCollision()) { playSoundB(winLevelSound, WINLEVELSOUNDLEN, WINLEVELSOUNDFREQ, 0); state = WINLEVEL; } // Standing still animation if (!player.isRunning) { player.currentFrame = 0; } // Running animation if (player.isRunning) { player.frameCount++; } // Seasonal BG1 Animations switch (season) { case FALL: bg1VOff--; break; case WINTER: bg1HOff--; bg1VOff--; break; } }