Streetwalrus Einstein 10 anni fa
parent
commit
f2c536fba2

+ 17 - 0
platform/include/Input.h

@@ -0,0 +1,17 @@
+#ifndef INCLUDE_INPUT_H
+#define INCLUDE_INPUT_H
+
+namespace WalrusRPG
+{
+    namespace Input
+    {
+        bool key_a();
+        bool key_b();
+        bool key_up();
+        bool key_down();
+        bool key_left();
+        bool key_right();
+    }
+}
+
+#endif

+ 34 - 0
platform/nspire/Input.cpp

@@ -0,0 +1,34 @@
+#include "Input.h"
+#include <libndls.h>
+
+#define INPUT WalrusRPG::Input
+
+bool INPUT::key_a()
+{
+    return isKeyPressed(KEY_NSPIRE_ENTER);
+}
+
+bool INPUT::key_b()
+{
+    return isKeyPressed(KEY_NSPIRE_ESC);
+}
+
+bool INPUT::key_up()
+{
+    return isKeyPressed(KEY_NSPIRE_8);
+}
+
+bool INPUT::key_down()
+{
+    return isKeyPressed(KEY_NSPIRE_5);
+}
+
+bool INPUT::key_left()
+{
+    return isKeyPressed(KEY_NSPIRE_4);
+}
+
+bool INPUT::key_right()
+{
+    return isKeyPressed(KEY_NSPIRE_6);
+}

+ 3 - 3
src/engine/StateMachine.cpp

@@ -1,10 +1,10 @@
-#include <libndls.h>
 #include "StateMachine.h"
 #include "Timing.h"
 #include "platform.h"
 #include "Graphics.h"
 #include "render/Text.h"
 #include "version.h"
+#include "Input.h"
 
 using namespace WalrusRPG::Graphics;
 using namespace WalrusRPG::States;
@@ -60,9 +60,9 @@ void STATEMACHINE::run()
             Graphics::frame_end();
         }
 
-        if (isKeyPressed(KEY_NSPIRE_ESC))
+        if (Input::key_b())
         {
-            while (isKeyPressed(KEY_NSPIRE_ESC))
+            while (Input::key_b())
                 ;
             this->pop();
         }

+ 7 - 5
src/render/Camera.cpp

@@ -1,9 +1,11 @@
-#include <libndls.h>
 #include "Camera.h"
 #include "utility/misc.h"
+#include "Input.h"
 
 #define CAMERA WalrusRPG::Camera
 
+using namespace WalrusRPG;
+
 CAMERA::Camera(signed x, signed y)
 {
     this->x = x;
@@ -28,13 +30,13 @@ void CAMERA::update(unsigned dt)
                 velocity += acceleration * dt;
          */
 
-    if (isKeyPressed(KEY_NSPIRE_5))
+    if (Input::key_down())
         y++;
-    if (isKeyPressed(KEY_NSPIRE_8))
+    if (Input::key_up())
         y--;
-    if (isKeyPressed(KEY_NSPIRE_6))
+    if (Input::key_right())
         x++;
-    if (isKeyPressed(KEY_NSPIRE_4))
+    if (Input::key_left())
         x--;
 }