From cc42a45f685454251ecc67a16ada3aa2801d164b Mon Sep 17 00:00:00 2001 From: huaqo Date: Sun, 5 Jul 2026 20:17:06 +0200 Subject: [PATCH] feat/refactor: player health and overlay display --- src/appGame.c | 8 ++------ src/appGameCollisions.c | 1 - src/appGameOverlay.c | 17 +++++++++++++++++ src/appGamePlayer.c | 10 ++++++++-- src/appGameProjectiles.c | 1 - 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 src/appGameOverlay.c diff --git a/src/appGame.c b/src/appGame.c index ec1d939..8ee8508 100644 --- a/src/appGame.c +++ b/src/appGame.c @@ -93,13 +93,9 @@ void RenderGame(App *app) { BeginMode2D(*camera); RenderComponents(app); EndMode2D(); - DrawTextureRec( - g->mouse.cursorTexture, - (Rectangle){0, 0, g->mouse.cursorTexture.width, - g->mouse.cursorTexture.height}, - (Vector2){g->mouse.screenPosition.x, g->mouse.screenPosition.y}, WHITE); + RenderOverlay(&g->mouse); EndTextureMode(); - + BeginDrawing(); ClearBackground(BLACK); for (int i = 0; i < SHADER_COUNT; i++) { diff --git a/src/appGameCollisions.c b/src/appGameCollisions.c index 259873a..ecc65af 100644 --- a/src/appGameCollisions.c +++ b/src/appGameCollisions.c @@ -1,5 +1,4 @@ #include "app.h" -#include float playerCollisionRadius = 8.0f; float enemiesCollisionRadius = 8.0f; diff --git a/src/appGameOverlay.c b/src/appGameOverlay.c new file mode 100644 index 0000000..bfd2843 --- /dev/null +++ b/src/appGameOverlay.c @@ -0,0 +1,17 @@ +#include "app.h" +#include "raylib.h" +#include + +void RenderOverlay(Mouse *mouse) { + + // Health + Player *player = GetPlayer(); + const char *healthText = TextFormat("%d", player->health); + DrawText(healthText, 0, 0, 25, WHITE); + + // Mouse + Rectangle mouseRectangle = (Rectangle){0, 0, mouse->cursorTexture.width, + mouse->cursorTexture.height}; + DrawTextureRec(mouse->cursorTexture, mouseRectangle, mouse->screenPosition, + WHITE); +} diff --git a/src/appGamePlayer.c b/src/appGamePlayer.c index cadccf5..a3d07ed 100644 --- a/src/appGamePlayer.c +++ b/src/appGamePlayer.c @@ -10,6 +10,8 @@ float playerSpeeds[SPEED_COUNT] = { 10.0f }; +Config config; + playerSpeedID GetPlayerSpeedID(float speed) { for (int i = 0; i < SPEED_COUNT; i++) { if (playerSpeeds[i] == speed) { @@ -27,12 +29,15 @@ Player* GetPlayer(void) void CreatePlayer(void) { + + InitConfig(&config, "config/player.ini"); + int PLAYER_HEALTH_MAX = GetConfigInt(&config, "HEALTH_MAX"); + TextureAsset startShipAsset = playerTextureAssets[START_SHIP]; Texture2D texture = LoadTexture(startShipAsset.path); float frameWidth = startShipAsset.frameWidth; float rotation = startShipAsset.rotation; - Sprite playerSprite = { .texture = texture, @@ -66,7 +71,8 @@ void CreatePlayer(void) .sprite = playerSprite, .animation = playerAnimation, .physics = playerPhysics, - .rotation = rotation + .rotation = rotation, + .health = PLAYER_HEALTH_MAX }; } diff --git a/src/appGameProjectiles.c b/src/appGameProjectiles.c index c71b472..9ceeabe 100644 --- a/src/appGameProjectiles.c +++ b/src/appGameProjectiles.c @@ -61,7 +61,6 @@ void UpdateProjectiles(Projectiles *projectiles) { void RenderProjectiles(Projectiles *projectiles) { for (int i = 0; i < projectiles->count; i++) { - printf("Projectile Active: %d", projectiles->active[i]); if (projectiles->active[i] == true) { DrawCircle(projectiles->physics[i].position.x, projectiles->physics[i].position.y, projectiles->radius[i],