I've been trying to create a maze-like top-down game where you go around collecting pieces of paper whilst avoiding some monsters, but I'm having trouble updating the tile once the player goes over it. What should happen is when the player collides with the piece of paper, it should change it to a blank tile (which is represented with a 0), update the score (Not yet implemented) and play a sound effect (Not yet implemented).
The code below kind of works, but it isn't updating the correct tiles.For reference, this is what the first level looks like (0 = empty tile, 4 = brick tile, 5 = door, 6 = paper, and 7, 9, 14 = text spelling "TEST"):Let me know if I need to provide any more code snippets, and thanks in advance!
The code below kind of works, but it isn't updating the correct tiles.
Code:
void update_tile(unsigned char coordinates) { levels[level_count][coordinates] = 0; // Disable rendering to prevent glitches ppu_off(); // Calculate the PPU address based on tile coordinates vram_adr(NTADR_A(Player.x >> 4, Player.y & 0xf0)); // Write the empty tile to the PPU vram_put(0); // Re-enable rendering ppu_on_all();}void bg_collision(void) {// Other collision detection with walls and stuff// Check for collision with paper on top left and bottom right of sprite coordinates = (temp_x >> 4) + (temp_y & 0xf0); // upper left if(c_map[coordinates] == 6) { // Delete paper, increase score and play sound effect update_tile(coordinates); // Update screen to remove paper } coordinates = (temp_x >> 4) + (temp_y & 0xf0); // bottom right if(c_map[coordinates] == 6){ // Delete paper, increase score and play sound effect update_tile(coordinates); // Update screen to remove paper }}
Code:
unsigned char level00[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,9,14,7,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,4,4,4,4,0,0,0,0,0,5,4,6,0,0,4,0,0,4,4,6,0,4,0,0,0,4,4,4,4,0,4,0,4,4,4,4,0,4,0,4,4,4,0,0,4,0,0,0,0,4,4,0,0,0,0,4,0,0,4,4,4,0,4,0,0,4,4,0,0,4,0,4,4,4,0,0,0,0,4,4,0,0,0,0,4,4,0,0,0,6,4,4,4,0,4,0,0,4,4,0,0,4,0,4,4,4,0,0,4,0,0,0,4,4,4,4,0,0,0,4,0,0,4,4,4,0,4,0,6,4,4,0,0,4,0,4,4,4,4,0,0,0,4,0,4,4,4,4,0,4,0,0,0,4,5,0,0,0,0,0,0,0,0,0,0,0,0,0,6,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4};
Statistics: Posted by Apollo8795 — Fri Aug 16, 2024 2:31 pm — Replies 8 — Views 290