various: fixup doors
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Id81f32d86f70a7df99c2ad3d478646416a6a6964
This commit is contained in:
parent
00b3798ae0
commit
d8b49054d5
6 changed files with 345 additions and 87 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "movement.h"
|
||||
#include "enemy.h"
|
||||
#include "map/map.h"
|
||||
#include "map/utils.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
// Check if position is occupied by player
|
||||
|
|
@ -8,11 +9,33 @@ static int is_player_at(Player *p, int x, int y) {
|
|||
return (p->position.x == x && p->position.y == y);
|
||||
}
|
||||
|
||||
static int direction_to_door_open_from(Vec2 dir) {
|
||||
if (dir.y == -1)
|
||||
return 0; // N
|
||||
if (dir.y == 1)
|
||||
return 1; // S
|
||||
if (dir.x == 1)
|
||||
return 2; // E
|
||||
if (dir.x == -1)
|
||||
return 3; // W
|
||||
return 255;
|
||||
}
|
||||
|
||||
MoveResult try_move_entity(Vec2 *p, Vec2 direction, Map *map, Player *player, Enemy *enemies, int enemy_count,
|
||||
bool moving_is_player) {
|
||||
int new_x = p->x + direction.x;
|
||||
int new_y = p->y + direction.y;
|
||||
|
||||
if (!in_bounds(new_x, new_y, MAP_WIDTH, MAP_HEIGHT))
|
||||
return MOVE_RESULT_BLOCKED_WALL;
|
||||
|
||||
if (map->tiles[new_y][new_x] == TILE_DOOR_CLOSED) {
|
||||
map->tiles[new_y][new_x] = TILE_DOOR_OPEN;
|
||||
map->door_open_from[new_y][new_x] = direction_to_door_open_from(direction);
|
||||
map->door_anim_target[new_y][new_x] = 1;
|
||||
map->door_anim_timer[new_y][new_x] = DOOR_ANIM_FRAMES;
|
||||
}
|
||||
|
||||
if (!is_floor(map, new_x, new_y))
|
||||
return MOVE_RESULT_BLOCKED_WALL;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue