Merge pull request 'dev: added step_count and health recovery' (#1) from amr/rogged:recover-health into main

Reviewed-on: #1
Reviewed-by: raf <raf@notashelf.dev>
This commit is contained in:
raf 2026-03-20 19:52:19 +00:00
commit 4908a32661
2 changed files with 126 additions and 113 deletions

View file

@ -44,6 +44,7 @@ typedef struct {
int attack;
int defense;
int floor;
int step_count;
Item inventory[MAX_INVENTORY];
int inventory_count;
} Player;

View file

@ -1,9 +1,9 @@
#include "player.h"
#include "combat.h"
#include "common.h"
#include "items.h"
#include "map.h"
#include "utils.h"
#include "combat.h"
#include "items.h"
#include <stdlib.h>
void player_init(Player *p, int x, int y) {
@ -14,6 +14,7 @@ void player_init(Player* p, int x, int y) {
p->attack = PLAYER_BASE_ATTACK;
p->defense = 0;
p->floor = 1;
p->step_count = 0;
p->inventory_count = 0;
// Initialize inventory to empty
@ -42,7 +43,8 @@ static Item* get_item_at(Item* items, int count, int x, int y) {
return NULL;
}
int player_move(Player* p, int dx, int dy, Map* map, Enemy* enemies, int enemy_count, Item* items, int item_count) {
int player_move(Player *p, int dx, int dy, Map *map, Enemy *enemies,
int enemy_count, Item *items, int item_count) {
int new_x = p->x + dx;
int new_y = p->y + dy;
@ -74,7 +76,11 @@ int player_move(Player* p, int dx, int dy, Map* map, Enemy* enemies, int enemy_c
// Move player
p->x = new_x;
p->y = new_y;
p->step_count += 1;
if (p->step_count % 15 == 0 && p->hp < p->max_hp) {
p->hp += 1;
// p->hunger -= 0.1; ??
}
return 1;
}
@ -98,8 +104,10 @@ void player_pickup(Player* p, Item* i) {
}
void player_use_item(Player *p, Item *i) {
if (p == NULL || i == NULL) return;
if (i->picked_up) return; // invalid item
if (p == NULL || i == NULL)
return;
if (i->picked_up)
return; // invalid item
// Apply item effect
item_use(p, i);
@ -109,7 +117,8 @@ void player_use_item(Player* p, Item* i) {
}
int player_use_first_item(Player *p) {
if (p == NULL || p->inventory_count == 0) return 0;
if (p == NULL || p->inventory_count == 0)
return 0;
// Find first valid item in inventory
for (int i = 0; i < MAX_INVENTORY; i++) {
@ -135,8 +144,11 @@ int player_use_first_item(Player* p) {
}
Item *player_get_inventory_item(Player *p, int index) {
if (p == NULL) return NULL;
if (index < 0 || index >= MAX_INVENTORY) return NULL;
if (p->inventory[index].picked_up) return NULL; // invalid/empty
if (p == NULL)
return NULL;
if (index < 0 || index >= MAX_INVENTORY)
return NULL;
if (p->inventory[index].picked_up)
return NULL; // invalid/empty
return &p->inventory[index];
}