Updated some examples with inconsistencies

This commit is contained in:
Ray
2025-09-04 18:57:00 +02:00
parent fb42819eab
commit 7646d08751
12 changed files with 71 additions and 39 deletions

View File

@ -2,12 +2,16 @@
*
* raylib [core] example - high dpi
*
* Example complexity rating: [★☆☆] e/4
* Example complexity rating: [★☆☆] 2/4
*
* Example originally created with raylib 5.5-dev, last time updated with raylib 5.6-dev
*
* Example contributed by Jonathan Marler (@marler8997) and reviewed by Ramon Santamaria (@raysan5)
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2013-2025 Ramon Santamaria (@raysan5)
* Copyright (c) 2025 Jonathan Marler (@marler8997)
*
********************************************************************************************/

View File

@ -6,10 +6,8 @@
*
* Example originally created with raylib 5.0, last time updated with raylib 5.0
*
* Example create by GreenSnakeLinux (@GreenSnakeLinux),
* lighter by oblerion (@oblerion) and
* reviewed by Ramon Santamaria (@raysan5) and
* improved by danilwhale (@danilwhale)
* Example contributed by GreenSnakeLinux (@GreenSnakeLinux),
* reviewed by Ramon Santamaria (@raysan5), oblerion (@oblerion) and danilwhale (@danilwhale)
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
@ -19,6 +17,7 @@
********************************************************************************************/
#include "raylib.h"
#include <math.h>
typedef enum {
@ -45,24 +44,21 @@ int main(void)
Vector2 padPosition = { 100, 350 };
float buttonRadius = 30;
Vector2 buttonPositions[BUTTON_MAX] =
{
Vector2 buttonPositions[BUTTON_MAX] = {
{ padPosition.x,padPosition.y - buttonRadius*1.5f }, // Up
{ padPosition.x - buttonRadius*1.5f, padPosition.y }, // Left
{ padPosition.x + buttonRadius*1.5f, padPosition.y }, // Right
{ padPosition.x, padPosition.y + buttonRadius*1.5f } // Down
};
const char *buttonLabels[BUTTON_MAX] =
{
const char *buttonLabels[BUTTON_MAX] = {
"Y", // Up
"X", // Left
"B", // Right
"A" // Down
};
Color buttonLabelColors[BUTTON_MAX] =
{
Color buttonLabelColors[BUTTON_MAX] = {
YELLOW, // Up
BLUE, // Left
RED, // Right
@ -83,22 +79,15 @@ int main(void)
{
// Update
//--------------------------------------------------------------------------
if ((GetTouchPointCount() > 0))
{
// Use touch position
inputPosition = GetTouchPosition(0);
}
else
{
// Use mouse position
inputPosition = GetMousePosition();
}
if ((GetTouchPointCount() > 0)) inputPosition = GetTouchPosition(0); // Use touch position
else inputPosition = GetMousePosition(); // Use mouse position
// Reset pressed button to none
pressedButton = BUTTON_NONE;
// Make sure user is pressing left mouse button if they're from desktop
if ((GetTouchPointCount() > 0) || ((GetTouchPointCount() == 0) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)))
if ((GetTouchPointCount() > 0) ||
((GetTouchPointCount() == 0) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)))
{
// Find nearest D-Pad button to the input position
for (int i = 0; i < BUTTON_MAX; i++)
@ -123,8 +112,8 @@ int main(void)
case BUTTON_DOWN: playerPosition.y += playerSpeed*GetFrameTime(); break;
default: break;
};
//--------------------------------------------------------------------------
// Draw
//--------------------------------------------------------------------------
BeginDrawing();
@ -157,4 +146,3 @@ int main(void)
return 0;
}