New method Input_GetKeyDir, to get direction with only the keys.

This commit is contained in:
2021-05-02 05:01:43 +02:00
committed by Valeriano A.R
parent 7aeafd4f32
commit 5d185aa480
2 changed files with 40 additions and 5 deletions

View File

@@ -113,9 +113,7 @@ void Input_SetPointerDown(int pointerDown) {
///////////////////////////// /////////////////////////////
// Input_GetPointerDown // Input_GetPointerDown
// //
int Input_GetPointerDown(){ int Input_GetPointerDown() { return _pointerDown; }
return _pointerDown;
}
///////////////////////////// /////////////////////////////
// Input_GetPointerPosition // Input_GetPointerPosition
@@ -152,7 +150,7 @@ int Input_AnyKey() {
///////////////////////////// /////////////////////////////
// Input_GetDir // Input_GetDir
// //
// Reports the direction of the dpad. // Reports the direction of the dpad and mouse.
int Input_GetDir(vec2 dir) { int Input_GetDir(vec2 dir) {
float vlen; float vlen;
Uint8 buttons; Uint8 buttons;
@@ -193,3 +191,34 @@ int Input_GetDir(vec2 dir) {
} }
} }
} }
/////////////////////////////
// Input_GetKeyDir
//
// Reports the direction of the dpad.
int Input_GetKeyDir(vec2 dir) {
float vlen;
// Use the keyboard
vec2_set(dir, 0.0f, 0.0f);
if (Input_GetKey(InputKey_Up)) {
dir[1] -= 1.0f;
}
if (Input_GetKey(InputKey_Down)) {
dir[1] += 1.0f;
}
if (Input_GetKey(InputKey_Left)) {
dir[0] -= 1.0f;
}
if (Input_GetKey(InputKey_Right)) {
dir[0] += 1.0f;
}
vlen = vec2_dot(dir, dir);
if (vlen > 0.0f) {
vlen = sqrtf(vlen);
vec2_scale(dir, dir, 1.0f / vlen);
return (1);
} else {
return (0);
}
}

View File

@@ -99,7 +99,13 @@ int Input_AnyKey();
///////////////////////////// /////////////////////////////
// Input_GetDir // Input_GetDir
// //
// Reports the direction of the dpad. // Reports the direction of the dpad and mouse.
int Input_GetDir(vec2 dir); int Input_GetDir(vec2 dir);
/////////////////////////////
// Input_GetKeyDir
//
// Reports the direction of the dpad.
int Input_GetKeyDir(vec2 dir);
#endif #endif