From 9af75703e8d03577cff42e05cab91a8e572da4a8 Mon Sep 17 00:00:00 2001 From: Edvin Jakobsson Date: Fri, 30 Jun 2023 19:45:40 +0200 Subject: Added some basic collison detection --- main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 0bf5362..627f620 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,7 @@ #include #include #include -// TODO FIRSST get rendering and movement around map working. +// TODO FIRSST get rendering and movement around map working. DONE // TODO Enemies, Load maps. Weapons @@ -239,8 +239,11 @@ bool gameLoop(int map_w, int map_h, SDL_Renderer *renderer, SDL_Event event, str player.angle -= 2 * M_PI; } - player.x += acceleration * cos(player.angle); - player.y += acceleration * sin(player.angle); + if(map[(int)(player.x + acceleration * cos(player.angle))][(int)(player.y + acceleration * sin(player.angle))].type == 0) + { + player.x += acceleration * cos(player.angle); + player.y += acceleration * sin(player.angle); + } if(acceleration > 0.0) acceleration -= 0.1; else if(acceleration < 0.0) -- cgit v1.2.3