forked from NotAShelf/rogged
movement: generalize; use vectors (#16)
Generalized movement, so that all entities move the same. Reviewed-on: NotAShelf/rogged#16 Reviewed-by: raf <raf@notashelf.dev> Co-authored-by: Squirrel Modeller <squirrelmodeller@protonmail.com> Co-committed-by: Squirrel Modeller <squirrelmodeller@protonmail.com>
This commit is contained in:
parent
1d738c35d4
commit
4dfe52ae72
9 changed files with 124 additions and 89 deletions
31
src/player.c
31
src/player.c
|
|
@ -2,15 +2,12 @@
|
|||
#include "combat.h"
|
||||
#include "common.h"
|
||||
#include "items.h"
|
||||
#include "map.h"
|
||||
#include "settings.h"
|
||||
#include "utils.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void player_init(Player *p, int x, int y) {
|
||||
p->x = x;
|
||||
p->y = y;
|
||||
p->position.x = x;
|
||||
p->position.y = y;
|
||||
p->hp = PLAYER_BASE_HP;
|
||||
p->max_hp = PLAYER_BASE_HP;
|
||||
p->attack = PLAYER_BASE_ATTACK;
|
||||
|
|
@ -43,36 +40,20 @@ Enemy *player_find_enemy_at(Enemy *enemies, int count, int x, int y) {
|
|||
if (count > MAX_ENEMIES)
|
||||
count = MAX_ENEMIES;
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (enemies[i].alive && enemies[i].x == x && enemies[i].y == y)
|
||||
if (enemies[i].alive && enemies[i].position.x == x && enemies[i].position.y == y)
|
||||
return &enemies[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int player_move(Player *p, int dx, int dy, Map *map) {
|
||||
int new_x = p->x + dx;
|
||||
int new_y = p->y + dy;
|
||||
|
||||
// Check bounds
|
||||
if (!in_bounds(new_x, new_y, MAP_WIDTH, MAP_HEIGHT))
|
||||
return 0;
|
||||
|
||||
// Check if walkable
|
||||
if (!is_floor(map, new_x, new_y))
|
||||
return 0;
|
||||
|
||||
// Move player
|
||||
p->x = new_x;
|
||||
p->y = new_y;
|
||||
void player_on_move(Player *p) {
|
||||
p->step_count += 1;
|
||||
// Regen suppressed while poisoned, bleeding, or burning
|
||||
if (p->step_count % REGEN_STEP_INTERVAL == 0 && p->hp < p->max_hp &&
|
||||
!combat_has_effect(p->effects, p->effect_count, EFFECT_POISON) &&
|
||||
!combat_has_effect(p->effects, p->effect_count, EFFECT_BLEED) &&
|
||||
!combat_has_effect(p->effects, p->effect_count, EFFECT_BURN)) {
|
||||
p->hp += 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void player_attack(Player *p, Enemy *e) {
|
||||
|
|
@ -228,8 +209,8 @@ int player_drop_item(Player *p, int inv_index, Item *items, int item_count) {
|
|||
if (items[i].picked_up) {
|
||||
// Place dropped item at this position
|
||||
items[i] = *item;
|
||||
items[i].x = p->x;
|
||||
items[i].y = p->y;
|
||||
items[i].x = p->position.x;
|
||||
items[i].y = p->position.y;
|
||||
items[i].picked_up = 0;
|
||||
// Remove from inventory
|
||||
player_remove_inventory_item(p, inv_index);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue