From 8d316d0d0d12c68cf1d6ea08c88d1640ff32a991 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Sat, 8 Jul 2023 16:40:25 +0200 Subject: [PATCH] Collisions are working :D! I only need to add a framerate limit and add some comments, then everything will be good to merge! --- src/player.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/player.c b/src/player.c index 1932a00..e5094f1 100644 --- a/src/player.c +++ b/src/player.c @@ -3,6 +3,9 @@ #include /* (Mibi88) TODO: Upscale the player for the CG50. */ +/* The player should not be bigger than a tile because it may cause problems + * with the collisions. If it's a problem please ask me (Mibi88) to adapt that. + */ #define P_WIDTH 8 #define P_HEIGHT 8 @@ -56,9 +59,9 @@ bool player_collision(Map *map_level, Player *player, Direction direction) { 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; + int player_tile_y = player->y/T_HEIGHT; for(i=0;inblayers;i++){ - if(is_in(hard_tiles, HARD_TILES_AMOUNT, + if(is_in((short int*)hard_tiles, HARD_TILES_AMOUNT, get_tile(map_level, player_tile_x+dx, player_tile_y+dy, i))){ return true; } @@ -67,7 +70,7 @@ bool player_collision(Map *map_level, Player *player, Direction direction) { } 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; + if(fix_x) player->x = player->x/T_WIDTH*T_WIDTH+P_WIDTH/2; + if(fix_y) player->y = player->y/T_HEIGHT*T_HEIGHT+P_HEIGHT/2; }