dev: added step_count and health recovery #1
2 changed files with 126 additions and 113 deletions
|
|
@ -44,6 +44,7 @@ typedef struct {
|
||||||
int attack;
|
int attack;
|
||||||
int defense;
|
int defense;
|
||||||
int floor;
|
int floor;
|
||||||
|
int step_count;
|
||||||
Item inventory[MAX_INVENTORY];
|
Item inventory[MAX_INVENTORY];
|
||||||
int inventory_count;
|
int inventory_count;
|
||||||
} Player;
|
} Player;
|
||||||
|
|
|
||||||
32
src/player.c
32
src/player.c
|
|
@ -1,9 +1,9 @@
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "combat.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "items.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "combat.h"
|
|
||||||
#include "items.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void player_init(Player *p, int x, int y) {
|
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->attack = PLAYER_BASE_ATTACK;
|
||||||
p->defense = 0;
|
p->defense = 0;
|
||||||
p->floor = 1;
|
p->floor = 1;
|
||||||
|
p->step_count = 0;
|
||||||
p->inventory_count = 0;
|
p->inventory_count = 0;
|
||||||
|
|
||||||
// Initialize inventory to empty
|
// Initialize inventory to empty
|
||||||
|
|
@ -42,7 +43,8 @@ static Item* get_item_at(Item* items, int count, int x, int y) {
|
||||||
return NULL;
|
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_x = p->x + dx;
|
||||||
int new_y = p->y + dy;
|
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
|
// Move player
|
||||||
p->x = new_x;
|
p->x = new_x;
|
||||||
p->y = new_y;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,8 +104,10 @@ void player_pickup(Player* p, Item* i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void player_use_item(Player *p, Item *i) {
|
void player_use_item(Player *p, Item *i) {
|
||||||
if (p == NULL || i == NULL) return;
|
if (p == NULL || i == NULL)
|
||||||
if (i->picked_up) return; // invalid item
|
return;
|
||||||
|
if (i->picked_up)
|
||||||
|
return; // invalid item
|
||||||
|
|
||||||
// Apply item effect
|
// Apply item effect
|
||||||
item_use(p, i);
|
item_use(p, i);
|
||||||
|
|
@ -109,7 +117,8 @@ void player_use_item(Player* p, Item* i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int player_use_first_item(Player *p) {
|
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
|
// Find first valid item in inventory
|
||||||
for (int i = 0; i < MAX_INVENTORY; i++) {
|
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) {
|
Item *player_get_inventory_item(Player *p, int index) {
|
||||||
if (p == NULL) return NULL;
|
if (p == NULL)
|
||||||
if (index < 0 || index >= MAX_INVENTORY) return NULL;
|
return NULL;
|
||||||
if (p->inventory[index].picked_up) return NULL; // invalid/empty
|
if (index < 0 || index >= MAX_INVENTORY)
|
||||||
|
return NULL;
|
||||||
|
if (p->inventory[index].picked_up)
|
||||||
|
return NULL; // invalid/empty
|
||||||
return &p->inventory[index];
|
return &p->inventory[index];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue