summaryrefslogtreecommitdiff
path: root/sdl3_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'sdl3_main.c')
-rw-r--r--sdl3_main.c58
1 files changed, 57 insertions, 1 deletions
diff --git a/sdl3_main.c b/sdl3_main.c
index b5f1404..5a4ec6f 100644
--- a/sdl3_main.c
+++ b/sdl3_main.c
@@ -34,7 +34,7 @@ static SDL_Renderer *renderer;
static bool running;
static Uint64 old_ticks, new_ticks;
-static Player player;
+static Player player = { .body.size = { ENTITY_SIZE, ENTITY_SIZE } };
static Ghost ghosts[1024];
static Bullet bullet[1024];
@@ -184,6 +184,34 @@ update(float delta)
if(kstate[SDL_SCANCODE_D])
player.body.vel[0] += SPEED;
+ for(int y = 0; y < map_height; y++)
+ for(int x = 0; x < map_width; x++) {
+ if(!map_data[x + y * map_width])
+ continue;
+
+ Body b = {
+ .pos = {
+ x * ENTITY_SIZE * 2.0,
+ y * ENTITY_SIZE * 2.0,
+ },
+ .size = { ENTITY_SIZE, ENTITY_SIZE },
+ };
+
+ if(checkcollision(&player.body, &b)) {
+ float p[2];
+ resolvecoll(&player.body, &b, p);
+
+ for(int i = 0; i < 2; i++)
+ player.body.pos[i] -= p[i];
+
+ if(p[0] != 0.0) {
+ player.body.vel[0] = 0;
+ } else {
+ player.body.vel[1] = 0;
+ }
+ }
+ }
+
if(shot) {
shot = false;
int i;
@@ -260,6 +288,34 @@ update(float delta)
}
}
+ for(int y = 0; y < map_height; y++)
+ for(int x = 0; x < map_width; x++) {
+ if(!map_data[x + y * map_width])
+ continue;
+
+ Body b = {
+ .pos = {
+ x * ENTITY_SIZE * 2.0,
+ y * ENTITY_SIZE * 2.0,
+ },
+ .size = { ENTITY_SIZE, ENTITY_SIZE },
+ };
+
+ if(checkcollision(&ghosts[i].body, &b)) {
+ float p[2];
+ resolvecoll(&ghosts[i].body, &b, p);
+
+ for(int i = 0; i < 2; i++)
+ ghosts[i].body.pos[i] -= p[i];
+
+ if(p[0] != 0.0) {
+ vx = 0;
+ } else {
+ vy = 0;
+ }
+ }
+ }
+
ghosts[i].body.vel[0] = vx;
ghosts[i].body.vel[1] = vy;
}