Files
raylib-speedruns/c/main.c

57 lines
1.4 KiB
C

#include <stdio.h>
#include <time.h>
#include <raylib.h>
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define LOGO_HEIGHT 64
#define LOGO_SPEED 300
int main()
{
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in C");
SetTargetFPS(60);
SetRandomSeed(time(NULL));
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 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);
while (!WindowShouldClose())
{
float delta_time = GetFrameTime();
x += dx * delta_time;
y += dy * delta_time;
if (x < 0 || (x + logo_texture.width) >= WINDOW_WIDTH - 1)
{
dx *= -1;
x += dx * delta_time;
}
if (y < 0 || (y + logo_texture.height) >= WINDOW_HEIGHT - 1)
{
dy *= -1;
y += dy * delta_time;
}
BeginDrawing();
ClearBackground(BLACK);
DrawTextureV(logo_texture, (Vector2){x, y}, WHITE);
EndDrawing();
}
UnloadTexture(logo_texture);
CloseWindow();
return 0;
}