From ce811be0799bfee8355aa56d3ab566fb5b5dab55 Mon Sep 17 00:00:00 2001 From: Schark Date: Tue, 12 Dec 2023 02:39:58 -0800 Subject: ((Super) Basic) Boundary checks --- src/main.c | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/main.c b/src/main.c index 0d08d16..cbe13d8 100644 --- a/src/main.c +++ b/src/main.c @@ -7,28 +7,28 @@ // TODO: move to implicit map definition with level editor in future #define MAP_HEIGHT 20 -#define MAP_WIDTH 20 +#define MAP_WIDTH 10 int world_map[MAP_HEIGHT][MAP_WIDTH] = { - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 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, 3, 3, 0, 0, 0, 0, 1}, + {1, 0, 3, 3, 3, 0, 0, 0, 0, 1}, + {1, 0, 3, 3, 3, 0, 0, 0, 0, 1}, + {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, }; typedef struct { @@ -171,11 +171,11 @@ int main(int argc, char *argv[]) { // init player Player player; player.pos_y = 2.0f; - player.pos_x = 2.0f; - player.dir_x = 1.0f; // facing right - player.dir_y = 0.0f; // facing right - player.plane_x = 0.0f; // FOV related - player.plane_y = 0.66f; // FOV related + player.pos_x = 9.0f; + player.dir_x = 1.0f; + player.dir_y = 0.0f; + player.plane_x = 0.20f; // FOV related + player.plane_y = 0.90f; // FOV related player.look_angle = 0.0f; player.move_speed = 0.035f; player.sensitivity = 0.001f; @@ -254,7 +254,12 @@ int main(int argc, char *argv[]) { glLoadIdentity(); // main raycast function + float prev_position[2] = {player.pos_x, player.pos_y}; move_player(&player, window, &mouse_x, &mouse_y, mode->width, mode->height); + if (world_map[(int)player.pos_x][(int)player.pos_y] != 0) { + player.pos_x = prev_position[0]; + player.pos_y = prev_position[1]; + } GLubyte* pixels = (GLubyte*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); raycast(&player, pixels, mode->width, mode->height); -- cgit v1.2.3-18-g5258