1717
1818// Simple example for decoding input as actions, allowing remapping of input to different keys or gamepad buttons
1919// For example instead of using `IsKeyDown(KEY_LEFT)`, you can use `IsActionDown(ACTION_LEFT)`
20- // which can be reassigned to e.g. KEY_A and also assigned to a gamepad button. the action will trigger with either gamepad or keys
20+ // which can be reassigned to e.g. KEY_A and also assigned to a gamepad button. the action will trigger with either gamepad or keys
2121
2222#include "raylib.h"
2323
@@ -44,7 +44,7 @@ typedef struct ActionInput {
4444// Global Variables Definition
4545//----------------------------------------------------------------------------------
4646static int gamepadIndex = 0 ; // Gamepad default index
47- static ActionInput actionInputs [MAX_ACTION ] = { 0 };
47+ static ActionInput actionInputs [MAX_ACTION ] = { 0 };
4848
4949//----------------------------------------------------------------------------------
5050// Module Functions Declaration
@@ -67,15 +67,15 @@ int main(void)
6767 const int screenHeight = 450 ;
6868
6969 InitWindow (screenWidth , screenHeight , "raylib [core] example - input actions" );
70-
71- // Set default actions
70+
71+ // Set default actions
7272 char actionSet = 0 ;
7373 SetActionsDefault ();
7474 bool releaseAction = false;
7575
7676 Vector2 position = (Vector2 ){ 400.0f , 200.0f };
7777 Vector2 size = (Vector2 ){ 40.0f , 40.0f };
78-
78+
7979 SetTargetFPS (60 );
8080 //--------------------------------------------------------------------------------------
8181
@@ -85,7 +85,7 @@ int main(void)
8585 // Update
8686 //----------------------------------------------------------------------------------
8787 gamepadIndex = 0 ; // Set gamepad being checked
88-
88+
8989 if (IsActionDown (ACTION_UP )) position .y -= 2 ;
9090 if (IsActionDown (ACTION_DOWN )) position .y += 2 ;
9191 if (IsActionDown (ACTION_LEFT )) position .x -= 2 ;
@@ -95,12 +95,12 @@ int main(void)
9595 position .x = (screenWidth - size .x )/2 ;
9696 position .y = (screenHeight - size .y )/2 ;
9797 }
98-
98+
9999 // Register release action for one frame
100100 releaseAction = false;
101101 if (IsActionReleased (ACTION_FIRE )) releaseAction = true;
102102
103- // Switch control scheme by pressing TAB
103+ // Switch control scheme by pressing TAB
104104 if (IsKeyPressed (KEY_TAB ))
105105 {
106106 actionSet = !actionSet ;
@@ -116,7 +116,7 @@ int main(void)
116116 ClearBackground (GRAY );
117117
118118 DrawRectangleV (position , size , releaseAction ? BLUE : RED );
119-
119+
120120 DrawText ((actionSet == 0 )? "Current input set: WASD (default)" : "Current input set: Cursor" , 10 , 10 , 20 , WHITE );
121121 DrawText ("Use TAB key to toggles Actions keyset" , 10 , 50 , 20 , GREEN );
122122
@@ -140,9 +140,9 @@ int main(void)
140140static bool IsActionPressed (int action )
141141{
142142 bool result = false;
143-
143+
144144 if (action < MAX_ACTION ) result = (IsKeyPressed (actionInputs [action ].key ) || IsGamepadButtonPressed (gamepadIndex , actionInputs [action ].button ));
145-
145+
146146 return result ;
147147}
148148
@@ -151,20 +151,20 @@ static bool IsActionPressed(int action)
151151static bool IsActionReleased (int action )
152152{
153153 bool result = false;
154-
154+
155155 if (action < MAX_ACTION ) result = (IsKeyReleased (actionInputs [action ].key ) || IsGamepadButtonReleased (gamepadIndex , actionInputs [action ].button ));
156-
156+
157157 return result ;
158158}
159159
160160// Check action key/button down
161161// NOTE: Combines key down and gamepad button down in one action
162- static bool IsActionDown (int action )
162+ static bool IsActionDown (int action )
163163{
164164 bool result = false;
165-
165+
166166 if (action < MAX_ACTION ) result = (IsKeyDown (actionInputs [action ].key ) || IsGamepadButtonDown (gamepadIndex , actionInputs [action ].button ));
167-
167+
168168 return result ;
169169}
170170
0 commit comments