feat/refactor: player health and overlay display

This commit is contained in:
2026-07-05 20:17:06 +02:00
parent a4289a21aa
commit cc42a45f68
5 changed files with 27 additions and 10 deletions
+2 -6
View File
@@ -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++) {
-1
View File
@@ -1,5 +1,4 @@
#include "app.h"
#include <raylib.h>
float playerCollisionRadius = 8.0f;
float enemiesCollisionRadius = 8.0f;
+17
View File
@@ -0,0 +1,17 @@
#include "app.h"
#include "raylib.h"
#include <limits.h>
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);
}
+8 -2
View File
@@ -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
};
}
-1
View File
@@ -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],