mirror of
https://github.com/raysan5/raylib.git
synced 2026-10-10 19:51:55 -04:00
Compare commits
3 Commits
b927f1b2b1
...
425e58ced9
| Author | SHA1 | Date | |
|---|---|---|---|
| 425e58ced9 | |||
| 77967288d1 | |||
| d0cec73467 |
@ -600,6 +600,7 @@ SHAPES = \
|
||||
shapes/shapes_dashed_line \
|
||||
shapes/shapes_digital_clock \
|
||||
shapes/shapes_double_pendulum \
|
||||
shapes/shapes_drag_puzzle \
|
||||
shapes/shapes_easings_ball \
|
||||
shapes/shapes_easings_box \
|
||||
shapes/shapes_easings_rectangles \
|
||||
|
||||
@ -561,6 +561,7 @@ SHAPES = \
|
||||
shapes/shapes_dashed_line \
|
||||
shapes/shapes_digital_clock \
|
||||
shapes/shapes_double_pendulum \
|
||||
shapes/shapes_drag_puzzle \
|
||||
shapes/shapes_easings_ball \
|
||||
shapes/shapes_easings_box \
|
||||
shapes/shapes_easings_rectangles \
|
||||
@ -921,6 +922,9 @@ shapes/shapes_digital_clock: shapes/shapes_digital_clock.c
|
||||
shapes/shapes_double_pendulum: shapes/shapes_double_pendulum.c
|
||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||
|
||||
shapes/shapes_drag_puzzle: shapes/shapes_drag_puzzle.c
|
||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||
|
||||
shapes/shapes_easings_ball: shapes/shapes_easings_ball.c
|
||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||
|
||||
|
||||
@ -13,11 +13,13 @@ The examples assume you have already built the `raylib` library in `../src`.
|
||||
The [Zig](https://ziglang.org/) toolchain can compile `C` and `C++` in addition to `Zig`.
|
||||
You may find it easier to use than other toolchains, especially when it comes to cross-compiling.
|
||||
|
||||
- `zig build` to compile all examples
|
||||
Run the following commands from the repository root:
|
||||
|
||||
- `zig build examples` to compile all examples
|
||||
- `zig build [module]` to compile all examples for a module (e.g. `zig build core`)
|
||||
- `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`)
|
||||
|
||||
## EXAMPLES COLLECTION [TOTAL: 212]
|
||||
## EXAMPLES COLLECTION [TOTAL: 213]
|
||||
|
||||
### category: core [49]
|
||||
|
||||
@ -75,7 +77,7 @@ Examples using raylib [core](../src/rcore.c) module platform functionality: wind
|
||||
| [core_keyboard_testbed](core/core_keyboard_testbed.c) | <img src="core/core_keyboard_testbed.png" alt="core_keyboard_testbed" width="80"> | ⭐⭐☆☆ | 5.6 | 5.6 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||
| [core_window_web](core/core_window_web.c) | <img src="core/core_window_web.png" alt="core_window_web" width="80"> | ⭐☆☆☆ | 1.3 | 5.5 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||
|
||||
### category: shapes [40]
|
||||
### category: shapes [41]
|
||||
|
||||
Examples using raylib shapes drawing functionality, provided by raylib [shapes](../src/rshapes.c) module.
|
||||
|
||||
@ -121,6 +123,7 @@ Examples using raylib shapes drawing functionality, provided by raylib [shapes](
|
||||
| [shapes_penrose_tile](shapes/shapes_penrose_tile.c) | <img src="shapes/shapes_penrose_tile.png" alt="shapes_penrose_tile" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 6.0 | [David Buzatto](https://github.com/davidbuzatto) |
|
||||
| [shapes_hilbert_curve](shapes/shapes_hilbert_curve.c) | <img src="shapes/shapes_hilbert_curve.png" alt="shapes_hilbert_curve" width="80"> | ⭐⭐⭐☆ | 5.6 | 5.6 | [Hamza RAHAL](https://github.com/hmz-rhl) |
|
||||
| [shapes_easings_testbed](shapes/shapes_easings_testbed.c) | <img src="shapes/shapes_easings_testbed.png" alt="shapes_easings_testbed" width="80"> | ⭐⭐⭐☆ | 2.5 | 2.5 | [Juan Miguel López](https://github.com/flashback-fx) |
|
||||
| [shapes_drag_puzzle](shapes/shapes_drag_puzzle.c) | <img src="shapes/shapes_drag_puzzle.png" alt="shapes_drag_puzzle" width="80"> | ⭐☆☆☆ | 6.0 | 6.0 | [Gabriel Piangers](https://github.com/gabriel-piangers) |
|
||||
|
||||
### category: textures [32]
|
||||
|
||||
|
||||
@ -98,6 +98,7 @@ shapes;shapes_ball_physics;★★☆☆;6.0;6.0;2025;2025;"David Buzatto";@david
|
||||
shapes;shapes_penrose_tile;★★★★;5.5;6.0;2025;2025;"David Buzatto";@davidbuzatto
|
||||
shapes;shapes_hilbert_curve;★★★☆;5.6;5.6;2025;2025;"Hamza RAHAL";@hmz-rhl
|
||||
shapes;shapes_easings_testbed;★★★☆;2.5;2.5;2019;2025;"Juan Miguel López";@flashback-fx
|
||||
shapes;shapes_drag_puzzle;★☆☆☆;6.0;6.0;2026;2026;"Gabriel Piangers";@gabriel-piangers
|
||||
textures;textures_clipboard_image;★☆☆☆;6.0;6.0;2026;2026;"Maicon Santana";@maiconpintoabreu
|
||||
textures;textures_magnifying_glass;★★★☆;5.6;5.6;2026;2026;"Luke Vaughan";@badram
|
||||
textures;textures_logo_raylib;★☆☆☆;1.0;1.0;2014;2025;"Ramon Santamaria";@raysan5
|
||||
@ -130,6 +131,7 @@ textures;textures_textured_curve;★★★☆;4.5;4.5;2022;2025;"Jeffery Myers";
|
||||
textures;textures_sprite_stacking;★★☆☆;6.0;6.0;2025;2025;"Robin";@RobinsAviary
|
||||
textures;textures_cellular_automata;★★☆☆;5.6;5.6;2025;2025;"Jordi Santonja";@JordSant
|
||||
textures;textures_framebuffer_rendering;★★☆☆;5.6;5.6;2026;2026;"Jack Boakes";@jackboakes
|
||||
textures;textures_portal_window;★★★★;6.0;6.0;2025;2025;"PanicTitan";@PanicTitan
|
||||
text;text_sprite_fonts;★☆☆☆;1.7;3.7;2017;2025;"Ramon Santamaria";@raysan5
|
||||
text;text_font_spritefont;★☆☆☆;1.0;1.0;2014;2025;"Ramon Santamaria";@raysan5
|
||||
text;text_font_filters;★★☆☆;1.3;4.2;2015;2025;"Ramon Santamaria";@raysan5
|
||||
@ -221,3 +223,5 @@ audio;audio_sound_multi;★★☆☆;5.0;5.0;2023;2025;"Jeffery Myers";@JeffM250
|
||||
audio;audio_sound_positioning;★★☆☆;5.5;5.5;2025;2025;"Le Juez Victor";@Bigfoot71
|
||||
audio;audio_spectrum_visualizer;★★★☆;6.0;6.0;2025;2025;"IANN";@meisei4
|
||||
audio;audio_stream_callback;★★★☆;6.0;6.0;2026;2026;"Dan Hoang";@dan-hoang
|
||||
|
||||
oang
|
||||
|
||||
164
examples/shapes/shapes_drag_puzzle.c
Normal file
164
examples/shapes/shapes_drag_puzzle.c
Normal file
@ -0,0 +1,164 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shapes] example - drag puzzle
|
||||
*
|
||||
* Example complexity rating: [★☆☆☆] 1/4
|
||||
*
|
||||
* Example originally created with raylib 6.0, last time updated with raylib 6.0
|
||||
*
|
||||
* Example contributed by Gabriel Piangers (@gabriel-piangers) 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) 2026 Gabriel Piangers (@gabriel-piangers)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
Vector2 center;
|
||||
float radius;
|
||||
} Circle;
|
||||
|
||||
typedef struct {
|
||||
Vector2 v1;
|
||||
Vector2 v2;
|
||||
Vector2 v3;
|
||||
} Triangle;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - drag puzzle");
|
||||
|
||||
// Rectangle
|
||||
Rectangle rec = { screenWidth/2 - 250, screenHeight/2 + 50, 100.0f, 100.0f };
|
||||
Rectangle recArea = { screenWidth/2 - 60, screenHeight/2 - 110, 110.0f, 110.0f };
|
||||
bool recPickedUp = false;
|
||||
|
||||
// Circle
|
||||
Circle circ = { screenWidth/2, screenHeight/2 + 100, 50.0f };
|
||||
Circle circArea = { screenWidth/2 - 195, screenHeight/2 - 55, 55.0f };
|
||||
bool circPickedUp = false;
|
||||
|
||||
// Triangle
|
||||
Triangle tri = { { 600, 282 }, { 550, 369 }, { 650, 369 } };
|
||||
Triangle triArea = { { 600, 115 }, { 540, 222 }, { 660, 222 } };
|
||||
bool triPickedUp = false;
|
||||
|
||||
Vector2 mouseOffset = { 0.0f, 0.0f }; // Stores the offset of the mouse relative to the object's pivot point
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
Vector2 mousePosition = GetMousePosition();
|
||||
bool recPlaced = false;
|
||||
bool circPlaced = false;
|
||||
bool triPlaced = false;
|
||||
|
||||
// Detect object pickup input
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointRec(mousePosition, rec))
|
||||
{
|
||||
recPickedUp = true;
|
||||
mouseOffset = (Vector2) { rec.x - mousePosition.x, rec.y - mousePosition.y };
|
||||
}
|
||||
else if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointCircle(mousePosition, circ.center, circ.radius))
|
||||
{
|
||||
circPickedUp = true;
|
||||
mouseOffset = (Vector2) { circ.center.x - mousePosition.x, circ.center.y - mousePosition.y };
|
||||
}
|
||||
else if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointTriangle(mousePosition, tri.v1, tri.v2, tri.v3))
|
||||
{
|
||||
triPickedUp = true;
|
||||
mouseOffset = (Vector2) { tri.v1.x - mousePosition.x, tri.v1.y - mousePosition.y }; // Uses v1 as the pivot point
|
||||
}
|
||||
|
||||
// Detect object drop input
|
||||
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && recPickedUp) recPickedUp = false;
|
||||
else if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && circPickedUp) circPickedUp = false;
|
||||
else if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && triPickedUp) triPickedUp = false;
|
||||
|
||||
// Rectangle update
|
||||
if (recPickedUp)
|
||||
{
|
||||
rec.x = mousePosition.x + mouseOffset.x;
|
||||
rec.y = mousePosition.y + mouseOffset.y;
|
||||
}
|
||||
Rectangle RecCol = GetCollisionRec(recArea, rec);
|
||||
if (RecCol.width == rec.width && RecCol.height == rec.height) recPlaced = true;
|
||||
|
||||
// Circle update
|
||||
if (circPickedUp)
|
||||
{
|
||||
circ.center.x = mousePosition.x + mouseOffset.x;
|
||||
circ.center.y = mousePosition.y + mouseOffset.y;
|
||||
}
|
||||
if (Vector2Distance(circ.center, circArea.center) < circArea.radius - circ.radius) circPlaced = true;
|
||||
|
||||
// Triangle update
|
||||
if (triPickedUp)
|
||||
{
|
||||
Vector2 v2Offset = { tri.v2.x - tri.v1.x, tri.v2.y - tri.v1.y };
|
||||
Vector2 v3Offset = { tri.v3.x - tri.v1.x, tri.v3.y - tri.v1.y };
|
||||
|
||||
tri.v1 = (Vector2) { mousePosition.x + mouseOffset.x, mousePosition.y + mouseOffset.y };
|
||||
tri.v2 = (Vector2) { tri.v1.x + v2Offset.x, tri.v1.y + v2Offset.y };
|
||||
tri.v3 = (Vector2) { tri.v1.x + v3Offset.x, tri.v1.y + v3Offset.y };
|
||||
}
|
||||
if (
|
||||
CheckCollisionPointTriangle(tri.v1, triArea.v1, triArea.v2, triArea.v3) &&
|
||||
CheckCollisionPointTriangle(tri.v2, triArea.v1, triArea.v2, triArea.v3) &&
|
||||
CheckCollisionPointTriangle(tri.v2, triArea.v1, triArea.v2, triArea.v3)
|
||||
) triPlaced = true;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawRectangleLinesEx(recArea, 2.0f, recPlaced ? GREEN : RED);
|
||||
DrawCircleLinesEx(circArea.center, circArea.radius, 2.0f, circPlaced ? GREEN : RED);
|
||||
DrawTriangleLinesEx(triArea.v1, triArea.v2, triArea.v3, 2.0f, triPlaced ? GREEN : RED);
|
||||
|
||||
// Draws objects that are not picked up first
|
||||
if (!triPickedUp) DrawTriangle(tri.v1, tri.v2, tri.v3, VIOLET);
|
||||
if (!circPickedUp) DrawCircleV(circ.center, circ.radius, BLUE);
|
||||
if (!recPickedUp) DrawRectangleRec(rec, ORANGE);
|
||||
|
||||
// Draws the object that is being dragged on top of others
|
||||
if (triPickedUp) DrawTriangle(tri.v1, tri.v2, tri.v3, VIOLET);
|
||||
if (circPickedUp) DrawCircleV(circ.center, circ.radius, BLUE);
|
||||
if (recPickedUp) DrawRectangleRec(rec, ORANGE);
|
||||
|
||||
DrawText("Use mouse to drag and drop the objects into the right spot!", 10, 10, 20, GRAY);
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
examples/shapes/shapes_drag_puzzle.png
Normal file
BIN
examples/shapes/shapes_drag_puzzle.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.9 KiB |
@ -432,7 +432,7 @@ int SDL_GetNumTouchFingers(SDL_TouchID touchID)
|
||||
// SDL_GetClipboardData function is available since SDL 3.1.3. (e.g. SDL3)
|
||||
void *SDL_GetClipboardData(const char *mime_type, size_t *size)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SDL: Getting clipboard data that is not text not available in SDL2");
|
||||
TRACELOG(LOG_WARNING, "SDL: Getting clipboard data that is not text is not available in SDL2");
|
||||
|
||||
// TODO: Implement getting clipboard data
|
||||
|
||||
|
||||
@ -197,7 +197,7 @@ static const int evkeyToUnicodeLUT[] = {
|
||||
// NOTE: Use short here to save a little memory
|
||||
static const short linuxToRaylibMap[KEYMAP_SIZE] = {
|
||||
// Don't map with designated initialization,
|
||||
// it will geenrate many naming conflicts
|
||||
// it will generate many naming conflicts
|
||||
0, 256, 49, 50, 51, 52, 53, 54,
|
||||
55, 56, 57, 48, 45, 61, 259, 258,
|
||||
81, 87, 69, 82, 84, 89, 85, 73,
|
||||
@ -2210,7 +2210,7 @@ static void PollKeyboardEvents(void)
|
||||
// If the event was a key, assume a working keyboard is connected, so disable the SSH keyboard
|
||||
platform.eventKeyboardMode = true;
|
||||
#endif
|
||||
// Keyboard keys appear for codes 1 to 255, ignore everthing else
|
||||
// Keyboard keys appear for codes 1 to 255, ignore everything else
|
||||
if ((event.code >= 1) && (event.code <= 255))
|
||||
{
|
||||
// Lookup the scancode in the keymap to get a keycode
|
||||
|
||||
Reference in New Issue
Block a user