refactor: constant logo height instead of using scale

This commit is contained in:
2026-03-11 19:06:11 +01:00
parent 96a26cea5c
commit 54f2fc9bd4
6 changed files with 126 additions and 81 deletions

View File

@@ -4,7 +4,7 @@
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define LOGO_SCALE 0.04f
#define LOGO_HEIGHT 64
#define LOGO_SPEED 300
int main()
@@ -13,13 +13,13 @@ int main()
SetTargetFPS(60);
SetRandomSeed(time(NULL));
Texture2D logo_texture = LoadTexture("./c_logo.png");
Image logo_image = LoadImage("./c_logo.png");
ImageResize(&logo_image, logo_image.width * LOGO_HEIGHT / logo_image.height, LOGO_HEIGHT);
Texture2D logo_texture = LoadTextureFromImage(logo_image);
UnloadImage(logo_image);
float logo_width = logo_texture.width * LOGO_SCALE;
float logo_height = logo_texture.height * LOGO_SCALE;
float x = GetRandomValue(0, WINDOW_WIDTH - logo_width);
float y = GetRandomValue(0, WINDOW_HEIGHT - logo_height);
float x = GetRandomValue(0, WINDOW_WIDTH - logo_texture.width);
float y = GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height);
float dx = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
float dy = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
@@ -31,12 +31,12 @@ int main()
x += dx * delta_time;
y += dy * delta_time;
if (x < 0 || (x + logo_width) >= WINDOW_WIDTH - 1)
if (x < 0 || (x + logo_texture.width) >= WINDOW_WIDTH - 1)
{
dx *= -1;
x += dx * delta_time;
}
if (y < 0 || (y + logo_height) >= WINDOW_HEIGHT - 1)
if (y < 0 || (y + logo_texture.height) >= WINDOW_HEIGHT - 1)
{
dy *= -1;
y += dy * delta_time;
@@ -45,7 +45,7 @@ int main()
BeginDrawing();
ClearBackground(BLACK);
DrawTextureEx(logo_texture, (Vector2){x, y}, 0, LOGO_SCALE, WHITE);
DrawTextureV(logo_texture, (Vector2){x, y}, WHITE);
EndDrawing();
}