REVIEWED: New examples on VS project

This commit is contained in:
Ray
2025-10-15 19:59:28 +02:00
parent 4ba92f8962
commit 8e052b81b4
20 changed files with 3098 additions and 76 deletions

View File

@@ -4,7 +4,7 @@
*
* Example complexity rating: [★★☆☆] 2/4
*
* Example originally created with raylib 5.5
* Example originally created with raylib 5.5, last time updated with raylib 5.6-dev
*
* Example contributed by JP Mortiboys (@themushroompirates) and reviewed by Ramon Santamaria (@raysan5)
*

View File

@@ -31,7 +31,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - Draw a mouse trail");
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - mouse trail");
// Array to store the history of mouse positions (our fixed-size queue)
Vector2 trailPositions[MAX_TRAIL_LENGTH] = { 0 };

View File

@@ -2,9 +2,9 @@
*
* raylib [shapes] example - pie chart
*
* Example complexity rating: [★☆☆] 2/4
* Example complexity rating: [★☆☆] 1/4
*
* Example originally created with raylib 5.6-dev, last time updated with raylib 5.6-dev
* Example originally created with raylib 5.5, last time updated with raylib 5.6
*
* Example contributed by Gideon Serfontein (@GideonSerf) and reviewed by Ramon Santamaria (@raysan5)
*
@@ -32,7 +32,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - interactive pie chart");
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - pie chart");
#define MAX_SLICES 10
int sliceCount = 7;

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [shapes] example - shapes recursive tree
* raylib [shapes] example - recursive tree
*
* Example complexity rating: [★★★☆] 3/4
*
@@ -11,7 +11,7 @@
* 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) 2018-2025 Jopestpe (@jopestpe)
* Copyright (c) 2025 Jopestpe (@jopestpe)
*
********************************************************************************************/
@@ -46,7 +46,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - shapes recursive tree");
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - recursive tree");
Vector2 start = { (screenWidth/2.0f) - 125.0f, (float)screenHeight };
float angle = 40.0f;

View File

@@ -31,16 +31,17 @@ typedef enum ParticleType {
FIRE
} ParticleType;
static const char particleTypesChar[3][10] = { "WATER", "SMOKE", "FIRE" };
static const char particleTypeNames[3][10] = { "WATER", "SMOKE", "FIRE" };
typedef struct Particle {
ParticleType type; // Particle type (WATER, SMOKE, FIRE)
Vector2 position; // Particle position on screen
Vector2 velocity; // Particle current speed and direction
bool alive; // Particle alive: inside screen and life time
float lifeTime; // Particle life time
ParticleType type; // Particle type (WATER, SMOKE, FIRE)
float radius; // Particle radius
Color color; // Particle color
float lifeTime; // Particle life time
bool alive; // Particle alive: inside screen and life time
} Particle;
typedef struct CircularBuffer {
@@ -68,7 +69,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - particles");
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - simple particles");
// Definition of particles
Particle *particles = (Particle*)RL_CALLOC(MAX_PARTICLES, sizeof(Particle)); // Particle array
@@ -90,13 +91,11 @@ int main(void)
// Emit new particles: when emissionRate is 1, emit every frame
if (emissionRate < 0)
{
if (rand()%(-emissionRate) == 0)
EmitParticle(&circularBuffer, emitterPosition, currentType);
if (rand()%(-emissionRate) == 0) EmitParticle(&circularBuffer, emitterPosition, currentType);
}
else
{
for (int i = 0; i <= emissionRate; ++i)
EmitParticle(&circularBuffer, emitterPosition, currentType);
for (int i = 0; i <= emissionRate; ++i) EmitParticle(&circularBuffer, emitterPosition, currentType);
}
// Update the parameters of each particle
@@ -105,43 +104,37 @@ int main(void)
UpdateCircularBuffer(&circularBuffer);
// Change Particle Emission Rate (UP/DOWN arrows)
if (IsKeyPressed(KEY_UP))
++emissionRate;
if (IsKeyPressed(KEY_DOWN))
--emissionRate;
if (IsKeyPressed(KEY_UP)) emissionRate++;
if (IsKeyPressed(KEY_DOWN)) emissionRate--;
// Change Particle Type (LEFT/RIGHT arrows)
if (IsKeyPressed(KEY_RIGHT))
(currentType == FIRE) ? (currentType = WATER) : ++currentType;
if (IsKeyPressed(KEY_LEFT))
(currentType == WATER) ? (currentType = FIRE) : --currentType;
if (IsKeyPressed(KEY_RIGHT)) (currentType == FIRE)? (currentType = WATER) : currentType++;
if (IsKeyPressed(KEY_LEFT)) (currentType == WATER)? (currentType = FIRE) : currentType--;
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
emitterPosition = GetMousePosition();
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) emitterPosition = GetMousePosition();
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
ClearBackground(RAYWHITE);
// Call the function with a loop to draw all particles
DrawParticles(&circularBuffer);
// Call the function with a loop to draw all particles
DrawParticles(&circularBuffer);
// Draw UI and Instructions
DrawRectangle(5, 5, 315, 75, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(5, 5, 315, 75, BLUE);
// Draw UI and Instructions
DrawRectangle(5, 5, 315, 75, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(5, 5, 315, 75, BLUE);
DrawText("CONTROLS:", 15, 15, 10, BLACK);
DrawText("UP/DOWN: Change Particle Emission Rate", 15, 35, 10, BLACK);
DrawText("LEFT/RIGHT: Change Particle Type (Water, Smoke, Fire)", 15, 55, 10, BLACK);
DrawText("CONTROLS:", 15, 15, 10, BLACK);
DrawText("UP/DOWN: Change Particle Emission Rate", 15, 35, 10, BLACK);
DrawText("LEFT/RIGHT: Change Particle Type (Water, Smoke, Fire)", 15, 55, 10, BLACK);
if (emissionRate < 0)
DrawText(TextFormat("Particles every %d frames | Type: %s", -emissionRate, particleTypesChar[currentType]), 15, 95, 10, DARKGRAY);
else
DrawText(TextFormat("%d Particles per frame | Type: %s", emissionRate + 1, particleTypesChar[currentType]), 15, 95, 10, DARKGRAY);
if (emissionRate < 0) DrawText(TextFormat("Particles every %d frames | Type: %s", -emissionRate, particleTypeNames[currentType]), 15, 95, 10, DARKGRAY);
else DrawText(TextFormat("%d Particles per frame | Type: %s", emissionRate + 1, particleTypeNames[currentType]), 15, 95, 10, DARKGRAY);
DrawFPS(screenWidth - 80, 10);
DrawFPS(screenWidth - 80, 10);
EndDrawing();
//----------------------------------------------------------------------------------
@@ -163,6 +156,7 @@ int main(void)
static void EmitParticle(CircularBuffer *circularBuffer, Vector2 emitterPosition, ParticleType type)
{
Particle *newParticle = AddToCircularBuffer(circularBuffer);
// If buffer is full, newParticle is NULL
if (newParticle != NULL)
{
@@ -174,21 +168,25 @@ static void EmitParticle(CircularBuffer *circularBuffer, Vector2 emitterPosition
float speed = (float)(rand()%10)/5.0f;
switch (type)
{
case WATER:
newParticle->radius = 5.0f;
newParticle->color = BLUE;
break;
case SMOKE:
newParticle->radius = 7.0f;
newParticle->color = GRAY;
break;
case FIRE:
newParticle->radius = 10.0f;
newParticle->color = YELLOW;
speed /= 10.0f;
break;
default: break;
case WATER:
{
newParticle->radius = 5.0f;
newParticle->color = BLUE;
} break;
case SMOKE:
{
newParticle->radius = 7.0f;
newParticle->color = GRAY;
} break;
case FIRE:
{
newParticle->radius = 10.0f;
newParticle->color = YELLOW;
speed /= 10.0f;
} break;
default: break;
}
float direction = (float)(rand()%360);
newParticle->velocity = (Vector2){ speed*cosf(direction*DEG2RAD), speed*sinf(direction*DEG2RAD) };
}
@@ -253,6 +251,7 @@ static void UpdateParticles(CircularBuffer *circularBuffer, int screenWidth, int
circularBuffer->buffer[i].alive = false;
}
}
static void UpdateCircularBuffer(CircularBuffer *circularBuffer)
{
// Update circular buffer: advance tail over dead particles

View File

@@ -1,10 +1,10 @@
/*******************************************************************************************
*
* raylib [shapes] example - simple starfield
* raylib [shapes] example - starfield
*
* Example complexity rating: [★☆☆☆] 1/4
*
* Example originally created with raylib 5.5
* Example originally created with raylib 5.5, last time updated with raylib 5.6-dev
*
* Example contributed by JP Mortiboys (@themushroompirates) and reviewed by Ramon Santamaria (@raysan5)
*

View File

@@ -11,7 +11,7 @@
* 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) 2018-2025 Jopestpe (@jopestpe)
* Copyright (c) 2025 Jopestpe (@jopestpe)
*
********************************************************************************************/