diff --git a/src/objects/player_control.cpp b/src/objects/player_control.cpp index c2d753033..5b4f87641 100644 --- a/src/objects/player_control.cpp +++ b/src/objects/player_control.cpp @@ -10,7 +10,7 @@ #include "../voxels/Chunks.h" #include "../window/Camera.h" #include "../window/Events.h" -#include +#include "../window/input.h" #define CROUCH_SPEED_MUL 0.25f #define CROUCH_SHIFT_Y -0.2f @@ -37,7 +37,7 @@ void PlayerController::update_controls(float delta){ /*block choose*/{ for (int i = 1; i < 10; i++){ - if (Events::jpressed(GLFW_KEY_0+i)){ + if (Events::jpressed(keycode::NUM_0+i)){ player->choosenBlock = i; } } @@ -45,10 +45,10 @@ void PlayerController::update_controls(float delta){ Camera* camera = player->camera; Hitbox* hitbox = player->hitbox; - bool sprint = Events::pressed(GLFW_KEY_LEFT_CONTROL); - bool shift = Events::pressed(GLFW_KEY_LEFT_SHIFT) && hitbox->grounded && !sprint; - bool zoom = Events::pressed(GLFW_KEY_C); - bool cheat = Events::pressed(GLFW_KEY_R); + bool sprint = Events::pressed(keycode::LEFT_CONTROL); + bool shift = Events::pressed(keycode::LEFT_SHIFT) && hitbox->grounded && !sprint; + bool zoom = Events::pressed(keycode::C); + bool cheat = Events::pressed(keycode::R); float speed = player->speed; if (player->flight){ @@ -81,14 +81,14 @@ void PlayerController::update_controls(float delta){ camera->position -= min(player->interpVel * 0.05f, 1.0f); }//end - if ((Events::jpressed(GLFW_KEY_F) && !player->noclip) || - (Events::jpressed(GLFW_KEY_N) && player->flight == player->noclip)){ + if ((Events::jpressed(keycode::F) && !player->noclip) || + (Events::jpressed(keycode::N) && player->flight == player->noclip)){ player->flight = !player->flight; if (player->flight){ hitbox->grounded = false; } } - if (Events::jpressed(GLFW_KEY_N)) { + if (Events::jpressed(keycode::N)) { player->noclip = !player->noclip; } @@ -108,23 +108,23 @@ void PlayerController::update_controls(float delta){ camera->zoom = zoomValue * dt + camera->zoom * (1.0f - dt); }//end - if (Events::pressed(GLFW_KEY_SPACE) && hitbox->grounded){ + if (Events::pressed(keycode::SPACE) && hitbox->grounded){ hitbox->velocity.y = JUMP_FORCE; } vec3 dir(0,0,0); - if (Events::pressed(GLFW_KEY_W)){ + if (Events::pressed(keycode::W)){ dir.x += camera->dir.x; dir.z += camera->dir.z; } - if (Events::pressed(GLFW_KEY_S)){ + if (Events::pressed(keycode::S)){ dir.x -= camera->dir.x; dir.z -= camera->dir.z; } - if (Events::pressed(GLFW_KEY_D)){ + if (Events::pressed(keycode::D)){ dir.x += camera->right.x; dir.z += camera->right.z; } - if (Events::pressed(GLFW_KEY_A)){ + if (Events::pressed(keycode::A)){ dir.x -= camera->right.x; dir.z -= camera->right.z; } @@ -133,10 +133,10 @@ void PlayerController::update_controls(float delta){ if (player->flight){ hitbox->linear_damping = PLAYER_AIR_DAMPING; hitbox->velocity.y *= 1.0f - delta * 9; - if (Events::pressed(GLFW_KEY_SPACE)){ + if (Events::pressed(keycode::SPACE)){ hitbox->velocity.y += speed * delta * 9; } - if (Events::pressed(GLFW_KEY_LEFT_SHIFT)){ + if (Events::pressed(keycode::LEFT_SHIFT)){ hitbox->velocity.y -= speed * delta * 9; } } @@ -212,11 +212,11 @@ void PlayerController::update_interaction(){ } Block* block = Block::blocks[vox->id]; - if (Events::jclicked(GLFW_MOUSE_BUTTON_1) && block->breakable){ + if (Events::jclicked(mousecode::BUTTON_1) && block->breakable){ chunks->set(x,y,z, 0, 0); - lighting->onBlockSet(x,y,z,0); + lighting->onBlockSet(x,y,z, 0); } - if (Events::jclicked(GLFW_MOUSE_BUTTON_2)){ + if (Events::jclicked(mousecode::BUTTON_2)){ if (block->model != BLOCK_MODEL_X_SPRITE){ x = (int)(iend.x)+(int)(norm.x); y = (int)(iend.y)+(int)(norm.y); @@ -227,7 +227,7 @@ void PlayerController::update_interaction(){ lighting->onBlockSet(x,y,z, player->choosenBlock); } } - if (Events::jclicked(GLFW_MOUSE_BUTTON_3)){ + if (Events::jclicked(mousecode::BUTTON_3)){ player->choosenBlock = chunks->get(x,y,z)->id; } } else { diff --git a/src/window/input.cpp b/src/window/input.cpp index ce7f54eb5..f134998d9 100644 --- a/src/window/input.cpp +++ b/src/window/input.cpp @@ -3,6 +3,14 @@ int keycode::ENTER = GLFW_KEY_ENTER; int keycode::TAB = GLFW_KEY_TAB; +int keycode::SPACE = GLFW_KEY_SPACE; +int keycode::BACKSPACE = GLFW_KEY_BACKSPACE; +int keycode::LEFT_SHIFT = GLFW_KEY_LEFT_SHIFT; +int keycode::LEFT_CONTROL = GLFW_KEY_LEFT_CONTROL; +int keycode::LEFT_ALT = GLFW_KEY_LEFT_ALT; +int keycode::RIGHT_SHIFT = GLFW_KEY_RIGHT_SHIFT; +int keycode::RIGHT_CONTROL = GLFW_KEY_RIGHT_CONTROL; +int keycode::RIGHT_ALT = GLFW_KEY_RIGHT_ALT; int keycode::F1 = GLFW_KEY_F1; int keycode::F2 = GLFW_KEY_F2; int keycode::F3 = GLFW_KEY_F3; @@ -40,4 +48,18 @@ int keycode::V = GLFW_KEY_V; int keycode::W = GLFW_KEY_W; int keycode::X = GLFW_KEY_X; int keycode::Y = GLFW_KEY_Y; -int keycode::Z = GLFW_KEY_Z; \ No newline at end of file +int keycode::Z = GLFW_KEY_Z; +int keycode::NUM_0 = GLFW_KEY_0; +int keycode::NUM_1 = GLFW_KEY_1; +int keycode::NUM_2 = GLFW_KEY_2; +int keycode::NUM_3 = GLFW_KEY_3; +int keycode::NUM_4 = GLFW_KEY_4; +int keycode::NUM_5 = GLFW_KEY_5; +int keycode::NUM_6 = GLFW_KEY_6; +int keycode::NUM_7 = GLFW_KEY_7; +int keycode::NUM_8 = GLFW_KEY_8; +int keycode::NUM_9 = GLFW_KEY_9; + +int mousecode::BUTTON_1 = GLFW_MOUSE_BUTTON_1; +int mousecode::BUTTON_2 = GLFW_MOUSE_BUTTON_2; +int mousecode::BUTTON_3 = GLFW_MOUSE_BUTTON_3; diff --git a/src/window/input.h b/src/window/input.h index a41da6b9c..8b19e54d7 100644 --- a/src/window/input.h +++ b/src/window/input.h @@ -4,6 +4,14 @@ namespace keycode { extern int ENTER; extern int TAB; + extern int SPACE; + extern int BACKSPACE; + extern int LEFT_CONTROL; + extern int LEFT_SHIFT; + extern int LEFT_ALT; + extern int RIGHT_CONTROL; + extern int RIGHT_SHIFT; + extern int RIGHT_ALT; extern int F1; extern int F2; extern int F3; @@ -42,6 +50,22 @@ namespace keycode { extern int X; extern int Y; extern int Z; + extern int NUM_0; + extern int NUM_1; + extern int NUM_2; + extern int NUM_3; + extern int NUM_4; + extern int NUM_5; + extern int NUM_6; + extern int NUM_7; + extern int NUM_8; + extern int NUM_9; +} + +namespace mousecode { + extern int BUTTON_1; + extern int BUTTON_2; + extern int BUTTON_3; } #endif // WINDOW_INPUT_H_ \ No newline at end of file