////////////////////////////////////////////////////////////////// // checkKeyboardMenu // Checks the keyboard for the menu options // // // Returns: // void // void checkKeyboardMenu() { u8 *pvideo; delay(20); if (( cpct_isKeyPressed(Key_1)) || (((cpct_isKeyPressed(keys.fire) || (cpct_isKeyPressed(Joy0_Fire1))) && (selectedOption == 0)))) { drawMarker(); selectedOption = 0; drawMarker(); waitKeyUp(Key_1); keys.up = redefineKey("UP"); keys.down = redefineKey("DOWN"); keys.left = redefineKey("LEFT"); keys.right = redefineKey("RIGHT"); keys.fire = redefineKey("FIRE"); keys.pause = redefineKey("PAUSE"); keys.abort = redefineKey("ABORT"); //keys.music = redefineKey("MUSIC"); pvideo = cpct_getScreenPtr(CPCT_VMEM_START, 8, 154); cpct_drawSolidBox(pvideo, #0, 64, FONT_H); }
//////////////////////////////////////////////////////////////////////////////// // 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); }
// // MAIN: Using keyboard to move a sprite example // void initialize() { u8* pvideomem; // Pointer to video memory // Disable firmware to prevent it from interfering with setPalette and setVideoMode cpct_disableFirmware(); // Set up the hardware palette using hardware colour values cpct_setPalette(g_palette, 16); cpct_setBorder(HW_BLACK); // Set video mode 0 (160x200, 16 colours) cpct_setVideoMode(0); // Draw floor. As cpct_drawSolidBox cannot draw boxes wider than 63 bytes // and Screen width is 80 bytes, we draw 2 boxes of SCR_W/2 (40 bytes) each pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, 0, FLOOR_Y); cpct_drawSolidBox(pvideomem, FLOOR_COLOR, SCR_W/2, FLOOR_HEIGHT); pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, SCR_W/2, FLOOR_Y); cpct_drawSolidBox(pvideomem, FLOOR_COLOR, SCR_W/2, FLOOR_HEIGHT); // Draw instructions pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 20); cpct_drawStringM0(" Sprite Flip Demo ", pvideomem, 2, 0); pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 34); cpct_drawStringM0("[Cursor]", pvideomem, 4, 0); pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, 40, 34); cpct_drawStringM0("Left/Right", pvideomem, 3, 0); }
void drawMarker() { u8* pvmem; cpct_setBlendMode(CPCT_BLEND_XOR); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 25, 60 + (20 * selectedOption)); cpct_drawSpriteBlended(pvmem, IC_ICONS_0_H, IC_ICONS_0_W, ic_icons_0); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 70, 60 + (20 * selectedOption)); cpct_drawSpriteBlended(pvmem, IC_ICONS_1_H, IC_ICONS_1_W, ic_icons_1); }
void drawTable() { u8* pvmem; pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 2, 0); cpct_etm_drawTilemap2x4_f(MAP_WIDTH, MAP_HEIGHT, pvmem, tmx); }
// // Fills all the screen with sprites using drawTileAlignedXXX functions // void fillupScreen(TTile* tile) { u8 *pvideomem; // Pointer to the place where next tile will be drawn u8 x, y; // Loop counters for x and y screen tiles u8 tilesperline = 80/tile->width; // Number of tiles per line = LINEWIDTH / TILEWIDTH // Cover all the screen (200 pixels) with tiles for (y=0; y < 200; y += tile->height) { pvideomem = cpct_getScreenPtr((u8*)0xC000, 0, y); // Calculate byte there this pixel line starts // Draw all the tiles for this line for (x=0; x < tilesperline; x++) { // Select the appropriate function to draw the tile, and draw it switch (tile->function) { case _2x4Fast: cpct_drawTileAligned2x4_f(tile->sprite, pvideomem); break; case _4x4Fast: cpct_drawTileAligned4x4_f(tile->sprite, pvideomem); break; case _2x8Fast: cpct_drawTileAligned2x8_f(tile->sprite, pvideomem); break; case _2x8: cpct_drawTileAligned2x8 (tile->sprite, pvideomem); break; case _4x8Fast: cpct_drawTileAligned4x8_f(tile->sprite, pvideomem); break; case _4x8: cpct_drawTileAligned4x8 (tile->sprite, pvideomem); break; } // Increase video memory pointer by tile->width bytes (point to next tile's place) pvideomem += tile->width; } } }
///////////////////////////////////////////////////////////////// // initialize // Initialize this application when it starts. Disable firmware, // set the video mode and colours, and initialize map and cursor. // void initialize() { u8 *pmem; // Disable firmware to prevent it from restoring video mode or // interfering with our drawString functions cpct_disableFirmware(); // Set the video Mode to 1 (320x200, 4 colours) cpct_setVideoMode(1); // Use default colours except for palette index 0 (background). // Default colours are (Blue, Yellow, Cyan, Red), let's use // (Black, Yellow, Cyan, Red). Change only colour 0 and border. cpct_setPALColour(0, 0x14); cpct_setBorder(0x14); // Initialize Base Pointer of the map in video memory. This is // the place where the map will start to be drawn (0,0). This // location is (MAP_START_X, MAP_START_Y) with respect to CPCT_VMEM_START. pmem = cpct_getScreenPtr(CPCT_VMEM_START, MAP_START_X, MAP_START_Y); map_setBaseMem(pmem); // Set cursor at the top-left corner of the screen cursor_setLocation(0, 0); // Draw messages with instructions, the map and the cursor drawMessages(); map_draw(); cursor_draw(); }
////////////////////////////////////////////////////////////////// // 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(); }
/* CREDITOS */ void credits(){ u8* memptr; cpct_clearScreen(0); memptr = cpct_getScreenPtr(VMEM, 18, 30); cpct_drawStringM0("Grupo Pyxis", memptr, 1, 0); memptr = cpct_getScreenPtr(VMEM, 23, 60); cpct_drawStringM0("Miembros:", memptr, 1, 0); memptr = cpct_getScreenPtr(VMEM, 10, 80); cpct_drawStringM0("Alberto Martinez", memptr,2, 0); memptr = cpct_getScreenPtr(VMEM, 27, 95); cpct_drawStringM0("Martinez", memptr,2, 0); memptr = cpct_getScreenPtr(VMEM, 13, 115); cpct_drawStringM0("Josep Domenech", memptr,2, 0); memptr = cpct_getScreenPtr(VMEM, 27, 125); cpct_drawStringM0("Mingot", memptr, 2, 0); memptr = cpct_getScreenPtr(VMEM, 12, 175); cpct_drawStringM0("Pulsa espacio", memptr, 1, 0); while (1){ cpct_scanKeyboard_f(); if(cpct_isKeyPressed(Key_Space)) { return; } } }
/////////////////////////////////////////////////////////////////////////////////////////////////// // Update an entity (do animation, and change screen location) // Parameters: // c: Character to be updated // u8 updateCharacter(TCharacter *c) { TEntity *e = &c->entity; TPhysics *p = &e->phys; TAnimation *anim = &e->graph.anim; TAnimFrame *af = anim->frames[anim->frame_id]; u8 alive = 1; // Previous to calculations, next position is similar to current e->x = e->nx; e->y = e->ny; e->pscreen = e->npscreen; e->pw = af->width; e->ph = af->height; // Update animation. If changes sprite, then we should redraw if ( updateAnimation(&e->graph.anim, e->nAnim, e->nStatus) ) { e->draw = 1; // Redraw af = anim->frames[anim->frame_id]; // Get values of the new frame e->nAnim = 0; // No next animation/animstatus e->nStatus = as_null; } // Update physics and check collisions updateCharacterPhysics(c); applyCharacterBlockCollisions(c); // Maintain into limits if ( e->nx <= G_minX) { e->nx = G_minX + 1; p->x = e->nx * SCALE; } else if ( e->nx + af->width >= G_maxX ) { e->nx = G_maxX - af->width; p->x = e->nx * SCALE; } if ( e->ny + af->height >= G_maxY ) { e->ny = G_maxY - af->height; p->y = e->ny * SCALE; alive = 0; } else if ( e->ny <= G_minY ) { e->ny = G_minY + 1; p->y = e->ny * SCALE; } // Check if character has moved to calculate new location and set for drawing if ( e->ny != e->y ) { e->npscreen = cpct_getScreenPtr(CPCT_VMEM_START, e->nx, e->ny); e->draw = 1; } else if ( e->nx != e->x ) { e->npscreen = e->npscreen + e->nx - e->x; e->draw = 1; } return alive; }
/////////////////////////////////////////////////////////////////////////////////////////////////// // Moves a block // Parameters: // b_idx: Index of the block // Returns: // 1 if the moved block has been destroyed // 0 if not // u8 moveBlock(u8 b_idx) { TEntity *e = &g_blocks[b_idx]; // Get next block entity // u8 newY; // New calculated Y coordinate after movement // Update block location acording to its Y physics e->phys.y += G_scrollVel; // All blocks use this same velocity for Y axis e->y = e->ny; e->ny = e->phys.y / SCALE; // Check if we have to move the block graphically if (e->ny != e->y) { // Check if the block has disappeared from the screen, to destroy it // Beware! Destroying a block moves all the rest in the array! if (e->ny > G_maxY) { destroyBlock(b_idx); return 1; // Return informing that the block has been destroyed! } e->draw = 1; } // Update block location according to its X physics if (e->phys.vx) { e->x = e->nx; e->phys.x += e->phys.vx; e->nx = e->phys.x / SCALE; // Is there any graphical movement? if (e->x != e->nx) { // Maintain into limits if (e->nx < G_minX) { // Crossed left boundary, bounce right e->nx = G_minX + 1; e->phys.x = e->nx * SCALE; e->phys.vx = -e->phys.vx; } else if ( e->nx + e->graph.block.w >= G_maxX ) { // Crossed right boundary, bounce left e->nx = G_maxX - e->graph.block.w; e->phys.x = e->nx * SCALE; e->phys.vx = -e->phys.vx; } e->draw = 1; // Set for redraw } } // Calculate new screen position, on draw if (e->draw) { e->pscreen = e->npscreen; e->npscreen = cpct_getScreenPtr(CPCT_VMEM_START, e->nx, e->ny); } // Return signalling that the block has NOT been destroyed return 0; }
/*MENU*/ int menu(){ u8* memptr; int init = 50; int pushed =0; int cont =0; cpct_clearScreen(0); memptr = cpct_getScreenPtr(VMEM,10,10); cpct_drawSprite(portada1,memptr,60,60); //Opciones memptr = cpct_getScreenPtr(VMEM,20,90); cpct_drawStringM0("Nueva Partida",memptr,1,0); memptr = cpct_getScreenPtr(VMEM,20,110); cpct_drawStringM0("Creditos",memptr,1,0); memptr = cpct_getScreenPtr(VMEM,20,130); cpct_drawStringM0("Constroles",memptr,1,0); memptr = cpct_getScreenPtr(VMEM,20,150); cpct_drawStringM0("Salir",memptr,1,0); /*memptr = cpct_getScreenPtr(VMEM,18,180); cpct_drawStringM0("Pulsa Intro",memptr,4,5);*/ //Indicador while(1){ cpct_scanKeyboard(); if(cpct_isKeyPressed(Key_CursorDown) && cont > 150){ cpct_drawSolidBox(memptr, 0, 2, 8); if(pushed<3) pushed ++; cont =0; } if(cpct_isKeyPressed(Key_CursorUp) && cont > 150){ cpct_drawSolidBox(memptr, 0, 2, 8); if(pushed>0) pushed --; cont = 0; } switch (pushed){ case 0: init = 90;break; case 1: init = 110;break; case 2: init = 130;break; case 3: init = 150;break; } memptr = cpct_getScreenPtr(VMEM,15,init); cpct_drawSprite(marcador,memptr, 2, 8); if(cpct_isKeyPressed(Key_Space)){ switch (pushed){ case 0: return 1;break; case 1: return 2;break; case 2: return 3;break; case 3: return 0;break; } } cont++; } }
/* Controles */ void controles(){ u8* memptr; cpct_clearScreen(0); memptr = cpct_getScreenPtr(VMEM, 23, 60); cpct_drawStringM0("Controles:", memptr, 1, 0); memptr = cpct_getScreenPtr(VMEM, 11, 80); cpct_drawStringM0("Movimiento: ", memptr, 2, 0); memptr = cpct_getScreenPtr(VMEM, 27, 95); cpct_drawStringM0("Flechas", memptr, 2, 0); memptr = cpct_getScreenPtr(VMEM, 13, 115); cpct_drawStringM0("Esc: Menu", memptr, 2, 0); memptr = cpct_getScreenPtr(VMEM, 13, 130); cpct_drawStringM0("Disparar: X", memptr, 2, 0); memptr = cpct_getScreenPtr(VMEM, 12, 175); cpct_drawStringM0("Pulsa espacio", memptr, 1, 0); while (1){ cpct_scanKeyboard_f(); if(cpct_isKeyPressed(Key_Space)) { return; } } }
///////////////////////////////////////////////////////////////// // drawTile // Draws only one of the tiles of the map, given its coordinates. // It calculates the location in the screen of the given tile and // gets its actual value from the map array. Then it draws the // tile to the screen. // void map_drawTile(u8 x, u8 y) { // Calculate screen location where tile should be drawn u8 *pmem = cpct_getScreenPtr(map_base_location, x, y*TILE_HEIGHT); // Select appropriate colour pattern for the tile // (YELLOW for walls, BLACK for background) u8 c_pattern = cpct_px2byteM1(C_BLACK, C_BLACK, C_BLACK, C_BLACK); if (map_getTile(x, y) != 0) c_pattern = cpct_px2byteM1(C_YELLOW, C_YELLOW, C_YELLOW, C_YELLOW); // Draw the tile as a solid box cpct_drawSolidBox(pmem, c_pattern, TILE_WIDTH, TILE_HEIGHT); }
//////////////////////////////////////////////////////////////////////////////////////////////// // Draw a frame around play area, using frame tiles. // pscr: Pointer to the upper-left corner of the screen / buffer where frame is to be drawn // x: X coordinate where the frame starts // void drawFrame(u8* pscr, u8 x) { u8 *pvmem; // Pointer to video memory (used for drawing tiles) u8 i; // Counter for loops //------ Draw Up-Left and Up-Right Corners pvmem = cpct_getScreenPtr(pscr, x, 0); cpct_drawTileAligned4x8(G_frameUpLeftCorner, pvmem); // Up-Left cpct_drawTileAligned4x8(G_frameUpRightCorner, pvmem + 54); // Up-Right //------ Draw left and right borders for(i=8; i < 192; i += 8) { pvmem = cpct_getScreenPtr(pscr, x, i); cpct_drawTileAligned4x8(G_frameLeft, pvmem); // Left border cpct_drawTileAligned4x8(G_frameRight, pvmem + 54); // Right border } //------ Draw upper border pvmem = cpct_getScreenPtr(pscr, x, 0); for(i=4; i < 28; i += 4) { pvmem += 4; cpct_drawTileAligned4x8(G_frameUp, pvmem); // Left part cpct_drawTileAligned4x8(G_frameUp, pvmem + 26); // Right part } cpct_drawSprite(G_frameUpCenter, pvmem + 2, 6, 8); // Central tile //------ Draw down border pvmem = cpct_getScreenPtr(pscr, x, 192); for(i=4; i < 28; i += 4) { pvmem += 4; cpct_drawTileAligned4x8(G_frameDown, pvmem); // Left part cpct_drawTileAligned4x8(G_frameDown, pvmem + 26); // Right part } cpct_drawSprite(G_frameDownCenter, pvmem + 2, 6, 8); // Central tile //------ Draw Down-Left and Down-Right Corners pvmem = cpct_getScreenPtr(pscr, x, 192); cpct_drawTileAligned4x8(G_frameDownLeftCorner, pvmem); // Down-Left cpct_drawTileAligned4x8(G_frameDownRightCorner, pvmem + 54); // Down-Right }
void printCells() { u8 i; u8 j; u8 x; u8 y; u8* pvmem; // Pointer to video memory for (i = 0; i < 4; i++) { //y = 30 + (i * 10); y = 4 + (i * 48); for (j = 0; j < 4; j++) { // x = 3 + (j * 12); x = 6 + (j * 12); if (cells[i][j] > 0) { pvmem = cpct_getScreenPtr(CPCT_VMEM_START, x, y); cpct_drawSpriteMaskedAlignedTable(cards[cells[i][j]], pvmem, CARD_W, CARD_H, am_tablatrans); } } } pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 63, 18); cpct_drawSprite(cards[cardBag[currentCard]], pvmem, CARD_W, CARD_H); }
//////////////////////////////////////////////////////////////////////////////// // Shows messages at the end of the game and asks for keypress for starting again // void showGameEnd(u16 score) { u8* pscr; // Pointer to the screen place where to show messages u8 str[6]; // String array to draw numbers on screen // Draw GAME OVER string pscr = cpct_getScreenPtr(CPCT_VMEM_START, 8, 24); cpct_drawStringM0("GAME OVER", pscr, 6, 0); // Draw SCORE string pscr = cpct_getScreenPtr(CPCT_VMEM_START, 16, 48); cpct_drawStringM0( "SCORE", pscr, 9, 0); // Draw the score got in this game pscr = cpct_getScreenPtr(CPCT_VMEM_START, 16, 56); sprintf(str, "%5u", score); cpct_drawStringM0(str, pscr, 14, 0); // Draw PRESS SPACE string pscr = cpct_getScreenPtr(CPCT_VMEM_START, 6, 112); cpct_drawStringM0("PRESS SPACE", pscr, 11, 0); // Wait for SPACE being pressed before continuing wait4Key(Key_Space); }
// // Draw CPCtelera's Squared Banner (Mode 0) // void drawBanner() { // Video memory pointers for the 2 sprites that form the Squared banner u8 *pvideo_s1, *pvideo_s2; // Clear the screen filling it up with 0's cpct_clearScreen_f64(0); // Set Mode 0 Squared Banner palette and change to Mode 0 cpct_setPalette (G_banner_palette, 16); cpct_setVideoMode(0); // Draw CPCtelera's Squared Banner in 2 parts of 80x96 pixels (40x96 bytes in mode 0) // We have to draw it in two parts because cpct_drawSprite function cannot // draw sprites wider than 63 bytes. // Remember: in Mode 0, 1 byte = 2 pixels // Draw left part at screen byte coordinates ( 0, 52) (pixel coordinates ( 0, 52)) pvideo_s1 = cpct_getScreenPtr(SCR_VMEM, 0, 52); cpct_drawSprite(G_CPCt_left, pvideo_s1, BANNER_W, BANNER_H); // Draw right part at screen byte coordinates (40, 52) (pixel coordinates (80, 52)) pvideo_s2 = cpct_getScreenPtr(SCR_VMEM, 40, 52); cpct_drawSprite(G_CPCt_right, pvideo_s2, BANNER_W, BANNER_H); }
/*GAME OVER*/ void gameOver(){ u8* memptr; cpct_clearScreen(0); memptr = cpct_getScreenPtr(VMEM,10,10); cpct_drawStringM0("Lounge Gladiator",memptr,1,0); memptr = cpct_getScreenPtr(VMEM,10,50); cpct_drawSprite(gameover,memptr,60,28); memptr = cpct_getScreenPtr(VMEM, 12, 175); cpct_drawStringM0("Pulsa espacio", memptr, 1, 0); while (1){ cpct_scanKeyboard_f(); if(cpct_isKeyPressed(Key_Space)) { return; } } }
// // Draw CPCtelera's Logo (Mode 1) // void drawLogo() { // Pointer to video memory location where the logo will be drawn u8* pvideo; // Clear the screen filling it up with 0's cpct_clearScreen_f64(0); // Set Mode 1 Logo palette and change to Mode 1 cpct_setPalette(G_logo_palette, 4); cpct_setVideoMode(1); // Draw CPCtelera's Logo as one unique sprite 160x191 pixels (40x191 bytes in mode 1) // Remember: in Mode 1, 1 byte = 4 pixels // Draw the sprite at screen byte coordinates (20, 4) (pixel coordinates (80, 4)) pvideo = cpct_getScreenPtr(SCR_VMEM, 20, 4); cpct_drawSprite(G_CPCt_logo, pvideo, LOGO_W, LOGO_H); }
//////////////////////////////////////////////////////////////////////////////////////// // 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); } }
///////////////////////////////////////////////////////////////// // draw // Draws the map completely. It displays a message down the // screen while drawing to inform the user. // void map_draw() { static u8* const string = "Drawing Map"; u8 x, y; u8* pmem; // Draw a message down the screen to inform the user // that the map is drawing pmem = cpct_getScreenPtr(CPCT_VMEM_START, 30, 160); cpct_drawStringM1(string, pmem, C_BLACK, C_RED); // Draw the map tile by tile for(y=0; y < MAP_HEIGHT; y++) for(x=0; x < MAP_WIDTH; x++) map_drawTile(x, y); // Remove the message that was informing the user // (Drawing the string with background colour) cpct_drawStringM1(string, pmem, C_BLACK, C_BLACK); }
/////////////////////////////////////////////////////////////////////////////////////////////////// // Sets up a new location for an entity in screen (and its velocity) // Parameters give information in screen coordinates and values // void setEntityLocation(TEntity *e, u8 x, u8 y, u8 vx, u8 vy, u8 eraseprev) { // Locate entity on screen e->npscreen = cpct_getScreenPtr(CPCT_VMEM_START, x, y); e->nx = x; e->ny = y; // Locate entity on the physics world (with integer arithmetic) e->phys.x = x * SCALE; e->phys.y = y * SCALE; e->phys.vx = vx * SCALE; e->phys.vy = vy * SCALE; // Make previous values of the entity equal to next if (eraseprev) { e->pscreen = e->npscreen; e->x = x; e->y = y; } }
// // MAIN: Using keyboard to move a sprite example // void main(void) { u8 x=20; // Sprite horizontal coordinate u8 lookingAt = LOOK_RIGHT; // Know where the sprite is looking at u8 nowLookingAt = lookingAt; // New looking direction after keypress // Initialize the Amstrad CPC initialize(); // // Infinite moving loop // while(1) { u8* pvideomem; // Pointer to video memory // Scan Keyboard (fastest routine) // The Keyboard has to be scanned to obtain pressed / not pressed status of // every key before checking each individual key's status. cpct_scanKeyboard_f(); // Check if user has pressed a Cursor Key and, if so, move the sprite if // it will still be inside screen boundaries if (cpct_isKeyPressed(Key_CursorRight) && x < (SCR_W - SP_W) ) { ++x; nowLookingAt = LOOK_RIGHT; } else if (cpct_isKeyPressed(Key_CursorLeft) && x > 0) { --x; nowLookingAt = LOOK_LEFT; } // Check if we have changed looking direction if (lookingAt != nowLookingAt) { lookingAt = nowLookingAt; cpct_hflipSpriteM0(SP_W, SP_H, g_spirit); } // Get video memory byte for coordinates x, y of the sprite (in bytes) pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, x, FLOOR_Y - SP_H); // Draw the sprite in the video memory location got from coordinates x, y cpct_drawSprite(g_spirit, pvideomem, SP_W, SP_H); } }
///////////////////////////////////////////////////////////////////////////////// // Draws the tilemap in a new location or with a change in its viewport. // The drawing is done in the backbuffer and then shown in the screen when it's // done, switching screen buffers just after the VSYNC // void drawScreenTilemap(TScreenTilemap *scr) { u8* ptmscr; // Backbuffer pointer where the tilemap is to be drawn // Clear the backbuffer cpct_memset_f64(g_scrbuffers[1], 0x00, 0x4000); // Calculate the new location where the tilemap is to be drawn in // the backbuffer, using x, y coordinates of the tilemap ptmscr = cpct_getScreenPtr(g_scrbuffers[1], scr->x, scr->y); // Draw the viewport of the tilemap in the backbuffer (pointed by ptmscr) cpct_etm_drawTileBox2x4(scr->viewport.x, scr->viewport.y, scr->viewport.w, scr->viewport.h, MAP_WIDTH, ptmscr, g_tilemap); // Wait for VSYNC and change screen buffers just afterwards, // to make the backbuffer show on the screen cpct_waitVSYNC(); swapBuffers(g_scrbuffers); }
// // MAIN: Using keyboard to move a sprite example // void main(void) { u8 x=10, y=10; // Sprite coordinates u8* pvideomem; // Pointer to video memory // // Set up the screen // // Disable firmware to prevent it from interfering with setPalette and setVideoMode cpct_disableFirmware(); // Set the colour palette cpct_fw2hw (G_palette, 4); // Convert our palette from firmware to hardware colours cpct_setPalette(G_palette, 4); // Set up the hardware palette using hardware colours // Set video mode 1 (320x200, 4 colours) cpct_setVideoMode(1); // // Infinite moving loop // while(1) { // Scan Keyboard (fastest routine) // The Keyboard has to be scanned to obtain pressed / not pressed status of // every key before checking each individual key's status. cpct_scanKeyboard_f(); // Check if user has pressed a Cursor Key and, if so, move the sprite if // it will still be inside screen boundaries if (cpct_isKeyPressed(Key_CursorRight) && x < (SCR_W - SP_W) ) ++x; else if (cpct_isKeyPressed(Key_CursorLeft) && x > 0 ) --x; if (cpct_isKeyPressed(Key_CursorUp) && y > 0 ) --y; else if (cpct_isKeyPressed(Key_CursorDown) && y < (SCR_H - SP_H) ) ++y; // Get video memory byte for coordinates x, y of the sprite (in bytes) pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, x, y); // Draw the sprite in the video memory location got from coordinates x, y cpct_drawSprite(G_spriteLogoCT, pvideomem, SP_W, SP_H); } }
///////////////////////////////////////////////////////////////////////////////// // Scrolls the tilemap, relocates pointers and draws left and right columns // with their new content after scrolling // void scrollScreenTilemap(TScreenTilemap *scr, i16 scroll) { // Select leftmost or rightmost column of the tilemap to be redrawn // depending on the direction of the scrolling movement made u8 column = (scroll > 0) ? (SCR_TILE_WIDTH-1) : (0); // Update pointers to tilemap drawable window, tilemap upper-left corner in video memory // and scroll offset scr->pVideo += 2*scroll; // Video memory starts now 2 bytes to the left or to the right scr->pTilemap += scroll; // Move the start pointer to the tilemap 1 tile (1 byte) to point to the drawable zone (viewport) scr->scroll += scroll; // Update scroll offset to produce scrolling // Wait for VSYNC before redrawing, cpct_waitVSYNC(); // Do hardware scrolling to the present offset cpct_setVideoMemoryOffset(scr->scroll); // Redraw newly appearing column (either it is left or right) cpct_etm_drawTileBox2x4(column, 0, // (X, Y) Upper-left Location of the Box (column in this case) to be redrawn 1, MAP_HEIGHT, // (Width, Height) of the Box (column) to be redrawn MAP_WIDTH, // Width of the full tilemap (which is wider than the screen in this case) scr->pVideo, // Pointer to the upper-left corner of the tilemap in video memory scr->pTilemap); // Pointer to the first tile of the tilemap to be drawn (upper-left corner // ... of the tilemap viewport window) // When scrolling to the right, erase the character (2x8) bytes that scrolls-out // through the top-left corner of the screen. Othewise, this pixel values will // loop and appear through the bottom-down corner later on. // When scrolling to the left, erase the character that appears on the left, just // below the visible tilemap if (scroll > 0) cpct_drawSolidBox(scr->pVideo - 2, 0, 2, 8); // top-left scrolled-out char else { u8* br_char = cpct_getScreenPtr(scr->pVideo, 0, 4*MAP_HEIGHT); cpct_drawSolidBox(br_char, 0, 2, 8); // bottom-right scrolled-out char } }
void drawMessages() { u8 i; // Define the strings for the messages as an array to // be able to draw them in a single loop static u8* const strings[NUM_MSGS] = { "[Cursors]" ,"Move" ,"[Space]" ,"Draw/Remove" ,"[Escape]" ,"Clear" }; // Define the properties of the messages that will be drawn: // (x,y) location, Foreground colour (fg) and Background Colour (bg) static const u8 msg_prop[NUM_MSGS][4] = { // x, y, fg, bg //---------------------------- { 20, 0, C_RED , C_BLACK }, // Message 0 { 40, 0, C_BLUE, C_BLACK }, // Message 1 { 20, 16, C_RED , C_BLACK }, // Message 2 { 40, 16, C_BLUE, C_BLACK }, // Message 3 { 20, 32, C_RED , C_BLACK }, // Message 4 { 40, 32, C_BLUE, C_BLACK } // Message 5 }; // Draw all messages in a single loop, using propertis of each message for(i=0; i < NUM_MSGS; i++) { u8* pmem; // Get Location where next message should be drawn using // message properties 0 and 1 (x and y coordinates) pmem = cpct_getScreenPtr(CPCT_VMEM_START, msg_prop[i][0], msg_prop[i][1]); // Draw the i-th message with colours from its properties 2 and 3 (fg, bg) cpct_drawStringM1(strings[i], pmem, msg_prop[i][2], msg_prop[i][3]); } }
/////////////////////////////////////////////////////////////////////////////////////////////////// // Draw a given animated entity on the screen // void drawBlockEntity (TEntity* e){ // Check if needs to be redrawn if ( e->draw ) { u8* sp; // Starting video mem pointer for blocks that are in the upper non-visible zone u8 eraseh;// height to be erased u8 drawh;// Height to draw of the box (taking into account invisible zones) // Get the entity values from its current animation status TBlock* block = &e->graph.block; // Take into account non visible zones for drawing the blocks sp = e->npscreen; if (e->ny <= G_minY) { drawh = block->h + e->ny - G_minY; sp = cpct_getScreenPtr(CPCT_VMEM_START, e->nx, G_minY); } else { if (e->ny + block->h > G_maxY) { drawh = G_maxY - e->ny; eraseh = G_maxY - e->y; } else { drawh = block->h; eraseh = drawh; } // Remove previous entity if (eraseh) cpct_drawSolidBox(e->pscreen, 0x00, block->w, eraseh); } // Draw the entity if (drawh) cpct_drawSolidBox(sp, block->colour, block->w, drawh); e->draw = 0; } }
void getName() { u8* pvmem; u8 moved, pos, chr; u8 markerX, markerY; drawFrame(9, 60, 73, 150); drawText("NEW HIGH SCORE", 20, 70, 1); drawText("ENTER YOUR NAME", 18, 85, 1); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 11, 100); cpct_drawSprite(g_tile_symbols_1, pvmem, 3, 11); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 14, 100); cpct_drawSprite(g_tile_symbols_2, pvmem, 3, 11); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 17, 100); cpct_drawSprite(g_tile_symbols_3, pvmem, 3, 11); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 20, 100); cpct_drawSprite(g_tile_symbols_4, pvmem, 3, 11); drawText("CHANGE LETTER", 24, 100, 0); drawText(" _ TO END", 20, 115, 1); drawFrame(12, 130, 70, 160); strcpy(newNameHighScore, "A"); drawText(newNameHighScore, 16, 140, 0); markerX = 15; markerY = 138; cpct_setBlendMode(CPCT_BLEND_XOR); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, markerX, markerY); cpct_drawSpriteBlended(pvmem, AM_MARKER_H, AM_MARKER_W, am_marker); pos = 0; chr = 65; moved = 0; while (1) { delay(24); if ((cpct_isKeyPressed(Joy0_Down)) || (cpct_isKeyPressed(keys.down))) { chr++; moved = 1; } else if ((cpct_isKeyPressed(Joy0_Up)) || (cpct_isKeyPressed(keys.up))) { chr--; moved = 1; } else if ((pos < 14) && ((cpct_isKeyPressed(Joy0_Right)) || (cpct_isKeyPressed(Joy0_Fire1)) || (cpct_isKeyPressed(keys.right)))) { if (chr == 95) { newNameHighScore[pos] = '\0'; break; } else { pos++; newNameHighScore[pos] = 65; newNameHighScore[pos + 1] = '\0'; chr = 65; moved = 1; } } else if ((pos > 0) && ((cpct_isKeyPressed(Joy0_Left)) || (cpct_isKeyPressed(keys.left)))) { newNameHighScore[pos] = '\0'; pos--; chr = newNameHighScore[pos]; moved = 1; } else if (cpct_isKeyPressed(keys.abort)) { break; } if (moved) { moved = 0; if (chr > 95) chr = 65; else if (chr < 65) chr = 95; newNameHighScore[pos] = chr; pvmem = cpct_getScreenPtr(CPCT_VMEM_START, markerX, markerY); cpct_drawSpriteBlended(pvmem, AM_MARKER_H, AM_MARKER_W, am_marker); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 16, 140); cpct_drawSolidBox(pvmem, #0, 45, 11); drawText(newNameHighScore, 16, 140, 0); markerX = 15 + (pos * 3); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, markerX, markerY); cpct_drawSpriteBlended(pvmem, AM_MARKER_H, AM_MARKER_W, am_marker); } } }