Adoranda/src/player.c

31 lines
804 B
C
Raw Normal View History

2021-08-08 01:43:26 +02:00
#include "player.h"
2021-08-25 01:30:30 +02:00
#include "define.h"
2021-08-08 01:43:26 +02:00
#include "engine.h"
#include "map.h"
#include "game.h"
/*
return the info tile value the player is facing to
TILE_SOLID by default (out of bound)
*/
2021-08-15 03:46:49 +02:00
int player_facing(struct Game const *game) {
2021-08-08 01:43:26 +02:00
int direction = game->player->direction;
int dx = (direction == DIR_RIGHT) - (direction == DIR_LEFT);
int dy = (direction == DIR_DOWN) - (direction == DIR_UP);
2021-08-25 01:01:43 +02:00
int index = game->player->pos.x + dx + game->map->w * (game->player->pos.y + dy);
if(game->player->pos.x + dx >= 0 &&
game->player->pos.x + dx <= game->map->w &&
game->player->pos.y + dy >= 0 &&
game->player->pos.y + dy <= game->map->h) {
2021-08-08 01:43:26 +02:00
return game->map->info_map[index];
}
return TILE_SOLID;
2021-08-15 03:46:49 +02:00
}
2021-08-25 01:01:43 +02:00
/* lol */
2021-08-25 01:30:30 +02:00
void set_player_xy(struct Player *p, int x, int y) {
p->pos.x = x;
p->pos.y = y;
2021-08-25 01:01:43 +02:00
}