/*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++; } }
// // 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); }
//////////////////////////////////////////////////////////////////////////////// // 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); }
///////////////////////////////////////////////////////////////// // 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); }
///////////////////////////////////////////////////////////////////////////////// // 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 } }
/////////////////////////////////////////////////////////////////////////////////////////////////// // 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; } }
/////////////////////////////////////////////////////////////////////////////////////////////////// // Draw a given animated entity on the screen // void drawAnimEntity (TEntity* e) { // Check if needs to be redrawn if ( e->draw ) { // Get the entity values from its current animation status TAnimation* anim = &e->graph.anim; TAnimFrame* frame = anim->frames[anim->frame_id]; // Remove trails cpct_drawSolidBox(e->pscreen, 0x00, e->pw, e->ph); // Draw the entity cpct_drawSprite(frame->sprite, e->npscreen, frame->width, frame->height); e->draw = 0; } }
// This example is built at 0x8000, so we can page at 0x4000. // See the build configuration. void main(void) { u8* pvmem; // Pointer to video memory u8* firstByteInPage = (u8*) 0x4000; u8 i; cpct_pageMemory(RAMCFG_0 | BANK_0); // Not needed, sets the memory with the first 64kb accesible, in consecutive banks. // firstByteInPage point to address 0x4000. With this memory // configuration, that is physical address 0x4000. *firstByteInPage = cpct_px2byteM1(1, 1, 1, 1); // Set the first byte in page to all pixels with colour 1 (yellow by default). cpct_pageMemory(RAMCFG_4 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF // RAMCFG_4: 0000-3FFF -> RAM_0, 4000-7FFF -> RAM_4, 8000-BFFF -> RAM_2, C000-FFFF -> RAM_3 // firstByteInPage point to address 0x4000. With this memory // configuration, 0x4000 is the first byte in BANK_0, RAM_4, // which is physical address 0x10000. *firstByteInPage = cpct_px2byteM1(2, 2, 2, 2); // Set the first byte in page to all pixels with colour 2 (cyan by default ). cpct_pageMemory(RAMCFG_5 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF // RAMCFG_5: 0000-3FFF -> RAM_0, 4000-7FFF -> RAM_5, 8000-BFFF -> RAM_2, C000-FFFF -> RAM_3 // firstByteInPage point to address 0x4000. With this memory // configuration, 0x4000 is the first byte in BANK_0, RAM_5, // which is physical address 0x14000. *firstByteInPage = cpct_px2byteM1(3, 3, 3, 3); // Set the first byte in page to all pixels with colour 3 (red by default ). cpct_pageMemory(RAMCFG_6 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF // RAMCFG_6: 0000-3FFF -> RAM_0, 4000-7FFF -> RAM_6, 8000-BFFF -> RAM_2, C000-FFFF -> RAM_3 // firstByteInPage point to address 0x4000. With this memory // configuration, 0x4000 is the first byte in BANK_0, RAM_6, // which is physical address 0x18000. *firstByteInPage = cpct_px2byteM1(1, 1, 2, 2); // Set the first byte in page to all pixels with colours 1, 2 (yellow, cyan by default ). cpct_pageMemory(RAMCFG_7 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF // RAMCFG_7: 0000-3FFF -> RAM_0, 4000-7FFF -> RAM_7, 8000-BFFF -> RAM_2, C000-FFFF -> RAM_3 // firstByteInPage point to address 0x4000. With this memory // configuration, 0x4000 is the first byte in BANK_0, RAM_7, // which is physical address 0x1C000. *firstByteInPage = cpct_px2byteM1(1, 1, 3, 3); // Set the first byte in page to all pixels with colours 1, 3 (yellow, cyan by default ). cpct_pageMemory(RAMCFG_0 | BANK_0); // Set the memory again to default state // Clear Screen cpct_memset(CPCT_VMEM_START, 0, 0x4000); // Let's make visible the values we stored. cpct_pageMemory(RAMCFG_0 | BANK_0); // Not needed, sets the memory with the first 64kb accesible, in consecutive banks. pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 0); cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 0); cpct_drawStringM1("RAMCFG_0", pvmem, 1, 0); cpct_pageMemory(RAMCFG_4 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 16); cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 16); cpct_drawStringM1("RAMCFG_4", pvmem, 1, 0); cpct_pageMemory(RAMCFG_5 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 32); cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 32); cpct_drawStringM1("RAMCFG_5", pvmem, 1, 0); cpct_pageMemory(RAMCFG_6 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 48); cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 48); cpct_drawStringM1("RAMCFG_6", pvmem, 1, 0); cpct_pageMemory(RAMCFG_7 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 64); cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 64); cpct_drawStringM1("RAMCFG_7", pvmem, 1, 0); cpct_pageMemory(DEFAULT_MEM_CFG); // Equivalent to RAMCFG_0 | BANK_0 // Loop forever while (1); }