diff options
author | Schark <jordan@schark.online> | 2023-12-12 02:39:58 -0800 |
---|---|---|
committer | Schark <jordan@schark.online> | 2023-12-12 02:39:58 -0800 |
commit | ce811be0799bfee8355aa56d3ab566fb5b5dab55 (patch) | |
tree | 7e6b481b9d16e7ec3f6710f27c99e7508eec666a /src | |
parent | 919e6e5ae22404e2c68a9ebd2cdbd05a44f3a362 (diff) | |
download | gamedev-ce811be0799bfee8355aa56d3ab566fb5b5dab55.tar.gz gamedev-ce811be0799bfee8355aa56d3ab566fb5b5dab55.zip |
((Super) Basic) Boundary checks
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 57 |
1 files changed, 31 insertions, 26 deletions
@@ -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,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+ {1, 0, 0, 0, 0, 0, 4, 4, 0, 1}, + {1, 0, 0, 0, 0, 0, 4, 4, 0, 1}, + {1, 0, 3, 3, 3, 0, 4, 4, 0, 1}, + {1, 0, 3, 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, 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); |