mirror of https://github.com/bgiraudr/Adoranda.git
31 lines
804 B
C
31 lines
804 B
C
#include "player.h"
|
|
#include "define.h"
|
|
#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)
|
|
*/
|
|
int player_facing(struct Game const *game) {
|
|
int direction = game->player->direction;
|
|
int dx = (direction == DIR_RIGHT) - (direction == DIR_LEFT);
|
|
int dy = (direction == DIR_DOWN) - (direction == DIR_UP);
|
|
|
|
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) {
|
|
return game->map->info_map[index];
|
|
}
|
|
return TILE_SOLID;
|
|
}
|
|
|
|
/* lol */
|
|
void set_player_xy(struct Player *p, int x, int y) {
|
|
p->pos.x = x;
|
|
p->pos.y = y;
|
|
}
|