about summary refs log tree commit diff stats
path: root/src/controls.c
blob: a3cefa1dfa686edc11d5ac7e65a7a8384ab889ea (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
38
39
40
41
42
43
44
45
46
#include "pong.h"
#include <raylib.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() {
	int ReturnVal = -1;
	if( IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsKeyPressed(KEY_SPACE) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_RIGHT_FACE_DOWN) ) {
		ReturnVal = CONTROLLER_ACTIVATE;
	} else if( IsKeyPressed(KEY_ESCAPE) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_MIDDLE_RIGHT) ) {
		ReturnVal = CONTROLLER_PAUSE;
	} else if( IsKeyPressed(KEY_A) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_LEFT) ) {
		ReturnVal = CONTROLLER_LEFT;
	} else if( IsKeyPressed(KEY_D) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_RIGHT) ) {
		ReturnVal = CONTROLLER_RIGHT;
	} else if( IsKeyPressed(KEY_W) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_UP) ) {
		ReturnVal = CONTROLLER_UP;
	} else if( IsKeyPressed(KEY_S) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_DOWN) ) {
		ReturnVal = CONTROLLER_DOWN;
	}
	return(ReturnVal);
}

/* Calls BeginDrawing() and EndDrawing() to clear input buffer. */
void clear_input_buffer() {
	BeginDrawing();
	EndDrawing();
	return;
}