QUOTE: Enjoy small things, cherish moments.

feat: Added max health - freezo - A retro platform game

freezo

A retro platform game
git clone git@soophie.de:/srv/git/freezo
log | files | refs | readme

commit 3f88293188282ff12f5d6b06150032ad4298d502
parent 2a7c197039c59c249b85cd20fd86c3bd4aba56d2
Author: Sophie <info@soophie.de>
Date:   Tue, 17 Dec 2024 20:27:30 +0100

feat: Added max health

Diffstat:
Minclude/const.h | 1-
Minclude/player.h | 3+++
Msrc/game.c | 13++++++++++++-
Msrc/player.c | 3++-
4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/include/const.h b/include/const.h @@ -7,7 +7,6 @@ #define PLAYER_HEIGHT 12 *SCALE #define ENEMY_WIDTH 8 * SCALE #define ENEMY_HEIGHT 12 * SCALE -#define PLAYER_HEALTH 6 #define PLAYER_SHOOTING_RANGE 2 * TILE_WIDTH #define PLAYER_GRAVITY 10 #define FONT_WIDTH 5 * (SCALE - 1) diff --git a/include/player.h b/include/player.h @@ -7,9 +7,12 @@ typedef struct Player player_t; #include "game.h" #include "entity.h" +#define PLAYER_MAX_HEALTH 6 + struct Player { pos_t pos; int health; + int max_health; bool on_ground; float velocity; float gravity; diff --git a/src/game.c b/src/game.c @@ -94,8 +94,16 @@ void game_update(game_t *game) { } if (game->sceen_timer == GAME_SCEEN_TIMER) { level_e level = game->level->type; + int max_health = game->player->max_health; + max_health -= 2; + if (max_health <= 0) { + level = LEVEL_1; + max_health = PLAYER_MAX_HEALTH; + } level_unload(game); level_load(game, level); + game->player->max_health = max_health; + game->player->health = max_health; game->defeat = false; game->xp = 0; game->sceen_timer = 0; @@ -115,9 +123,12 @@ void game_update(game_t *game) { if (game->sceen_timer == GAME_SCEEN_TIMER) { if (game->level->type < LEVELS) { level_e level = game->level->type; + int max_health = game->player->max_health; level++; level_unload(game); level_load(game, level); + game->player->max_health = max_health; + game->player->health = max_health; } game->victory = false; game->sceen_timer = 0; @@ -226,7 +237,7 @@ void game_draw(game_t *game) { DrawTextureRec(game->assets.tiles, texture_rect(1, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0 + i * (TILE_WIDTH + TILE_WIDTH / 4.0), TILE_WIDTH / 2.0 }, WHITE); i++; } - for (; i < PLAYER_HEALTH / 2; i++) { + for (; i < game->player->max_health / 2; i++) { DrawTextureRec(game->assets.tiles, texture_rect(2, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0 + i * (TILE_WIDTH + TILE_WIDTH / 4.0), TILE_WIDTH / 2.0 }, WHITE); } if (game->is_muted) { diff --git a/src/player.c b/src/player.c @@ -12,7 +12,8 @@ player_t *player_create(pos_t pos) { player_t *player = malloc(sizeof(player_t)); *player = (player_t) { .pos = pos, - .health = 6, + .health = PLAYER_MAX_HEALTH, + .max_health = PLAYER_MAX_HEALTH, .on_ground = false, .velocity = 0.0, .gravity = 0.0,