blob: fca64daf74e3fb41cb9c3a586e858d697c13a8c1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include "pong.h"
/* Checks what button the player is pressing amongst all control inputs. */
int player_controls() {
if( IsMouseButtonDown(MOUSE_LEFT_BUTTON) || IsKeyDown(KEY_SPACE) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_RIGHT_FACE_DOWN) ) {
return(CONTROLLER_ACTIVATE);
} else if( IsKeyDown(KEY_ESCAPE) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_MIDDLE_RIGHT) ) {
return(CONTROLLER_PAUSE);
} else if( IsKeyDown(KEY_A) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_LEFT_FACE_LEFT) ) {
return(CONTROLLER_LEFT);
} else if( IsKeyDown(KEY_D) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_LEFT_FACE_RIGHT) ) {
return(CONTROLLER_RIGHT);
} else if( IsKeyDown(KEY_W) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_LEFT_FACE_UP) ) {
return(CONTROLLER_UP);
} else if( IsKeyDown(KEY_S) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_LEFT_FACE_DOWN) ) {
return(CONTROLLER_DOWN);
}
return(-1);
}
/* Same as player_controls() but check if the button was pressed, rather than held down. */
int player_controls_pressed() {
if( IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsKeyPressed(KEY_SPACE) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_RIGHT_FACE_DOWN) ) {
return(CONTROLLER_ACTIVATE);
} else if( IsKeyPressed(KEY_ESCAPE) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_MIDDLE_RIGHT) ) {
return(CONTROLLER_PAUSE);
} else if( IsKeyPressed(KEY_A) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_LEFT) ) {
return(CONTROLLER_LEFT);
} else if( IsKeyPressed(KEY_D) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_RIGHT) ) {
return(CONTROLLER_RIGHT);
} else if( IsKeyPressed(KEY_W) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_UP) ) {
return(CONTROLLER_UP);
} else if( IsKeyPressed(KEY_S) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_DOWN) ) {
return(CONTROLLER_DOWN);
}
return(-1);
}
|