EXAMPLES: Format tweaks
This commit is contained in:
parent
9f07cfe0b7
commit
f0889a74fe
91 changed files with 409 additions and 397 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Mixed audio processing
|
* raylib [audio] example - mixed audio processing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateMusicStream(music); // Update music buffer with new stream data
|
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||||
|
|
||||||
// Restart music playing (stop and play)
|
// Restart music playing (stop and play)
|
||||||
if (IsKeyPressed(KEY_SPACE))
|
if (IsKeyPressed(KEY_SPACE))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Playing spatialized 3D sound
|
* raylib [audio] example - spatialized 3D sound
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
@ -31,9 +31,9 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - Playing spatialized 3D sound");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - spatialized 3D sound");
|
||||||
|
|
||||||
InitAudioDevice();
|
InitAudioDevice();
|
||||||
|
|
||||||
Sound sound = LoadSound("resources/coin.wav");
|
Sound sound = LoadSound("resources/coin.wav");
|
||||||
|
|
@ -45,9 +45,9 @@ int main(void)
|
||||||
.fovy = 60,
|
.fovy = 60,
|
||||||
.projection = CAMERA_PERSPECTIVE
|
.projection = CAMERA_PERSPECTIVE
|
||||||
};
|
};
|
||||||
|
|
||||||
DisableCursor();
|
DisableCursor();
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadSound(sound);
|
UnloadSound(sound);
|
||||||
CloseAudioDevice(); // Close audio device
|
CloseAudioDevice(); // Close audio device
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
@ -100,23 +100,23 @@ static void SetSoundPosition(Camera listener, Sound sound, Vector3 position, flo
|
||||||
// Calculate direction vector and distance between listener and sound source
|
// Calculate direction vector and distance between listener and sound source
|
||||||
Vector3 direction = Vector3Subtract(position, listener.position);
|
Vector3 direction = Vector3Subtract(position, listener.position);
|
||||||
float distance = Vector3Length(direction);
|
float distance = Vector3Length(direction);
|
||||||
|
|
||||||
// Apply logarithmic distance attenuation and clamp between 0-1
|
// Apply logarithmic distance attenuation and clamp between 0-1
|
||||||
float attenuation = 1.0f/(1.0f + (distance/maxDist));
|
float attenuation = 1.0f/(1.0f + (distance/maxDist));
|
||||||
attenuation = Clamp(attenuation, 0.0f, 1.0f);
|
attenuation = Clamp(attenuation, 0.0f, 1.0f);
|
||||||
|
|
||||||
// Calculate normalized vectors for spatial positioning
|
// Calculate normalized vectors for spatial positioning
|
||||||
Vector3 normalizedDirection = Vector3Normalize(direction);
|
Vector3 normalizedDirection = Vector3Normalize(direction);
|
||||||
Vector3 forward = Vector3Normalize(Vector3Subtract(listener.target, listener.position));
|
Vector3 forward = Vector3Normalize(Vector3Subtract(listener.target, listener.position));
|
||||||
Vector3 right = Vector3Normalize(Vector3CrossProduct(listener.up, forward));
|
Vector3 right = Vector3Normalize(Vector3CrossProduct(listener.up, forward));
|
||||||
|
|
||||||
// Reduce volume for sounds behind the listener
|
// Reduce volume for sounds behind the listener
|
||||||
float dotProduct = Vector3DotProduct(forward, normalizedDirection);
|
float dotProduct = Vector3DotProduct(forward, normalizedDirection);
|
||||||
if (dotProduct < 0.0f) attenuation *= (1.0f + dotProduct*0.5f);
|
if (dotProduct < 0.0f) attenuation *= (1.0f + dotProduct*0.5f);
|
||||||
|
|
||||||
// Set stereo panning based on sound position relative to listener
|
// Set stereo panning based on sound position relative to listener
|
||||||
float pan = 0.5f + 0.5f*Vector3DotProduct(normalizedDirection, right);
|
float pan = 0.5f + 0.5f*Vector3DotProduct(normalizedDirection, right);
|
||||||
|
|
||||||
// Apply final sound properties
|
// Apply final sound properties
|
||||||
SetSoundVolume(sound, attenuation);
|
SetSoundVolume(sound, attenuation);
|
||||||
SetSoundPan(sound, pan);
|
SetSoundPan(sound, pan);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ int main(void)
|
||||||
|
|
||||||
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
|
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
|
||||||
bool pause = false; // Music playing paused
|
bool pause = false; // Music playing paused
|
||||||
|
|
||||||
bool enableEffectLPF = false; // Enable effect low-pass-filter
|
bool enableEffectLPF = false; // Enable effect low-pass-filter
|
||||||
bool enableEffectDelay = false; // Enable effect delay (1 second)
|
bool enableEffectDelay = false; // Enable effect delay (1 second)
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ int main(void)
|
||||||
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
||||||
else DetachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
else DetachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get normalized time played for current music stream
|
// Get normalized time played for current music stream
|
||||||
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music);
|
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music);
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ int main(void)
|
||||||
|
|
||||||
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 20, LIGHTGRAY);
|
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 20, LIGHTGRAY);
|
||||||
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 260, 20, LIGHTGRAY);
|
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 260, 20, LIGHTGRAY);
|
||||||
|
|
||||||
DrawText(TextFormat("PRESS F TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), 200, 320, 20, GRAY);
|
DrawText(TextFormat("PRESS F TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), 200, 320, 20, GRAY);
|
||||||
DrawText(TextFormat("PRESS D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY);
|
DrawText(TextFormat("PRESS D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ int main ()
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsKeyPressed(KEY_ONE)) zoomMode = 0;
|
if (IsKeyPressed(KEY_ONE)) zoomMode = 0;
|
||||||
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;
|
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;
|
||||||
|
|
||||||
// Translate based on mouse right click
|
// Translate based on mouse right click
|
||||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
|
||||||
{
|
{
|
||||||
|
|
@ -68,7 +68,7 @@ int main ()
|
||||||
// Set the offset to where the mouse is
|
// Set the offset to where the mouse is
|
||||||
camera.offset = GetMousePosition();
|
camera.offset = GetMousePosition();
|
||||||
|
|
||||||
// Set the target to match, so that the camera maps the world space point
|
// Set the target to match, so that the camera maps the world space point
|
||||||
// under the cursor to the screen space point under the cursor at any zoom
|
// under the cursor to the screen space point under the cursor at any zoom
|
||||||
camera.target = mouseWorldPos;
|
camera.target = mouseWorldPos;
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ int main ()
|
||||||
// Set the offset to where the mouse is
|
// Set the offset to where the mouse is
|
||||||
camera.offset = GetMousePosition();
|
camera.offset = GetMousePosition();
|
||||||
|
|
||||||
// Set the target to match, so that the camera maps the world space point
|
// Set the target to match, so that the camera maps the world space point
|
||||||
// under the cursor to the screen space point under the cursor at any zoom
|
// under the cursor to the screen space point under the cursor at any zoom
|
||||||
camera.target = mouseWorldPos;
|
camera.target = mouseWorldPos;
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +111,7 @@ int main ()
|
||||||
|
|
||||||
BeginMode2D(camera);
|
BeginMode2D(camera);
|
||||||
|
|
||||||
// Draw the 3d grid, rotated 90 degrees and centered around 0,0
|
// Draw the 3d grid, rotated 90 degrees and centered around 0,0
|
||||||
// just so we have something in the XY plane
|
// just so we have something in the XY plane
|
||||||
rlPushMatrix();
|
rlPushMatrix();
|
||||||
rlTranslatef(0, 25*50, 0);
|
rlTranslatef(0, 25*50, 0);
|
||||||
|
|
@ -121,19 +121,19 @@ int main ()
|
||||||
|
|
||||||
// Draw a reference circle
|
// Draw a reference circle
|
||||||
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);
|
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
// Draw mouse reference
|
// Draw mouse reference
|
||||||
//Vector2 mousePos = GetWorldToScreen2D(GetMousePosition(), camera)
|
//Vector2 mousePos = GetWorldToScreen2D(GetMousePosition(), camera)
|
||||||
DrawCircleV(GetMousePosition(), 4, DARKGRAY);
|
DrawCircleV(GetMousePosition(), 4, DARKGRAY);
|
||||||
DrawTextEx(GetFontDefault(), TextFormat("[%i, %i]", GetMouseX(), GetMouseY()),
|
DrawTextEx(GetFontDefault(), TextFormat("[%i, %i]", GetMouseX(), GetMouseY()),
|
||||||
Vector2Add(GetMousePosition(), (Vector2){ -44, -24 }), 20, 2, BLACK);
|
Vector2Add(GetMousePosition(), (Vector2){ -44, -24 }), 20, 2, BLACK);
|
||||||
|
|
||||||
DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY);
|
DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY);
|
||||||
if (zoomMode == 0) DrawText("Mouse left button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY);
|
if (zoomMode == 0) DrawText("Mouse left button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY);
|
||||||
else DrawText("Mouse left button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);
|
else DrawText("Mouse left button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ int main(void)
|
||||||
|
|
||||||
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40.0f, 40.0f };
|
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40.0f, 40.0f };
|
||||||
DrawRectangleRec(playerRect, RED);
|
DrawRectangleRec(playerRect, RED);
|
||||||
|
|
||||||
DrawCircleV(player.position, 5.0f, GOLD);
|
DrawCircleV(player.position, 5.0f, GOLD);
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
* Addapted from the core_3d_camera_split_screen example:
|
* Addapted from the core_3d_camera_split_screen example:
|
||||||
* https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_split_screen.c
|
* https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_split_screen.c
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||||
|
|
@ -81,9 +81,9 @@ int main(void)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginTextureMode(screenCamera1);
|
BeginTextureMode(screenCamera1);
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode2D(camera1);
|
BeginMode2D(camera1);
|
||||||
|
|
||||||
// Draw full scene with first camera
|
// Draw full scene with first camera
|
||||||
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -106,17 +106,17 @@ int main(void)
|
||||||
DrawRectangleRec(player1, RED);
|
DrawRectangleRec(player1, RED);
|
||||||
DrawRectangleRec(player2, BLUE);
|
DrawRectangleRec(player2, BLUE);
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
||||||
DrawText("PLAYER1: W/S/A/D to move", 10, 10, 10, MAROON);
|
DrawText("PLAYER1: W/S/A/D to move", 10, 10, 10, MAROON);
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
BeginTextureMode(screenCamera2);
|
BeginTextureMode(screenCamera2);
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode2D(camera2);
|
BeginMode2D(camera2);
|
||||||
|
|
||||||
// Draw full scene with second camera
|
// Draw full scene with second camera
|
||||||
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -138,21 +138,21 @@ int main(void)
|
||||||
|
|
||||||
DrawRectangleRec(player1, RED);
|
DrawRectangleRec(player1, RED);
|
||||||
DrawRectangleRec(player2, BLUE);
|
DrawRectangleRec(player2, BLUE);
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
||||||
DrawText("PLAYER2: UP/DOWN/LEFT/RIGHT to move", 10, 10, 10, DARKBLUE);
|
DrawText("PLAYER2: UP/DOWN/LEFT/RIGHT to move", 10, 10, 10, DARKBLUE);
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw both views render textures to the screen side by side
|
// Draw both views render textures to the screen side by side
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
DrawTextureRec(screenCamera1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
DrawTextureRec(screenCamera1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
||||||
DrawTextureRec(screenCamera2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
DrawTextureRec(screenCamera2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
||||||
|
|
||||||
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ int main(void)
|
||||||
UpdateCameraPro(&camera,
|
UpdateCameraPro(&camera,
|
||||||
(Vector3){
|
(Vector3){
|
||||||
(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
|
(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
|
||||||
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
|
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
|
||||||
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
|
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
|
||||||
(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
|
(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
|
||||||
0.0f // Move up-down
|
0.0f // Move up-down
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ int main(void)
|
||||||
|
|
||||||
// Build a flipped rectangle the size of the split view to use for drawing later
|
// Build a flipped rectangle the size of the split view to use for drawing later
|
||||||
Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenPlayer1.texture.width, (float)-screenPlayer1.texture.height };
|
Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenPlayer1.texture.width, (float)-screenPlayer1.texture.height };
|
||||||
|
|
||||||
// Grid data
|
// Grid data
|
||||||
int count = 5;
|
int count = 5;
|
||||||
float spacing = 4;
|
float spacing = 4;
|
||||||
|
|
@ -98,9 +98,9 @@ int main(void)
|
||||||
// Draw Player1 view to the render texture
|
// Draw Player1 view to the render texture
|
||||||
BeginTextureMode(screenPlayer1);
|
BeginTextureMode(screenPlayer1);
|
||||||
ClearBackground(SKYBLUE);
|
ClearBackground(SKYBLUE);
|
||||||
|
|
||||||
BeginMode3D(cameraPlayer1);
|
BeginMode3D(cameraPlayer1);
|
||||||
|
|
||||||
// Draw scene: grid of cube trees on a plane to make a "world"
|
// Draw scene: grid of cube trees on a plane to make a "world"
|
||||||
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
||||||
|
|
||||||
|
|
@ -116,20 +116,20 @@ int main(void)
|
||||||
// Draw a cube at each player's position
|
// Draw a cube at each player's position
|
||||||
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
||||||
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
||||||
DrawText("PLAYER1: W/S to move", 10, 10, 20, MAROON);
|
DrawText("PLAYER1: W/S to move", 10, 10, 20, MAROON);
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw Player2 view to the render texture
|
// Draw Player2 view to the render texture
|
||||||
BeginTextureMode(screenPlayer2);
|
BeginTextureMode(screenPlayer2);
|
||||||
ClearBackground(SKYBLUE);
|
ClearBackground(SKYBLUE);
|
||||||
|
|
||||||
BeginMode3D(cameraPlayer2);
|
BeginMode3D(cameraPlayer2);
|
||||||
|
|
||||||
// Draw scene: grid of cube trees on a plane to make a "world"
|
// Draw scene: grid of cube trees on a plane to make a "world"
|
||||||
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
||||||
|
|
||||||
|
|
@ -145,21 +145,21 @@ int main(void)
|
||||||
// Draw a cube at each player's position
|
// Draw a cube at each player's position
|
||||||
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
||||||
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
||||||
DrawText("PLAYER2: UP/DOWN to move", 10, 10, 20, DARKBLUE);
|
DrawText("PLAYER2: UP/DOWN to move", 10, 10, 20, DARKBLUE);
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw both views render textures to the screen side by side
|
// Draw both views render textures to the screen side by side
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
||||||
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
||||||
|
|
||||||
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ int main(void)
|
||||||
player.position = (Vector2){ 400, 280 };
|
player.position = (Vector2){ 400, 280 };
|
||||||
player.speed = 0;
|
player.speed = 0;
|
||||||
player.canJump = false;
|
player.canJump = false;
|
||||||
|
|
||||||
// Define environment elements (platforms)
|
// Define environment elements (platforms)
|
||||||
EnvElement envElements[MAX_ENVIRONMENT_ELEMENTS] = {
|
EnvElement envElements[MAX_ENVIRONMENT_ELEMENTS] = {
|
||||||
{{ 0, 0, 1000, 400 }, 0, LIGHTGRAY },
|
{{ 0, 0, 1000, 400 }, 0, LIGHTGRAY },
|
||||||
|
|
@ -70,13 +70,13 @@ int main(void)
|
||||||
camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
|
camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
|
||||||
camera.rotation = 0.0f;
|
camera.rotation = 0.0f;
|
||||||
camera.zoom = 1.0f;
|
camera.zoom = 1.0f;
|
||||||
|
|
||||||
// Automation events
|
// Automation events
|
||||||
AutomationEventList aelist = LoadAutomationEventList(0); // Initialize list of automation events to record new events
|
AutomationEventList aelist = LoadAutomationEventList(0); // Initialize list of automation events to record new events
|
||||||
SetAutomationEventList(&aelist);
|
SetAutomationEventList(&aelist);
|
||||||
bool eventRecording = false;
|
bool eventRecording = false;
|
||||||
bool eventPlaying = false;
|
bool eventPlaying = false;
|
||||||
|
|
||||||
unsigned int frameCounter = 0;
|
unsigned int frameCounter = 0;
|
||||||
unsigned int playFrameCounter = 0;
|
unsigned int playFrameCounter = 0;
|
||||||
unsigned int currentPlayFrame = 0;
|
unsigned int currentPlayFrame = 0;
|
||||||
|
|
@ -90,7 +90,7 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
float deltaTime = 0.015f;//GetFrameTime();
|
float deltaTime = 0.015f;//GetFrameTime();
|
||||||
|
|
||||||
// Dropped files logic
|
// Dropped files logic
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsFileDropped())
|
if (IsFileDropped())
|
||||||
|
|
@ -102,14 +102,14 @@ int main(void)
|
||||||
{
|
{
|
||||||
UnloadAutomationEventList(aelist);
|
UnloadAutomationEventList(aelist);
|
||||||
aelist = LoadAutomationEventList(droppedFiles.paths[0]);
|
aelist = LoadAutomationEventList(droppedFiles.paths[0]);
|
||||||
|
|
||||||
eventRecording = false;
|
eventRecording = false;
|
||||||
|
|
||||||
// Reset scene state to play
|
// Reset scene state to play
|
||||||
eventPlaying = true;
|
eventPlaying = true;
|
||||||
playFrameCounter = 0;
|
playFrameCounter = 0;
|
||||||
currentPlayFrame = 0;
|
currentPlayFrame = 0;
|
||||||
|
|
||||||
player.position = (Vector2){ 400, 280 };
|
player.position = (Vector2){ 400, 280 };
|
||||||
player.speed = 0;
|
player.speed = 0;
|
||||||
player.canJump = false;
|
player.canJump = false;
|
||||||
|
|
@ -174,7 +174,7 @@ int main(void)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Events playing
|
// Events playing
|
||||||
// NOTE: Logic must be before Camera update because it depends on mouse-wheel value,
|
// NOTE: Logic must be before Camera update because it depends on mouse-wheel value,
|
||||||
// that can be set by the played event... but some other inputs could be affected
|
// that can be set by the played event... but some other inputs could be affected
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (eventPlaying)
|
if (eventPlaying)
|
||||||
|
|
@ -228,7 +228,7 @@ int main(void)
|
||||||
if (min.x > 0) camera.offset.x = screenWidth/2 - min.x;
|
if (min.x > 0) camera.offset.x = screenWidth/2 - min.x;
|
||||||
if (min.y > 0) camera.offset.y = screenHeight/2 - min.y;
|
if (min.y > 0) camera.offset.y = screenHeight/2 - min.y;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Events management
|
// Events management
|
||||||
if (IsKeyPressed(KEY_S)) // Toggle events recording
|
if (IsKeyPressed(KEY_S)) // Toggle events recording
|
||||||
{
|
{
|
||||||
|
|
@ -238,12 +238,12 @@ int main(void)
|
||||||
{
|
{
|
||||||
StopAutomationEventRecording();
|
StopAutomationEventRecording();
|
||||||
eventRecording = false;
|
eventRecording = false;
|
||||||
|
|
||||||
ExportAutomationEventList(aelist, "automation.rae");
|
ExportAutomationEventList(aelist, "automation.rae");
|
||||||
|
|
||||||
TraceLog(LOG_INFO, "RECORDED FRAMES: %i", aelist.count);
|
TraceLog(LOG_INFO, "RECORDED FRAMES: %i", aelist.count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetAutomationEventBaseFrame(180);
|
SetAutomationEventBaseFrame(180);
|
||||||
StartAutomationEventRecording();
|
StartAutomationEventRecording();
|
||||||
|
|
@ -293,7 +293,7 @@ int main(void)
|
||||||
DrawRectangleRec((Rectangle){ player.position.x - 20, player.position.y - 40, 40, 40 }, RED);
|
DrawRectangleRec((Rectangle){ player.position.x - 20, player.position.y - 40, 40, 40 }, RED);
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
// Draw game controls
|
// Draw game controls
|
||||||
DrawRectangle(10, 10, 290, 145, Fade(SKYBLUE, 0.5f));
|
DrawRectangle(10, 10, 290, 145, Fade(SKYBLUE, 0.5f));
|
||||||
DrawRectangleLines(10, 10, 290, 145, Fade(BLUE, 0.8f));
|
DrawRectangleLines(10, 10, 290, 145, Fade(BLUE, 0.8f));
|
||||||
|
|
@ -323,7 +323,7 @@ int main(void)
|
||||||
|
|
||||||
if (((frameCounter/15)%2) == 1) DrawText(TextFormat("PLAYING RECORDED EVENTS... [%i]", currentPlayFrame), 50, 170, 10, DARKGREEN);
|
if (((frameCounter/15)%2) == 1) DrawText(TextFormat("PLAYING RECORDED EVENTS... [%i]", currentPlayFrame), 50, 170, 10, DARKGREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom frame control");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom frame control");
|
||||||
|
|
||||||
// Custom timming variables
|
// Custom timming variables
|
||||||
|
|
@ -48,11 +48,11 @@ int main(void)
|
||||||
double updateDrawTime = 0.0; // Update + Draw time
|
double updateDrawTime = 0.0; // Update + Draw time
|
||||||
double waitTime = 0.0; // Wait time (if target fps required)
|
double waitTime = 0.0; // Wait time (if target fps required)
|
||||||
float deltaTime = 0.0f; // Frame time (Update + Draw + Wait time)
|
float deltaTime = 0.0f; // Frame time (Update + Draw + Wait time)
|
||||||
|
|
||||||
float timeCounter = 0.0f; // Accumulative time counter (seconds)
|
float timeCounter = 0.0f; // Accumulative time counter (seconds)
|
||||||
float position = 0.0f; // Circle position
|
float position = 0.0f; // Circle position
|
||||||
bool pause = false; // Pause control flag
|
bool pause = false; // Pause control flag
|
||||||
|
|
||||||
int targetFPS = 60; // Our initial target fps
|
int targetFPS = 60; // Our initial target fps
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -64,12 +64,12 @@ int main(void)
|
||||||
#ifndef PLATFORM_WEB // NOTE: On non web platforms the PollInputEvents just works before the inputs checks
|
#ifndef PLATFORM_WEB // NOTE: On non web platforms the PollInputEvents just works before the inputs checks
|
||||||
PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
|
PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
|
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_UP)) targetFPS += 20;
|
if (IsKeyPressed(KEY_UP)) targetFPS += 20;
|
||||||
else if (IsKeyPressed(KEY_DOWN)) targetFPS -= 20;
|
else if (IsKeyPressed(KEY_DOWN)) targetFPS -= 20;
|
||||||
|
|
||||||
if (targetFPS < 0) targetFPS = 0;
|
if (targetFPS < 0) targetFPS = 0;
|
||||||
|
|
||||||
if (!pause)
|
if (!pause)
|
||||||
|
|
@ -91,12 +91,12 @@ int main(void)
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
for (int i = 0; i < GetScreenWidth()/200; i++) DrawRectangle(200*i, 0, 1, GetScreenHeight(), SKYBLUE);
|
for (int i = 0; i < GetScreenWidth()/200; i++) DrawRectangle(200*i, 0, 1, GetScreenHeight(), SKYBLUE);
|
||||||
|
|
||||||
DrawCircle((int)position, GetScreenHeight()/2 - 25, 50, RED);
|
DrawCircle((int)position, GetScreenHeight()/2 - 25, 50, RED);
|
||||||
|
|
||||||
DrawText(TextFormat("%03.0f ms", timeCounter*1000.0f), (int)position - 40, GetScreenHeight()/2 - 100, 20, MAROON);
|
DrawText(TextFormat("%03.0f ms", timeCounter*1000.0f), (int)position - 40, GetScreenHeight()/2 - 100, 20, MAROON);
|
||||||
DrawText(TextFormat("PosX: %03.0f", position), (int)position - 50, GetScreenHeight()/2 + 40, 20, BLACK);
|
DrawText(TextFormat("PosX: %03.0f", position), (int)position - 50, GetScreenHeight()/2 + 40, 20, BLACK);
|
||||||
|
|
||||||
DrawText("Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate.", 10, 10, 20, DARKGRAY);
|
DrawText("Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate.", 10, 10, 20, DARKGRAY);
|
||||||
DrawText("PRESS SPACE to PAUSE MOVEMENT", 10, GetScreenHeight() - 60, 20, GRAY);
|
DrawText("PRESS SPACE to PAUSE MOVEMENT", 10, GetScreenHeight() - 60, 20, GRAY);
|
||||||
DrawText("PRESS UP | DOWN to CHANGE TARGET FPS", 10, GetScreenHeight() - 30, 20, GRAY);
|
DrawText("PRESS UP | DOWN to CHANGE TARGET FPS", 10, GetScreenHeight() - 30, 20, GRAY);
|
||||||
|
|
@ -108,18 +108,18 @@ int main(void)
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
// NOTE: In case raylib is configured to SUPPORT_CUSTOM_FRAME_CONTROL,
|
// NOTE: In case raylib is configured to SUPPORT_CUSTOM_FRAME_CONTROL,
|
||||||
// Events polling, screen buffer swap and frame time control must be managed by the user
|
// Events polling, screen buffer swap and frame time control must be managed by the user
|
||||||
|
|
||||||
SwapScreenBuffer(); // Flip the back buffer to screen (front buffer)
|
SwapScreenBuffer(); // Flip the back buffer to screen (front buffer)
|
||||||
|
|
||||||
currentTime = GetTime();
|
currentTime = GetTime();
|
||||||
updateDrawTime = currentTime - previousTime;
|
updateDrawTime = currentTime - previousTime;
|
||||||
|
|
||||||
if (targetFPS > 0) // We want a fixed frame rate
|
if (targetFPS > 0) // We want a fixed frame rate
|
||||||
{
|
{
|
||||||
waitTime = (1.0f/(float)targetFPS) - updateDrawTime;
|
waitTime = (1.0f/(float)targetFPS) - updateDrawTime;
|
||||||
if (waitTime > 0.0)
|
if (waitTime > 0.0)
|
||||||
{
|
{
|
||||||
WaitTime((float)waitTime);
|
WaitTime((float)waitTime);
|
||||||
currentTime = GetTime();
|
currentTime = GetTime();
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,10 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color)
|
//------------------------------------------------------------------------------------
|
||||||
{
|
// Module functions declaration
|
||||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, (float)fontSize, 3);
|
//------------------------------------------------------------------------------------
|
||||||
Vector2 pos = (Vector2){x - size.x/2, y - size.y/2 };
|
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color);
|
||||||
DrawTextEx(GetFontDefault(), text, pos, (float)fontSize, 3, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
|
|
@ -31,10 +29,20 @@ int main(void)
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi");
|
||||||
SetWindowMinSize(450, 450);
|
SetWindowMinSize(450, 450);
|
||||||
|
|
||||||
|
int logicalGridDescY = 120;
|
||||||
|
int logicalGridLabelY = logicalGridDescY + 30;
|
||||||
|
int logicalGridTop = logicalGridLabelY + 30;
|
||||||
|
int logicalGridBottom = logicalGridTop + 80;
|
||||||
|
int pixelGridTop = logicalGridBottom - 20;
|
||||||
|
int pixelGridBottom = pixelGridTop + 80;
|
||||||
|
int pixelGridLabelY = pixelGridBottom + 30;
|
||||||
|
int pixelGridDescY = pixelGridLabelY + 30;
|
||||||
|
int cellSize = 50;
|
||||||
|
float cellSizePx = (float)cellSize;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -44,67 +52,60 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
int monitorCount = GetMonitorCount();
|
int monitorCount = GetMonitorCount();
|
||||||
if (monitorCount > 1 && IsKeyPressed(KEY_N)) {
|
|
||||||
SetWindowMonitor((GetCurrentMonitor() + 1) % monitorCount);
|
if ((monitorCount > 1) && IsKeyPressed(KEY_N))
|
||||||
|
{
|
||||||
|
SetWindowMonitor((GetCurrentMonitor() + 1)%monitorCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
int currentMonitor = GetCurrentMonitor();
|
int currentMonitor = GetCurrentMonitor();
|
||||||
|
Vector2 dpiScale = GetWindowScaleDPI();
|
||||||
|
cellSizePx = ((float)cellSize)/dpiScale.x;
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
Vector2 dpiScale = GetWindowScaleDPI();
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
int windowCenter = GetScreenWidth() / 2;
|
int windowCenter = GetScreenWidth()/2;
|
||||||
DrawTextCenter(TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, DARKGRAY);
|
DrawTextCenter(TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, DARKGRAY);
|
||||||
DrawTextCenter(TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 16, LIGHTGRAY);
|
DrawTextCenter(TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 20, LIGHTGRAY);
|
||||||
|
|
||||||
const int logicalGridDescY = 120;
|
|
||||||
const int logicalGridLabelY = logicalGridDescY + 30;
|
|
||||||
const int logicalGridTop = logicalGridLabelY + 30;
|
|
||||||
const int logicalGridBottom = logicalGridTop + 80;
|
|
||||||
const int pixelGridTop = logicalGridBottom - 20;
|
|
||||||
const int pixelGridBottom = pixelGridTop + 80;
|
|
||||||
const int pixelGridLabelY = pixelGridBottom + 30;
|
|
||||||
const int pixelGridDescY = pixelGridLabelY + 30;
|
|
||||||
|
|
||||||
const int cellSize = 50;
|
|
||||||
const float cellSizePx = ((float)cellSize) / dpiScale.x;
|
|
||||||
|
|
||||||
DrawTextCenter(TextFormat("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE);
|
DrawTextCenter(TextFormat("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE);
|
||||||
|
|
||||||
bool odd = true;
|
bool odd = true;
|
||||||
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) {
|
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd)
|
||||||
if (odd) {
|
{
|
||||||
DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
|
if (odd) DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
|
||||||
}
|
|
||||||
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 12, LIGHTGRAY);
|
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 10, LIGHTGRAY);
|
||||||
DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY);
|
DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
odd = true;
|
odd = true;
|
||||||
const int minTextSpace = 30;
|
const int minTextSpace = 30;
|
||||||
int last_text_x = -minTextSpace;
|
int lastTextX = -minTextSpace;
|
||||||
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) {
|
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd)
|
||||||
int x = (int)(((float)i) / dpiScale.x);
|
{
|
||||||
if (odd) {
|
int x = (int)(((float)i)/dpiScale.x);
|
||||||
DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom-pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
|
if (odd) DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom - pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
|
||||||
}
|
|
||||||
DrawLine(x, pixelGridTop, (int)(((float)i) / dpiScale.x), pixelGridLabelY - 10, GRAY);
|
DrawLine(x, pixelGridTop, (int)(((float)i) / dpiScale.x), pixelGridLabelY - 10, GRAY);
|
||||||
if (x - last_text_x >= minTextSpace) {
|
|
||||||
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 12, LIGHTGRAY);
|
if ((x - lastTextX) >= minTextSpace)
|
||||||
last_text_x = x;
|
{
|
||||||
|
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 10, LIGHTGRAY);
|
||||||
|
lastTextX = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
|
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
|
||||||
|
|
||||||
{
|
const char *text = "Can you see this?";
|
||||||
const char *text = "Can you see this?";
|
Vector2 size = MeasureTextEx(GetFontDefault(), text, 20, 3);
|
||||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, 16, 3);
|
Vector2 pos = (Vector2){ GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5 };
|
||||||
Vector2 pos = (Vector2){GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5};
|
DrawTextEx(GetFontDefault(), text, pos, 20, 3, LIGHTGRAY);
|
||||||
DrawTextEx(GetFontDefault(), text, pos, 16, 3, LIGHTGRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -117,3 +118,13 @@ int main(void)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module functions definition
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color)
|
||||||
|
{
|
||||||
|
Vector2 size = MeasureTextEx(GetFontDefault(), text, (float)fontSize, 3);
|
||||||
|
Vector2 pos = (Vector2){ x - size.x/2, y - size.y/2 };
|
||||||
|
DrawTextEx(GetFontDefault(), text, pos, (float)fontSize, 3, color);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ int main(void)
|
||||||
isCursorHidden = 0;
|
isCursorHidden = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ballPosition = GetMousePosition();
|
ballPosition = GetMousePosition();
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) ballColor = MAROON;
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) ballColor = MAROON;
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ int main(void)
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
for (int i = 0; i < tCount; ++i)
|
for (int i = 0; i < tCount; ++i)
|
||||||
{
|
{
|
||||||
// Make sure point is not (0, 0) as this means there is no touch for it
|
// Make sure point is not (0, 0) as this means there is no touch for it
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
* Example originally created with raylib 5.0, last time updated with raylib 5.0
|
* Example originally created with raylib 5.0, last time updated with raylib 5.0
|
||||||
*
|
*
|
||||||
* Example create by GreenSnakeLinux (@GreenSnakeLinux),
|
* Example create by GreenSnakeLinux (@GreenSnakeLinux),
|
||||||
* lighter by oblerion (@oblerion) and
|
* lighter by oblerion (@oblerion) and
|
||||||
* reviewed by Ramon Santamaria (@raysan5) and
|
* reviewed by Ramon Santamaria (@raysan5) and
|
||||||
* improved by danilwhale (@danilwhale)
|
* improved by danilwhale (@danilwhale)
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires linking with pthreads library on MinGW,
|
* NOTE: This example requires linking with pthreads library on MinGW,
|
||||||
* it can be accomplished passing -static parameter to compiler
|
* it can be accomplished passing -static parameter to compiler
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 3.0
|
* Example originally created with raylib 2.5, last time updated with raylib 3.0
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Generates a random sequence
|
* raylib [core] example - generate random sequence
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
@ -43,7 +43,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - Generates a random sequence");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random sequence");
|
||||||
|
|
||||||
int rectCount = 20;
|
int rectCount = 20;
|
||||||
float rectSize = (float)screenWidth/rectCount;
|
float rectSize = (float)screenWidth/rectCount;
|
||||||
|
|
@ -118,8 +118,8 @@ int main(void)
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
static Color GenerateRandomColor()
|
static Color GenerateRandomColor()
|
||||||
{
|
{
|
||||||
Color color = {
|
Color color = {
|
||||||
GetRandomValue(0, 255),
|
GetRandomValue(0, 255),
|
||||||
GetRandomValue(0, 255),
|
GetRandomValue(0, 255),
|
||||||
GetRandomValue(0, 255),
|
GetRandomValue(0, 255),
|
||||||
255
|
255
|
||||||
|
|
@ -138,20 +138,20 @@ static ColorRect *GenerateRandomColorRectSequence(float rectCount, float rectWid
|
||||||
for (int i = 0; i < rectCount; i++)
|
for (int i = 0; i < rectCount; i++)
|
||||||
{
|
{
|
||||||
int rectHeight = (int)Remap((float)seq[i], 0, rectCount - 1, 0, screenHeight);
|
int rectHeight = (int)Remap((float)seq[i], 0, rectCount - 1, 0, screenHeight);
|
||||||
|
|
||||||
rectangles[i].c = GenerateRandomColor();
|
rectangles[i].c = GenerateRandomColor();
|
||||||
rectangles[i].r = CLITERAL(Rectangle){ startX + i*rectWidth, screenHeight - rectHeight, rectWidth, (float)rectHeight };
|
rectangles[i].r = CLITERAL(Rectangle){ startX + i*rectWidth, screenHeight - rectHeight, rectWidth, (float)rectHeight };
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadRandomSequence(seq);
|
UnloadRandomSequence(seq);
|
||||||
|
|
||||||
return rectangles;
|
return rectangles;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
|
static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
|
||||||
{
|
{
|
||||||
int *seq = LoadRandomSequence(rectCount, 0, rectCount - 1);
|
int *seq = LoadRandomSequence(rectCount, 0, rectCount - 1);
|
||||||
|
|
||||||
for (int i1 = 0; i1 < rectCount; i1++)
|
for (int i1 = 0; i1 < rectCount; i1++)
|
||||||
{
|
{
|
||||||
ColorRect *r1 = &rectangles[i1];
|
ColorRect *r1 = &rectangles[i1];
|
||||||
|
|
@ -166,16 +166,16 @@ static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
|
||||||
r2->r.height = tmp.r.height;
|
r2->r.height = tmp.r.height;
|
||||||
r2->r.y = tmp.r.y;
|
r2->r.y = tmp.r.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadRandomSequence(seq);
|
UnloadRandomSequence(seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawTextCenterKeyHelp(const char *key, const char *text, int posX, int posY, int fontSize, Color color)
|
static void DrawTextCenterKeyHelp(const char *key, const char *text, int posX, int posY, int fontSize, Color color)
|
||||||
{
|
{
|
||||||
int spaceSize = MeasureText(" ", fontSize);
|
int spaceSize = MeasureText(" ", fontSize);
|
||||||
int pressSize = MeasureText("Press", fontSize);
|
int pressSize = MeasureText("Press", fontSize);
|
||||||
int keySize = MeasureText(key, fontSize);
|
int keySize = MeasureText(key, fontSize);
|
||||||
int textSize = MeasureText(text, fontSize);
|
int textSize = MeasureText(text, fontSize);
|
||||||
int textSizeCurrent = 0;
|
int textSizeCurrent = 0;
|
||||||
|
|
||||||
DrawText("Press", posX, posY, fontSize, color);
|
DrawText("Press", posX, posY, fontSize, color);
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ int main(void)
|
||||||
// SetRandomSeed(0xaabbccff); // Set a custom random seed if desired, by default: "time(NULL)"
|
// SetRandomSeed(0xaabbccff); // Set a custom random seed if desired, by default: "time(NULL)"
|
||||||
|
|
||||||
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
|
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
|
||||||
|
|
||||||
unsigned int framesCounter = 0; // Variable used to count frames
|
unsigned int framesCounter = 0; // Variable used to count frames
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 3.7, last time updated with raylib 4.0
|
* Example originally created with raylib 3.7, last time updated with raylib 4.0
|
||||||
*
|
*
|
||||||
* Example contributed by Giancamillo Alessandroni (@NotManyIdeasDev) and
|
* Example contributed by Giancamillo Alessandroni (@NotManyIdeasDev) and
|
||||||
* reviewed by Ramon Santamaria (@raysan5)
|
* reviewed by Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ int main(void)
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
EndVrStereoMode();
|
EndVrStereoMode();
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
BeginShaderMode(distortion);
|
BeginShaderMode(distortion);
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue