void gameOver() { cpct_etm_setTileset2x4(g_tile_tileset_4); cpct_etm_drawTilemap2x4_f(MAP_WIDTH_TILES, MAP_HEIGHT_TILES, SCR_VMEM, g_backgroundGameOver); waitNVSYNCs(3000); gameScene=MENUSCREEN; }
void mainMenu() { 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 ("CONTROLS", getScreenPosition(5, 7), 15, 7); cpct_drawStringM0 ("CREDITS", getScreenPosition(5, 9), 15, 7); initScroll(); initPlayer(); cpct_scanKeyboard_f (); do { waitNVSYNCs(3); cpct_akp_musicPlay(); Road(); drawPlayer(); if ( cpct_isKeyPressed (Key_CursorUp) && option != 0) { --option; } else if ( cpct_isKeyPressed (Key_CursorDown) && option != 2) { ++option; } switch (option) { case 0: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 7), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(3, 5), 4, 8); break; case 1: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 5), 4, 8); cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 9), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(3, 7), 4, 8); break; case 2: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 7), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(3, 9), 4, 8); break; } cpct_scanKeyboard_f (); // waitNVSYNCs(5); } while (!cpct_isKeyPressed(Key_Return)); switch (option) { case 0: playMenu(); break; case 1: gameScene=CONTROLSSCREEN; break; case 2: gameScene=CREDITSSCEENE; break; } }
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; } }
//////////////////////////////////////////////////////////////////////////////////////// // MAIN PROGRAM: move a sprite over a background // void main(void) { // One alien that will move bouncing through the screen static const TAlien sa = {0, 0, 1, 1}; TAlien* a = (TAlien*)&sa; // Initialize screen, palette and background initialization(); // // Main loop: Moves the sprite left-to-right and vice-versa // while(1) { u8* pscra; // Pointer to the screen location to draw the alien // Check if sprite is going to got out the screen and produce bouncing in its case if (a->vx < 0) { if (a->tx < -a->vx) a->vx = 1; } else if (a->tx + a->vx + ALIEN_WIDTH_TILES >= MAP_WIDTH_TILES) a->vx = -1; if (a->vy < 0) { if (a->ty < -a->vy) a->vy = 1; } else if (a->ty + a->vy + ALIEN_HEIGHT_TILES >= MAP_HEIGHT_TILES) a->vy = -1; // Wait for VSYNC before drawing to the screen to reduce flickering // We also wait for several VSYNC to make it move slow, or it will be too fast waitNVSYNCs(2); // Redraw a tilebox over the alien to erase it (redrawing background over it) cpct_etm_drawTileBox2x4(a->tx, a->ty, ALIEN_WIDTH_TILES, ALIEN_HEIGHT_TILES, MAP_WIDTH_TILES, CPCT_VMEM_START, g_background); // Move the alien and calculate it's new location on screen a->tx += a->vx; a->ty += a->vy; pscra = cpct_getScreenPtr(CPCT_VMEM_START, TILEWIDTH_BYTES*a->tx, TILEHEIGHT_BYTES*a->ty); // Draw the alien in its new location cpct_drawSpriteMaskedAlignedTable(g_alien, pscra, ALIEN_WIDTH_BYTES, ALIEN_HEIGHT_BYTES, g_masktable); } }