From 622604ab99f53a891700919268e34ab679c96330 Mon Sep 17 00:00:00 2001 From: Schark Date: Thu, 11 May 2023 22:04:13 -0700 Subject: Created player files for easier management of movement --- src/player.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/player.c (limited to 'src/player.c') diff --git a/src/player.c b/src/player.c new file mode 100644 index 0000000..91c4520 --- /dev/null +++ b/src/player.c @@ -0,0 +1,34 @@ +#include +#include + +#include "player.h" + +void move_player(Player *player, GLFWwindow* window) { + if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) { + player->pos_x += player->dir_x * player->move_speed; + player->pos_y += player->dir_y * player->move_speed; + } + if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { + player->pos_x -= player->dir_x * player->move_speed; + player->pos_y -= player->dir_y * player->move_speed; + } + if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { + // this changes where we're casting our rays + double old_dir_x = player->dir_x; + player->dir_x = player->dir_x * cos(-player->rot_speed) - player->dir_y * sin(-player->rot_speed); + player->dir_y = old_dir_x * sin(-player->rot_speed) + player->dir_y * cos(-player->rot_speed); + // this updates perspective + double old_plane_x = player->plane_x; + player->plane_x = player->plane_x * cos(-player->rot_speed) - player->plane_y * sin(-player->rot_speed); + player->plane_y = old_plane_x * sin(-player->rot_speed) + player->plane_y * cos(-player->rot_speed); + } + if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { + double old_dir_x = player->dir_x; + player->dir_x = player->dir_x * cos(player->rot_speed) - player->dir_y * sin(player->rot_speed); + player->dir_y = old_dir_x * sin(player->rot_speed) + player->dir_y * cos(player->rot_speed); + double old_plane_x = player->plane_x; + player->plane_x = player->plane_x * cos(player->rot_speed) - player->plane_y * sin(player->rot_speed); + player->plane_y = old_plane_x * sin(player->rot_speed) + player->plane_y * cos(player->rot_speed); + } + +} -- cgit v1.2.3-18-g5258