diff options
Diffstat (limited to 'src/input.c')
| -rw-r--r-- | src/input.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/input.c b/src/input.c new file mode 100644 index 0000000..6ac092f --- /dev/null +++ b/src/input.c @@ -0,0 +1,85 @@ +#include "input.h" + +joypad_buttons_t pressed_p1; +joypad_buttons_t held_p1; +joypad_inputs_t inputs_p1; + +void updateController() +{ + joypad_poll(); + pressed_p1 = joypad_get_buttons_pressed(JOYPAD_PORT_1); + held_p1 = joypad_get_buttons_held(JOYPAD_PORT_1); + inputs_p1 = joypad_get_inputs(JOYPAD_PORT_1); + + + float x = inputs_p1.stick_x; + float y = inputs_p1.stick_y; + + if(x > 60) + { + x = 60.0f; + } + else if(x < -60) + { + x = -60.0f; + } + else if((x > -5) && (x < 5)) + { + x = 0.0f; + } + + if(y > 60) + { + y = 60; + } + else if(y < -60) + { + y = -60; + } + else if((y > -5) && (y < 5)) + { + y = 0; + } + + if(x > 0) + { + x -= 5; + } + else if(x < 0) + { + x += 5; + } + + if(y > 0) + { + y -= 5; + } + else if(y < 0) + { + y += 5; + } + + //float distance = sqrtf((x * x) + (y * y)); + + //char text[500]; + //char text2[500]; + //char text3[500]; + //sprintf(text, "x %f", x); + //sprintf(text2, "y %f", y); + //sprintf(text3, "d %f", distance); + //DrawText(text, 100, 10, 12, GREEN); + //DrawText(text2, 100, 30, 12, GREEN); + //DrawText(text3, 100, 60, 12, GREEN); + + /* + if(distance != 0) + { + inputs_p1.stick_x = (x / distance) * 127.0f; + inputs_p1.stick_y = (y / distance) * 127.0f; + } + */ + + inputs_p1.stick_x = x / 55.0f * 127.0f; + inputs_p1.stick_y = y / 55.0f * 127.0f; + +} |
