////////////////////////////////////////////////////////////////////////////// // MAIN: code execution starts here // Initializes buffers at 0x4000 and 0xC000 and goes switching between // both of them on keypresses // void main(void) { u8 scr = 0; // Video buffer selector: selects what is to be shown on the screen u16 pattern; // Will contain a 4 pixel-colour pattern // First, Initialize the CPC initializeCPC(); // Construct a color pattern with 4 consecutive pixels of 4 different // colours in mode 0, that will be used to fill up the second buffer pattern = ( cpct_px2byteM0(4, 6) << 8 ) | cpct_px2byteM0(8, 9); // Second, Set up the 0x4000 video buffer. This set up will erase // all code placed in the 0x4000 area that has already been used // for initializing the CPC. Therefore, this code will have been // used one and then replaced to gain some space. setUpVideoBuffer(VMEM_1, pattern, "0x4000 Screen Buffer", 0, 6); // Main Loop while (1) { // Wait for VSYNC and show pressently // selected video buffer in the screen cpct_waitVSYNC(); cpct_setVideoMemoryPage(g_buffers[scr]); // Sets the memory page that will be shown on screen // Select the alternate video buffer and wait // for a keypress to change what is being shown on screen scr = scr ^ 0x01; // Does operation scr XOR 1, which alternates the value of the last bit of scr, // ... so that it alternates between 0 and 1. wait4KeyPress(); } }
void drawScoreBoard() { u8 i; u32 c = 0; cpct_waitVSYNC(); cpct_memset(CPCT_VMEM_START, cpct_px2byteM0(0, 0), 0x4000); drawText("AMSTHREES SCOREBOARD", 13, 2, 1); for (i = 0; i < 8; i++) { drawNumber(i + 1, 2, 5, 30 + (i * 15)); drawText(nameHallOfFame[i], 14, 30 + (i * 15), 0); drawNumber(scoreHallOfFame[i], 1, 69, 30 + (i * 15)); } drawText("JOHN LOBO", 25, 170, 1); drawText("@ GLASNOST CORP 2016", 11, 185, 1); c = 40000; // Number of loops passed if not keypressed // Wait 'till the user presses a key, counting loop iterations do { c--; // One more cycle cpct_scanKeyboard_f(); // Scan the keyboard } while (( ! cpct_isAnyKeyPressed_f() ) && c > 0); //delay(2000); }
//////////////////////////////////////////////////////////////////////////////// // Initializes elements of the screen on the initialization of a new game // void initializeGameScreen(u16 hiscore) { u8* pscr; // Pointer to the screen location where we want to draw u8 c; // Colour pattern to draw u8 str[6]; // Score // Clear the screen cpct_clearScreen(0); // // Draw backgrounds and Hi-Score // c = cpct_px2byteM0(8,8); // Colour pattern 8-8 (black-black) // Draw black background for scoreboard pscr = cpct_getScreenPtr(CPCT_VMEM_START, 54, 0); cpct_drawSolidBox(pscr, c, 26, 200); // Draw "HI" string pscr = cpct_getScreenPtr(CPCT_VMEM_START, 60, 16); cpct_drawStringM0("HI", pscr, 3, 8); // Draw HI-Score pscr = cpct_getScreenPtr(CPCT_VMEM_START, 60, 24); sprintf(str, "%5u", hiscore); cpct_drawStringM0(str, pscr, 15, 8); // Draw Credits pscr = cpct_getScreenPtr(CPCT_VMEM_START, 60, 172); cpct_drawSprite(G_credits, pscr, 20, 27); // Draw tiled frame around playing area drawFrame(CPCT_VMEM_START, 0); }
u8 randomCreateNewBlock(u8 y, u8 h, u8 rndinc) { u8 last_y = g_blocks[g_lastBlock-1].ny; // y coordinate of the upmost block u8 created = 0; // Flag to signal if a new block was created // If there is enough pixel space, create a random number (0-31) and, // if it is less than last_y (18...31), create a new platform if ( (RAND_0_15(1) + MINPIXELSPACE) < last_y ) { u8 w; // Random Width for the new block u8 x = G_minX + RAND_0_63(1); // Random X for the new block // If random x is out of range, modularize it to set it on range if (x >= G_maxX - 1) x = x - G_maxX + G_minX; // Create random width for the new platform (4..19) w = RAND_0_15(rndinc) + 4; // If rightmost pixel of the new block exceedes range, // adjust it to the limits if (x + w > G_maxX) w = G_maxX - x; // Create the new solid block (if there is enough space) if ( newSolidBlock(x, y, w, h, cpct_px2byteM0(G_platfColour, G_platfColour)) ) created = 1; } return created; }
/////////////////////////////////////////////////////////////////////////////////////////////////// // Initialize entities // Sets up entities at their initial values // void initializeEntities() { TPhysics *p = ((TPhysics*)&g_Character.entity.phys); G_platfColour = cpct_px2byteM0(8, 8); G_scrollVel = 3 * SCALE / FPS; // Scroll down velocity, 3 px/sec g_movingBlocks = 0; // Initialize blocks g_lastBlock = 0; // Block ID newSolidBlock( 4, 120, 50, 5, G_platfColour); // 0 / newSolidBlock(14, 100, 10, 3, G_platfColour); // 1 / newSolidBlock(34, 100, 10, 3, G_platfColour); // 2 / newSolidBlock(26, 80, 6, 3, G_platfColour); // 3 / newSolidBlock( 8, 60, 10, 3, G_platfColour); // 4 / newSolidBlock(36, 55, 10, 3, G_platfColour); // 5 / newSolidBlock(20, 30, 20, 3, G_platfColour); // 6 / newSolidBlock( 9, 10, 10, 3, G_platfColour); // 7 / newSolidBlock(44, 9, 4, 3, G_platfColour); // 8 / G_score = 9; // 9 points for the 9 starting blocks G_platfColour = 8; // Initialize main character setEntityLocation(&g_Character.entity, 28, 120-20, 0, 0, 1); // Define initial collition range g_colMinBlock = 0; g_colMaxBlock = 2; }
////////////////////////////////////////////////////////////////// // drawMenu // // // // Returns: // void // void drawMenu() { u8* pvmem; cpct_waitVSYNC(); cpct_memset(CPCT_VMEM_START, cpct_px2byteM0(0, 0), 0x4000); //Small Logo pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 23, 0); cpct_drawSprite(logo_micro, pvmem, 5, 18); drawText("AMSTHREES", 30, 4, 0); // Session Highest Card drawText("SESSION", 1, 57, 0); drawText("HIGH", 5, 72, 0); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 7, 92); cpct_drawSprite(cards[highestCardAll], pvmem, CARD_W, CARD_H); drawFrame(23, 43, 76, 151); //Camelot Mode Badgae if (camelotMode) { pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 80 - G_CAMELOTBADGE_W, 8); cpct_drawSpriteMaskedAlignedTable(g_camelotBadge, pvmem, G_CAMELOTBADGE_W, G_CAMELOTBADGE_H, am_tablatrans); } drawText("REDEFINE", 38, 60, 0); drawText("MUSIC", 38, 80, 0); if (playing) drawText("OFF", 56, 80, 0); else drawText("ON", 56, 80, 0); drawText("HELP", 38, 100, 0); drawText("PLAY", 38, 120, 0); drawNumber(1, 1, 31, 60); drawNumber(2, 1, 31, 80); drawNumber(3, 1, 31, 100); drawNumber(4, 1, 31, 120); drawText("JOHN LOBO", 25, 170, 1); drawText("@ GLASNOST CORP 2016", 11, 185, 1); drawMarker(); }