Browse Source

Add second keyboard input mode

Samuel Čavoj 2 years ago
parent
commit
951823dd31
3 changed files with 9 additions and 1 deletions
  1. 1 0
      include/game.h
  2. 1 0
      include/types.h
  3. 7 1
      src/game.cc

+ 1 - 0
include/game.h

@@ -24,6 +24,7 @@ namespace Asteroids {
         AsteroidField asteroid_field;
         ParticleRenderer particle_renderer;
         input_state_t keyboard_inp = {0};
+        input_state_t keyboard_inp2 = {0};
 
         struct {
             struct {

+ 1 - 0
include/types.h

@@ -7,6 +7,7 @@ namespace Asteroids {
 
     enum input_mode_t {
         INPUT_MODE_KEYBOARD,
+        INPUT_MODE_KEYBOARD2,
         INPUT_MODE_GP1,
         INPUT_MODE_GP2,
         INPUT_MODE_GP3,

+ 7 - 1
src/game.cc

@@ -67,13 +67,19 @@ void Game::key_cb(GLFWwindow *window, int key,
         case GLFW_KEY_RIGHT: game->keyboard_inp.right = state * 1.f; break;
         case GLFW_KEY_ESCAPE: glfwSetWindowShouldClose(window, true); break;
         case GLFW_KEY_R: game->asteroid_field.reset_ships(); break;
+        case GLFW_KEY_Q: game->keyboard_inp2.shoot = state; break;
+        case GLFW_KEY_W: game->keyboard_inp2.accelerate = state * 1.f; break;
+        case GLFW_KEY_A: game->keyboard_inp2.left = state * 1.f; break;
+        case GLFW_KEY_D: game->keyboard_inp2.right = state * 1.f; break;
     }
 }
 
 input_state_t Game::get_input(input_mode_t im) {
     if (im == INPUT_MODE_KEYBOARD) {
         return this->keyboard_inp;
-    } else {
+    } else if (im == INPUT_MODE_KEYBOARD2) {
+        return this->keyboard_inp2;
+    }else {
         int jsid = im - 1;
         GLFWgamepadstate gpstate;
         input_state_t s = {0};