Joe Shotton / ll16j23s_test_docs

Files at this revision

API Documentation at this revision

Comitter:
JoeShotton
Date:
Sun Apr 05 19:59:03 2020 +0000
Parent:
24:33639c2eacb3
Child:
26:a596dce2f938
Commit message:
Basic movement implemented with fsm and cell alignment

Changed in this revision

Gamepad.cpp Show annotated file Show diff for this revision Revisions of this file
Gamepad.h Show annotated file Show diff for this revision Revisions of this file
--- a/Gamepad.cpp	Fri Jan 31 10:49:11 2020 +0000
+++ b/Gamepad.cpp	Sun Apr 05 19:59:03 2020 +0000
@@ -196,6 +196,29 @@
     return d;
 }
 
+int Gamepad::get_cardinal()
+{
+    float angle = get_angle();  // 0 to 360, -1 for centred
+
+    int d = 0;
+    // partition 360 into segments and check which segment the angle is in
+    if (angle < 0.0f) {
+        d = 0;   // check for -1.0 angle
+    } else if (angle < 22.5f) {  // then keep going in 45 degree increments
+        d = 1;
+    } else if (angle < 112.5f) {
+        d = 2;
+    } else if (angle < 202.5f) {
+        d = 3;
+    } else if (angle < 292.5f) {
+        d = 4;
+    } else {
+        d = 1;
+    }
+
+    return d;
+}
+
 void Gamepad::reset_buttons()
 {
     A_fall = B_fall = X_fall = Y_fall = start_fall = false;
--- a/Gamepad.h	Fri Jan 31 10:49:11 2020 +0000
+++ b/Gamepad.h	Sun Apr 05 19:59:03 2020 +0000
@@ -145,6 +145,11 @@
     */
     Direction get_direction();    // N,NE,E,SE etc.
 
+    /** CUSTOM: Gets joystick cardinal direction
+    * @returns an integer, 0 for centre, 1 - 4 for NESW respectively
+    */
+    int get_cardinal();
+
     /** Gets raw cartesian co-ordinates of joystick
     * @returns a struct with x,y members, each in the range 0.0 to 1.0
     */