diff --git a/src/dusk/entity/player.h b/src/dusk/entity/player.h index 54ebe11..1709342 100644 --- a/src/dusk/entity/player.h +++ b/src/dusk/entity/player.h @@ -17,7 +17,7 @@ typedef struct { #define PLAYER_ENTITY_ID (UINT32_MAX-1) #define PLAYER_MOVE_SPEED FIXED248(1, 0) -#define PLAYER_MOVE_SPEED_XY FIXED248(0, 70) +#define PLAYER_MOVE_SPEED_XY FIXED248(0, 80) /** * Initializes the player and all player-related entities. diff --git a/src/dusk/world/chunk.c b/src/dusk/world/chunk.c index 7b5e691..15271bd 100644 --- a/src/dusk/world/chunk.c +++ b/src/dusk/world/chunk.c @@ -278,12 +278,17 @@ void chunkUnload(chunk_t *chunk) { entity++; } while(entity < ENTITIES + ENTITY_COUNT_MAX); + assertTrue( + entity < ENTITIES + ENTITY_COUNT_MAX, + "Entity ID not found in ENTITIES array, cannot unload" + ); + // If the entity is still within our chunk bounds, it's getting unloaded if( - entity->x >= chunk->x * CHUNK_WIDTH * TILE_WIDTH && - entity->x < (chunk->x + 1) * CHUNK_WIDTH * TILE_WIDTH && - entity->y >= chunk->y * CHUNK_HEIGHT * TILE_HEIGHT && - entity->y < (chunk->y + 1) * CHUNK_HEIGHT * TILE_HEIGHT + fx248Flooru32(entity->x) >= chunk->x * CHUNK_WIDTH * TILE_WIDTH && + fx248Ceilu32(entity->x) < (chunk->x + 1) * CHUNK_WIDTH * TILE_WIDTH && + fx248Flooru32(entity->y) >= chunk->y * CHUNK_HEIGHT * TILE_HEIGHT && + fx248Ceilu32(entity->y) < (chunk->y + 1) * CHUNK_HEIGHT * TILE_HEIGHT ) { shouldUnload = true; } else { @@ -298,13 +303,7 @@ void chunkUnload(chunk_t *chunk) { // This entity is still in use, leave it loaded. if(!shouldUnload) continue; - assertTrue( - entity < ENTITIES + ENTITY_COUNT_MAX, - "Entity ID not found for unloading" - ); - // NULL the entity type, effectively unloading it. - printf("Unloading entity ID %u\n", entity->id); entity->type = ENTITY_TYPE_NULL; } } \ No newline at end of file diff --git a/src/dusk/world/chunk.h b/src/dusk/world/chunk.h index 30b0f3a..4194931 100644 --- a/src/dusk/world/chunk.h +++ b/src/dusk/world/chunk.h @@ -9,7 +9,7 @@ #include "tile.h" #define CHUNK_MAP_WIDTH 4 -#define CHUNK_MAP_HEIGHT 4 +#define CHUNK_MAP_HEIGHT 3 #define CHUNK_MAP_COUNT (CHUNK_MAP_WIDTH * CHUNK_MAP_HEIGHT) #define CHUNK_WIDTH 8 diff --git a/src/dusk/world/overworld.c b/src/dusk/world/overworld.c index 27e868f..fcbf907 100644 --- a/src/dusk/world/overworld.c +++ b/src/dusk/world/overworld.c @@ -51,16 +51,21 @@ void overworldUpdate() { OVERWORLD_CAMERA_Y = fx248Flooru32(entity->y); uint16_t x, y; - if(OVERWORLD_CAMERA_X < RENDER_WIDTH / 2) { + uint16_t halfWidth, halfHeight; + halfWidth = ((CHUNK_MAP_WIDTH - 1) * CHUNK_WIDTH * TILE_WIDTH) / 2; + halfHeight = ((CHUNK_MAP_HEIGHT - 1) * CHUNK_HEIGHT * TILE_HEIGHT) / 2; + + // Calculate the chunk map position based on the camera position. + if(OVERWORLD_CAMERA_X < halfWidth) { x = 0; } else { - x = (OVERWORLD_CAMERA_X - (RENDER_WIDTH / 2)) / (CHUNK_WIDTH*TILE_WIDTH); + x = (OVERWORLD_CAMERA_X - halfWidth) / (CHUNK_WIDTH*TILE_WIDTH); } - if(OVERWORLD_CAMERA_Y < RENDER_HEIGHT / 2) { + if(OVERWORLD_CAMERA_Y < halfHeight) { y = 0; } else { - y = (OVERWORLD_CAMERA_Y -(RENDER_HEIGHT / 2)) / (CHUNK_HEIGHT*TILE_HEIGHT); + y = (OVERWORLD_CAMERA_Y - halfHeight) / (CHUNK_HEIGHT*TILE_HEIGHT); } chunkMapSetPosition(x, y); diff --git a/src/duskraylib/display/draw/drawoverworld.c b/src/duskraylib/display/draw/drawoverworld.c index c935169..07593c0 100644 --- a/src/duskraylib/display/draw/drawoverworld.c +++ b/src/duskraylib/display/draw/drawoverworld.c @@ -105,7 +105,7 @@ void drawOverworldDraw(void) { entity_t *entity = ENTITIES; do { drawOverworldDrawEntity(entity++); - } while(entity->type != ENTITY_TYPE_NULL); + } while(entity < ENTITIES + ENTITY_COUNT_MAX); EndMode2D(); } @@ -113,6 +113,7 @@ void drawOverworldDraw(void) { void drawOverworldDrawEntity(const entity_t *entity) { assertNotNull(entity, "Entity pointer cannot be NULL"); + if(entity->type == ENTITY_TYPE_NULL) return; // Skip null entities uint32_t x = fx248Tou32(entity->x); uint32_t y = fx248Tou32(entity->y); @@ -130,47 +131,4 @@ void drawOverworldDrawEntity(const entity_t *entity) { (Vector2){ x, y }, WHITE ); - - // DrawRectangle( - // x, - // y, - // TILE_WIDTH, - // TILE_HEIGHT, - // (entity->type == ENTITY_TYPE_PLAYER) ? BLUE : YELLOW - // ); - - // switch(entity->dir) { - // case ENTITY_DIR_NORTH: - // DrawTriangle( - // (Vector2){ x + TILE_WIDTH / 2, y }, - // (Vector2){ x, y + TILE_HEIGHT }, - // (Vector2){ x + TILE_WIDTH, y + TILE_HEIGHT }, - // WHITE - // ); - // break; - // case ENTITY_DIR_SOUTH: - // DrawTriangle( - // (Vector2){ x + TILE_WIDTH / 2, y + TILE_HEIGHT }, - // (Vector2){ x + TILE_WIDTH, y }, - // (Vector2){ x, y }, - // WHITE - // ); - // break; - // case ENTITY_DIR_WEST: - // DrawTriangle( - // (Vector2){ x, y + TILE_HEIGHT / 2 }, - // (Vector2){ x + TILE_WIDTH, y + TILE_HEIGHT }, - // (Vector2){ x + TILE_WIDTH, y }, - // WHITE - // ); - // break; - // case ENTITY_DIR_EAST: - // DrawTriangle( - // (Vector2){ x + TILE_WIDTH, y + TILE_HEIGHT / 2 }, - // (Vector2){ x, y }, - // (Vector2){ x, y + TILE_HEIGHT }, - // WHITE - // ); - // break; - // } } \ No newline at end of file diff --git a/tools/mapcompile/mapcompile.py b/tools/mapcompile/mapcompile.py index 3a16d4c..b0463de 100644 --- a/tools/mapcompile/mapcompile.py +++ b/tools/mapcompile/mapcompile.py @@ -188,7 +188,7 @@ for layerIndex, layer in enumerate(tileLayers): # Pre generate entity data -nextEntityId = 1 +nextEntityId = 100 for obIndex, ob in enumerate(objectLayer['objects']): if 'x' not in ob or 'y' not in ob: print(f"Error: Object in object layer does not contain 'x' or 'y' key.")