#include "player.h"
-void onKeyPressed(unsigned char key, int x, int y) {
+void onKeyboardEvent(GLFWwindow* window, int key, int scancode, int action, int mods) {
switch (key) {
- case 'w':
- playerMovementInput(0.0f, 1.0f);
+ case GLFW_KEY_W:
+ if (action == GLFW_PRESS) {
+ startMovement(DIRECTION_UP);
+ }
+ else if (action == GLFW_RELEASE) {
+ stopMovement(DIRECTION_UP);
+ }
break;
- case 's':
- playerMovementInput(0.0f, -1.0f);
+ case GLFW_KEY_S:
+ if (action == GLFW_PRESS) {
+ startMovement(DIRECTION_DOWN);
+ }
+ else if (action == GLFW_RELEASE) {
+ stopMovement(DIRECTION_DOWN);
+ }
break;
- case 'a':
- playerMovementInput(-1.0f, 0.0f);
+ case GLFW_KEY_A:
+ if (action == GLFW_PRESS) {
+ startMovement(DIRECTION_LEFT);
+ }
+ else if (action == GLFW_RELEASE) {
+ stopMovement(DIRECTION_LEFT);
+ }
break;
- case 'd':
- playerMovementInput(1.0f, 0.0f);
+ case GLFW_KEY_D:
+ if (action == GLFW_PRESS) {
+ startMovement(DIRECTION_RIGHT);
+ }
+ else if (action == GLFW_RELEASE) {
+ stopMovement(DIRECTION_RIGHT);
+ }
break;
default:
break;
}
}
-
-void onKeyboardEvent(GLFWwindow* window, int key, int scancode, int action, int mods) {
- if (action == GLFW_PRESS) {
- switch (key) {
- case GLFW_KEY_W:
- playerMovementInput(0.0f, 1.0f);
- break;
- case GLFW_KEY_S:
- playerMovementInput(0.0f, -1.0f);
- break;
- case GLFW_KEY_A:
- playerMovementInput(-1.0f, 0.0f);
- break;
- case GLFW_KEY_D:
- playerMovementInput(1.0f, 0.0f);
- break;
- default:
- break;
- }
- }
-}