Skip to content

Commit 85f8485

Browse files
SilverNexus2QuzarDC
authored andcommitted
Per change request, add exit condition to the example.
A, B, X, Y, and Start pressed together terminates the example.
1 parent 9d513f6 commit 85f8485

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

  • examples/dreamcast/raylib/texture2d

examples/dreamcast/raylib/texture2d/main.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,27 @@ int main() {
183183
}
184184
}
185185
EndDrawing();
186+
187+
// Check the inputs for an exit combination of ABXYStart on every controller port
188+
// A more complicated program would likely want to decouple input checks from framerate,
189+
// which this example accomplishes by putting the input check in the same loop as drawing.
190+
for (int i = 0; i < 4; ++i) {
191+
// Assuming gamepad 0 is the primary controller
192+
if(IsGamepadAvailable(i)){
193+
int a_pressed = IsGamepadButtonDown(i, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
194+
int b_pressed = IsGamepadButtonDown(i, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT);
195+
int x_pressed = IsGamepadButtonDown(i, GAMEPAD_BUTTON_RIGHT_FACE_LEFT);
196+
int y_pressed = IsGamepadButtonDown(i, GAMEPAD_BUTTON_RIGHT_FACE_UP);
197+
int start_pressed = IsGamepadButtonDown(i, GAMEPAD_BUTTON_MIDDLE_RIGHT);
198+
199+
// Now we do the check. We don't really care what controller presses the combo,
200+
// only that some controller presses the combo.
201+
if (a_pressed && b_pressed && x_pressed && y_pressed && start_pressed) {
202+
// I think this directly closes the window, which should escape the loop
203+
CloseWindow();
204+
}
205+
}
206+
}
186207
}
187208

188209
// Cleanup. Even thought we shouldn't reach here under normal circumstances.

0 commit comments

Comments
 (0)