summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c57
1 files 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
- {1, 0, 0, 0, 0, 0,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, 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);