#include "player.h" #include "map.h" #include /* (Mibi88) TODO: Upscale the player for the CG50. */ #define P_WIDTH 8 #define P_HEIGHT 8 /* SPEED should NOT be 8 or bigger: it this may cause bugs when handling * collisions! */ #ifdef FXCG50 #define SPEED 3 #else #define SPEED 1 #endif const char one_px_mov[8] = { 0, -1, /* Up */ 0, 1, /* Down */ -1, 0, /* Left */ 1, 0 /* Right */ }; /* TODO: Search for all hard tiles in the tileset. hard_tiles is a list of their * IDs */ #define HARD_TILES_AMOUNT 5 const short int hard_tiles[HARD_TILES_AMOUNT] = { MAP_OUTSIDE, 124, 148, 125, 149 }; extern bopti_image_t demo_player_img; void player_draw(Player *player) { dimage(player->px-P_WIDTH/2, player->py-P_HEIGHT/2, &demo_player_img); } void player_move(Map *map_level, Player *player, Direction direction) { /* How this player movement will modify the player x and y. */ const char dx = one_px_mov[direction*2]*SPEED; const char dy = one_px_mov[direction*2+1]*SPEED; if(player_collision(map_level, player, direction)){ player_fix_position(player, dx, dy); }else{ player->x += dx; player->y += dy; } } void player_action(Player *player) { /**/ } bool player_collision(Map *map_level, Player *player, Direction direction) { /* What's the tile the player is going to. */ short int i; const char dx = one_px_mov[direction*2]; const char dy = one_px_mov[direction*2+1]; int player_tile_x = player->x/T_WIDTH; int player_tile_y = player->x/T_WIDTH; for(i=0;inblayers;i++){ if(is_in(hard_tiles, HARD_TILES_AMOUNT, get_tile(map_level, player_tile_x+dx, player_tile_y+dy, i))){ return true; } } return false; } void player_fix_position(Player *player, bool fix_x, bool fix_y) { if(fix_x) player->x = player->x/T_WIDTH*T_WIDTH; if(fix_y) player->y = player->y/T_HEIGHT*T_HEIGHT; }