void playMenu() { u8 option=0; cpct_etm_setTileset2x4(g_tile_tileset_bg); cpct_etm_drawTilemap2x4_f(MAP_WIDTH_TILES, MAP_HEIGHT_TILES, SCR_VMEM, g_background); cpct_drawSprite (g_tile_titulo, getScreenPosition(5, 2), 32, 16); cpct_drawStringM0 ("PLAY GAME", getScreenPosition(5, 5), 15, 7); cpct_drawStringM0 ("INFINITY MODE", getScreenPosition(6, 7), 15, 7); cpct_drawStringM0 ("LEVELS MODE", getScreenPosition(6, 9), 15, 7); initScroll(); initPlayer(); cpct_scanKeyboard_f (); do { waitNVSYNCs(3); cpct_akp_musicPlay(); Road(); drawPlayer(); if ( cpct_isKeyPressed (Key_Esc)) { gameScene=MENUSCREEN; return; } else if ( cpct_isKeyPressed (Key_CursorUp) && option != 0) { --option; } else if ( cpct_isKeyPressed (Key_CursorDown) && option != 1) { ++option; } switch (option) { case 0: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(4, 9), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(4, 7), 4, 8); break; case 1: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(4, 7), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(4, 9), 4, 8); break; } cpct_scanKeyboard_f (); // waitNVSYNCs(5); } while (!cpct_isKeyPressed(Key_Return)); switch (option) { case 0: cpct_akp_stop(); gameScene=PLAYGAMESCREEN; break; case 1: cpct_akp_stop(); gameScene=NEXTLEVELSCREEN; break; } }
void activateMusic() { playing = 1; cpct_akp_stop(); cpct_akp_musicInit(song02); cpct_akp_SFXInit(song02); cpct_akp_musicPlay(); }
void deActivateMusic() { playing = 0; cpct_akp_stop(); cpct_akp_musicInit(song00); cpct_akp_SFXInit(song00); cpct_akp_musicPlay(); }
////////////////////////////////////////////////////////////////// // game // // // // Returns: // void // void game(void) { u8 moved; u8 *pvmem; u8 dir = 0; initGame(); // Clear Screen clearScreen(); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 61, 72); cpct_drawSprite(logo_small, pvmem, 15, 55); //drawFrame(2, 1, 49, 182); drawTable(); drawText("NEXT", 62, 2, 0); printCells(); highestCardGame = getHighestCard(); drawText("HIGHEST", 59, 138, 0); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 63, 154); cpct_drawSprite(cards[highestCardGame], pvmem, CARD_W, CARD_H); moved = 0; // Loop forever while (1) { delay(24); rotatedCells = 0; if ((cpct_isKeyPressed(Joy0_Right)) || (cpct_isKeyPressed(keys.right))) { if (rotateCellsRight() > 0) { dir = RIGHT; addRandomCellTurn(RIGHT); moved = 1; } } else if ((cpct_isKeyPressed(Joy0_Left)) || (cpct_isKeyPressed(keys.left))) { if (rotateCellsLeft() > 0) { dir = LEFT; addRandomCellTurn(LEFT); moved = 1; } } else if ((cpct_isKeyPressed(Joy0_Down)) || (cpct_isKeyPressed(keys.down))) { if (rotateCellsDown() > 0) { dir = DOWN; addRandomCellTurn(DOWN); moved = 1; } } else if ((cpct_isKeyPressed(Joy0_Up)) || (cpct_isKeyPressed(keys.up))) { if (rotateCellsUp() > 0) { dir = UP; addRandomCellTurn(UP); moved = 1; } } else if ( cpct_isKeyPressed(keys.music)) { if (!playing) { activateMusic(); } else { deActivateMusic(); } } else if (cpct_isKeyPressed(keys.abort)) break; if (moved) { //Empty the rotated cells buffer after ending the animation //cpct_waitVSYNC(); if (changedCards.number > 0) { animate(dir); resetChangedCards(); highestCardGame = getHighestCard(); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 63, 154); cpct_drawSprite(cards[highestCardGame], pvmem, CARD_W, CARD_H); // Play sound Effect cpct_akp_SFXPlay(3, 14, 50 + (highestCardGame * 2), 1, 0, AY_CHANNEL_A); } moved = 0; if (anyMovesLeft() == 0) { cpct_akp_stop(); cpct_akp_musicInit(song05); cpct_akp_musicPlay(); drawScore(); wait4UserKeypress(); drawFrame(14, 60, 68, 130); drawText("NO MORE MOVES", 20, 70, 1); drawText("GAME OVER", 22, 90, 1); sprintf(aux_txt, "SCORE %d", score); drawText(aux_txt, 22, 110, 1); delay(200); wait4UserKeypress(); setHighScore(score); drawScoreBoard(); cpct_akp_stop(); cpct_akp_musicInit(song02); cpct_akp_musicPlay(); break; } } } }
//////////////////////////////////////////////////////////////////////// // MAIN: Arkos Tracker Music Example // Keys: // * SPACE - Start / Stop Music // * 1 - Play a sound effect on Channel A // * 2 - Play a sound effect on Channel C // void main(void) { TKeyStatus k_space, k_0, k_1; // Status of the 3 Keys for this example (Space, 1, 2) u8 playing = 1; // Flag to know if music is playing or not u8 color = 1; // Color to draw charactes (normal / inverse) u8* pvideomem = CPCT_VMEM_START; // Pointer to video memory where next character will be drawn // All 3 keys are considered to be released at the start of the program k_space = k_0 = k_1 = K_RELEASED; // Initialize CPC cpct_disableFirmware(); // Disable firmware to prevent interaction cpct_setVideoMode(2); // Set Mode 2 (640x200, 2 colours) // Initialize the song to be played cpct_akp_musicInit(molusk_song); // Initialize the music cpct_akp_SFXInit(molusk_song); // Initialize instruments to be used for SFX (Same as music song) while (1) { // We have to call the play function 50 times per second (because the song is // designed at 50Hz). We only have to wait for VSYNC and call the play function // when the song is not stopped (still playing) cpct_waitVSYNC(); // Check if the music is playing. When it is, do all the things the music // requires to be done every 1/50 secs. if (playing) { cpct_akp_musicPlay(); // Play next music 1/50 step. // Write a new number to the screen to see something while playing. // The number will be 0 when music is playing, and 1 when it finishes. // -> If some SFX is playing write the channel where it is playing // Check if there is an instrument plaing on channel A if (cpct_akp_SFXGetInstrument(AY_CHANNEL_A)) cpct_drawCharM2(pvideomem, color, 'A'); // Write an 'A' because channel A is playing // Check if there is an instrument plaing on channel C else if (cpct_akp_SFXGetInstrument(AY_CHANNEL_C)) cpct_drawCharM2(pvideomem, color, 'C'); // Write an 'C' because channel A is playing // No SFX is playing on Channels A or C, write the number of times // this song has looped. else cpct_drawCharM2(pvideomem, color, '0' + cpct_akp_songLoopTimes); // Point to the start of the next character in video memory if (++pvideomem >= (u8*)0xC7D0) { pvideomem = CPCT_VMEM_START; // When we reach the end of the screen, we return.. color ^= 1; // .. to the start, and change the colour } // Check if music has already ended (when looptimes is > 0) if (cpct_akp_songLoopTimes > 0) cpct_akp_musicInit(molusk_song); // Song has ended, start it again and set loop to 0 } // Check keyboard to let the user play/stop the song with de Space Bar // and reproduce some sound effects with keys 1 and 0 cpct_scanKeyboard_f(); // When Space is released, stop / continue music if ( checkKeyEvent(Key_Space, &k_space) == K_RELEASED ) { // Only stop it when it was playing previously // No need to call "play" again when continuing, as the // change in "playing" status will make the program call "play" // again from the next cycle on if (playing) cpct_akp_stop(); // Change it from playing to not playing and viceversa (0 to 1, 1 to 0) playing ^= 1; // Check if Key 0 has been released to reproduce a Sound effect on channel A } else if ( checkKeyEvent(Key_0, &k_0) == K_RELEASED ) { cpct_akp_SFXPlay(13, 15, 36, 20, 0, AY_CHANNEL_A); // Check if Key 1 has been released to reproduce a Sound effect on channel C } else if ( checkKeyEvent(Key_1, &k_1) == K_RELEASED ) cpct_akp_SFXPlay(3, 15, 60, 0, 40, AY_CHANNEL_C); } }