so://phie

freezo

A retro platform game
git clone git://soophie.de/freezo

feat: Added max health


commit: 3f88293188282ff12f5d6b06150032ad4298d502
parent: 2a7c197039c59c249b85cd20fd86c3bd4aba56d2
author: Sophie <info@soophie.de>
time: 2024-12-17 20:27

diff --git a/include/const.h b/include/const.h

index 51e62ba..adebafe 100644

--- a/include/const.h

+++ b/include/const.h

1@@ -7,7 +7,6 @@

2 #define PLAYER_HEIGHT 12 *SCALE

3 #define ENEMY_WIDTH 8 * SCALE

4 #define ENEMY_HEIGHT 12 * SCALE

5-#define PLAYER_HEALTH 6

6 #define PLAYER_SHOOTING_RANGE 2 * TILE_WIDTH

7 #define PLAYER_GRAVITY 10

8 #define FONT_WIDTH 5 * (SCALE - 1)

9

10

diff --git a/include/player.h b/include/player.h

index 7b24aa4..099d524 100644

--- a/include/player.h

+++ b/include/player.h

1@@ -7,9 +7,12 @@ typedef struct Player player_t;

2 #include "game.h"

3 #include "entity.h"

4

5+#define PLAYER_MAX_HEALTH 6

6+

7 struct Player {

8 pos_t pos;

9 int health;

10+ int max_health;

11 bool on_ground;

12 float velocity;

13 float gravity;

14

15

diff --git a/src/game.c b/src/game.c

index 845eda9..9f4ae24 100644

--- a/src/game.c

+++ b/src/game.c

1@@ -94,8 +94,16 @@ void game_update(game_t *game) {

2 }

3 if (game->sceen_timer == GAME_SCEEN_TIMER) {

4 level_e level = game->level->type;

5+ int max_health = game->player->max_health;

6+ max_health -= 2;

7+ if (max_health <= 0) {

8+ level = LEVEL_1;

9+ max_health = PLAYER_MAX_HEALTH;

10+ }

11 level_unload(game);

12 level_load(game, level);

13+ game->player->max_health = max_health;

14+ game->player->health = max_health;

15 game->defeat = false;

16 game->xp = 0;

17 game->sceen_timer = 0;

18@@ -115,9 +123,12 @@ void game_update(game_t *game) {

19 if (game->sceen_timer == GAME_SCEEN_TIMER) {

20 if (game->level->type < LEVELS) {

21 level_e level = game->level->type;

22+ int max_health = game->player->max_health;

23 level++;

24 level_unload(game);

25 level_load(game, level);

26+ game->player->max_health = max_health;

27+ game->player->health = max_health;

28 }

29 game->victory = false;

30 game->sceen_timer = 0;

31@@ -226,7 +237,7 @@ void game_draw(game_t *game) {

32 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);

33 i++;

34 }

35- for (; i < PLAYER_HEALTH / 2; i++) {

36+ for (; i < game->player->max_health / 2; i++) {

37 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);

38 }

39 if (game->is_muted) {

40

41

diff --git a/src/player.c b/src/player.c

index 0a58d31..162b96d 100644

--- a/src/player.c

+++ b/src/player.c

1@@ -12,7 +12,8 @@ player_t *player_create(pos_t pos) {

2 player_t *player = malloc(sizeof(player_t));

3 *player = (player_t) {

4 .pos = pos,

5- .health = 6,

6+ .health = PLAYER_MAX_HEALTH,

7+ .max_health = PLAYER_MAX_HEALTH,

8 .on_ground = false,

9 .velocity = 0.0,

10 .gravity = 0.0,

11

12