Show player pos, fix chunks off screen

This commit is contained in:
2026-06-18 10:24:45 -05:00
parent 9810fd51ab
commit a162002af2
6 changed files with 68 additions and 3 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ errorret_t consoleDraw(void) {
errorChain(textDraw(
0, FONT_DEFAULT.tileset->tileHeight * i,
CONSOLE.line[i],
COLOR_WHITE,
COLOR_RED,
&FONT_DEFAULT
));
}
+2 -2
View File
@@ -17,8 +17,8 @@
#define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH)
#define MAP_CHUNK_WIDTH 3
#define MAP_CHUNK_HEIGHT 3
#define MAP_CHUNK_WIDTH 5
#define MAP_CHUNK_HEIGHT 5
#define MAP_CHUNK_DEPTH 3
#define MAP_CHUNK_COUNT (MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT * MAP_CHUNK_DEPTH)
+1
View File
@@ -13,4 +13,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
uifullbox.c
uiloading.c
uitextbox.c
uiplayerpos.c
)
+2
View File
@@ -13,6 +13,7 @@
#include "ui/uitextbox.h"
#include "ui/uifullbox.h"
#include "ui/uiloading.h"
#include "ui/uiplayerpos.h"
uielement_t UI_ELEMENTS[] = {
// Fullbox under: above scene, below system UI.
@@ -28,6 +29,7 @@ uielement_t UI_ELEMENTS[] = {
// These render above the fullbox overlay.
{ .type = UI_ELEMENT_TYPE_NATIVE, .draw = consoleDraw },
{ .type = UI_ELEMENT_TYPE_NATIVE, .draw = uiFPSDraw },
{ .type = UI_ELEMENT_TYPE_NATIVE, .draw = uiPlayerPosDraw },
{ .type = UI_ELEMENT_TYPE_NATIVE, .draw = uiLoadingDraw },
+44
View File
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "uiplayerpos.h"
#include "display/text/text.h"
#include "display/spritebatch/spritebatch.h"
#include "rpg/entity/entity.h"
#include "rpg/entity/entitytype.h"
#include "rpg/overworld/worldpos.h"
errorret_t uiPlayerPosDraw() {
entity_t *player = NULL;
for(uint8_t i = 0; i < ENTITY_COUNT; i++) {
if(ENTITIES[i].type == ENTITY_TYPE_PLAYER) {
player = &ENTITIES[i];
break;
}
}
if(!player) errorOk();
chunkpos_t chunkPos;
worldPosToChunkPos(&player->position, &chunkPos);
char_t text[64];
snprintf(
text,
sizeof(text),
"%d,%d,%d[%d,%d,%d]",
(int_t)player->position.x,
(int_t)player->position.y,
(int_t)player->position.z,
(int_t)chunkPos.x,
(int_t)chunkPos.y,
(int_t)chunkPos.z
);
float_t y = (float_t)FONT_DEFAULT.tileset->tileHeight;
errorChain(textDraw(0, y, text, COLOR_GREEN, &FONT_DEFAULT));
return spriteBatchFlush();
}
+18
View File
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "error/error.h"
/**
* Draws the player world and chunk position on screen.
* Searches for the first ENTITY_TYPE_PLAYER and renders:
* WORLDX,WORLDY,WORLDZ[chunkx,chunky,chunkz]
*
* @return Any error that occurs.
*/
errorret_t uiPlayerPosDraw();