Ver a proveniência

Update textures_sprite_stacking.c

pull/5365/head
Ray há 1 mês
ascendente
cometimento
8fcd99c8dd
1 ficheiros alterados com 20 adições e 30 eliminações
  1. +20
    -30
      examples/textures/textures_sprite_stacking.c

+ 20
- 30
examples/textures/textures_sprite_stacking.c Ver ficheiro

@ -17,7 +17,8 @@
********************************************************************************************/ ********************************************************************************************/
#include "raylib.h" #include "raylib.h"
#include "raymath.h"
#include "raymath.h" // Required for: Clamp()
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Program main entry point // Program main entry point
@ -33,18 +34,14 @@ int main(void)
Texture2D booth = LoadTexture("resources/booth.png"); Texture2D booth = LoadTexture("resources/booth.png");
// The overall scale of the stacked sprite
float stackScale = 3.0f;
// The vertical spacing between each layer
float stackSpacing = 2.0f;
// The number of layers. Used for calculating the size of a single slice
unsigned int stackCount = 122;
// The speed to rotate the stacked sprite
float rotationSpeed = 30.0f;
// The current rotation of the stacked sprite
float rotation = 0.0f;
// The amount that speed will change by when the user presses A/D
const float speedChange = 0.25f;
float stackScale = 3.0f; // Overall scale of the stacked sprite
float stackSpacing = 2.0f; // Vertical spacing between each layer
unsigned int stackCount = 122; // Number of layers, used for calculating the size of a single slice
float rotationSpeed = 30.0f; // Stacked sprites rotation speed
float rotation = 0.0f; // Current rotation of the stacked sprite
const float speedChange = 0.25f; // Amount speed will change by when the user presses A/D
SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
@ -57,22 +54,16 @@ int main(void)
stackSpacing = Clamp(stackSpacing, 0.0f, 5.0f); stackSpacing = Clamp(stackSpacing, 0.0f, 5.0f);
// Add a positive/negative offset to spin right/left at different speeds // Add a positive/negative offset to spin right/left at different speeds
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A))
{
rotationSpeed -= speedChange;
}
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D))
{
rotationSpeed += speedChange;
}
rotation += rotationSpeed * GetFrameTime();
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) rotationSpeed -= speedChange;
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) rotationSpeed += speedChange;
rotation += rotationSpeed*GetFrameTime();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// Get the size of a single slice // Get the size of a single slice
@ -86,20 +77,19 @@ int main(void)
// Draw the stacked sprite, rotated to the correct angle, with an vertical offset applied based on its y location // Draw the stacked sprite, rotated to the correct angle, with an vertical offset applied based on its y location
for (int i = stackCount - 1; i >= 0; i--) for (int i = stackCount - 1; i >= 0; i--)
{ {
Rectangle source = { 0.0f, (float)i*frameHeight, frameWidth, frameHeight };
// Center vertically // Center vertically
Rectangle source = { 0.0f, (float)i*frameHeight, frameWidth, frameHeight };
Rectangle dest = { screenWidth/2.0f, (screenHeight/2.0f) + (i*stackSpacing) - (stackSpacing*stackCount/2.0f), scaledWidth, scaledHeight }; Rectangle dest = { screenWidth/2.0f, (screenHeight/2.0f) + (i*stackSpacing) - (stackSpacing*stackCount/2.0f), scaledWidth, scaledHeight };
Vector2 origin = { scaledWidth/2.0f, scaledHeight/2.0f }; Vector2 origin = { scaledWidth/2.0f, scaledHeight/2.0f };
DrawTexturePro(booth, source, dest, origin, rotation, WHITE); DrawTexturePro(booth, source, dest, origin, rotation, WHITE);
} }
DrawText("a/d to spin\nmouse wheel to change separation (aka 'angle')", 10, 10, 20, DARKGRAY);
const char *spacingText = TextFormat("current spacing: %.01f", stackSpacing);
DrawText(spacingText, 10, 50, 20, DARKGRAY);
const char *speedText = TextFormat("current speed: %.02f", rotationSpeed);
DrawText(speedText, 10, 70, 20, DARKGRAY);
DrawText("A/D to spin\nmouse wheel to change separation (aka 'angle')", 10, 10, 20, DARKGRAY);
DrawText(TextFormat("current spacing: %.01f", stackSpacing), 10, 50, 20, DARKGRAY);
DrawText(TextFormat("current speed: %.02f", rotationSpeed), 10, 70, 20, DARKGRAY);
DrawText("redbooth model (c) kluchek under cc 4.0", 10, 420, 20, DARKGRAY); DrawText("redbooth model (c) kluchek under cc 4.0", 10, 420, 20, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }

Carregando…
Cancelar
Guardar