← Back to ratslair.com
aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorEdvin Jakobsson <[email protected]>2023-06-30 19:45:40 +0200
committerEdvin Jakobsson <[email protected]>2023-06-30 19:45:40 +0200
commit9af75703e8d03577cff42e05cab91a8e572da4a8 (patch)
tree954a952f657af7dff1da741676df2fc3e910621b /main.c
parent3f85ae5b817a9baa92d6ff8e1eda245a9a62c837 (diff)
Added some basic collison detection
Diffstat (limited to 'main.c')
-rw-r--r--main.c9
1 files 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 <SDL2/SDL_ttf.h>
#include <stdbool.h>
#include <math.h>
-// 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)