Input changes

This commit is contained in:
2022-07-10 00:25:07 +02:00
parent e4ac76be59
commit d2d5666aa5

View File

@@ -2,41 +2,34 @@
extern float pos[3]; extern float pos[3];
/* 0: escape /* 0: nothing
* 1: W * 1: W
* 2: S * 2: S
* 3: * 3: A
* 4: D
*/ */
static bool pressed[5]; static bool pressed[5];
static int index;
void key_pressed(GLFWwindow* window, int key, int scancode, int action, int mods){ void key_pressed(GLFWwindow* window, int key, int scancode, int action, int mods){
if ( key == GLFW_KEY_ESCAPE && action == GLFW_PRESS){ if ( key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, true);
glfwSetWindowShouldClose(window, true); if ( key == GLFW_KEY_Q && action == GLFW_PRESS ) glfwSetWindowShouldClose(window, true);
}
if ( key == GLFW_KEY_Q && action == GLFW_PRESS ){ index = 0;
glfwSetWindowShouldClose(window, true); if ( key == GLFW_KEY_W ) index = 1;
} if ( key == GLFW_KEY_S ) index = 2;
if ( key == GLFW_KEY_W && action == GLFW_PRESS ){ if ( key == GLFW_KEY_A ) index = 3;
pressed[1] = true; if ( key == GLFW_KEY_D ) index = 4;
}
if ( key == GLFW_KEY_W && action == GLFW_RELEASE ){ if ( action == GLFW_PRESS ) pressed[index] = true;
pressed[1] = false; if ( action == GLFW_RELEASE ) pressed[index] = false;
}
if ( key == GLFW_KEY_S && action == GLFW_PRESS ){
pressed[2] = true;
}
if ( key == GLFW_KEY_S && action == GLFW_RELEASE ) {
pressed[2] = false;
}
} }
void processInput(){ void processInput(){
if (pressed[1] == true){ if (pressed[1] == true) pos[1] += 0.01f;
pos[1] += 0.01f; if (pressed[2] == true) pos[1] -= 0.01f;
} if (pressed[3] == true) pos[0] -= 0.01f;
if (pressed[2] == true){ if (pressed[4] == true) pos[0] += 0.01f;
pos[1] -= 0.01f;
}
} }