feat(c): implement
This commit is contained in:
2
c/Makefile
Normal file
2
c/Makefile
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
raylib_c: main.c
|
||||||
|
gcc main.c -Wall -Wextra -Werror -pedantic -o raylib_c -I../_raylib-5.5_linux_amd64/include -L../_raylib-5.5_linux_amd64/lib -l:libraylib.a -lm
|
||||||
8
c/README.md
Normal file
8
c/README.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Raylib in C
|
||||||
|
|
||||||
|
## Quick start
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ make
|
||||||
|
$ ./raylib_c
|
||||||
|
```
|
||||||
BIN
c/c_logo.png
Normal file
BIN
c/c_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 108 KiB |
57
c/main.c
Normal file
57
c/main.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <raylib.h>
|
||||||
|
|
||||||
|
#define WINDOW_WIDTH 800
|
||||||
|
#define WINDOW_HEIGHT 600
|
||||||
|
#define LOGO_SCALE 0.04f
|
||||||
|
#define LOGO_SPEED 300
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in C");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
SetRandomSeed(time(NULL));
|
||||||
|
|
||||||
|
Texture2D logo_texture = LoadTexture("./c_logo.png");
|
||||||
|
|
||||||
|
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 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_width) >= WINDOW_WIDTH - 1)
|
||||||
|
{
|
||||||
|
dx *= -1;
|
||||||
|
x += dx * delta_time;
|
||||||
|
}
|
||||||
|
if (y < 0 || (y + logo_height) >= WINDOW_HEIGHT - 1)
|
||||||
|
{
|
||||||
|
dy *= -1;
|
||||||
|
y += dy * delta_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
DrawTextureEx(logo_texture, (Vector2){x, y}, 0, LOGO_SCALE, WHITE);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
UnloadTexture(logo_texture);
|
||||||
|
CloseWindow();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user