commit e8b7e98bd29f7c5fb8dc53d87210d685f90c57ab Author: Abdelrahman Date: Sat May 10 12:35:11 2025 +0100 INITIAL COMMIT diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b8b9dbc --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.cache +compile_commands.json +main +test +*.png +raylib diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2862933 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "wapp"] + path = wapp + url = git@git.thewizardapprentice.com:abdelrahman/wizapp-stdlib +[submodule "raylib-src"] + path = raylib-src + url = git@github.com:raysan5/raylib diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3f5bd2b --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +CC = clang +CFLAGS = -g -Iraylib/include -Iwapp/src +LDFLAGS = '-Wl,-rpath,$$ORIGIN/raylib/lib' -Lraylib/lib -lraylib +OUT = main + +.PHONY: all game + +all: game + +game: + cd wapp && python3 -m codegen + $(CC) $(CFLAGS) $(LDFLAGS) main.c wapp/src/wapp.c -o $(OUT) diff --git a/build b/build new file mode 100755 index 0000000..e482bec --- /dev/null +++ b/build @@ -0,0 +1,3 @@ +#!/bin/bash + +bear -- make diff --git a/main.c b/main.c new file mode 100644 index 0000000..779538f --- /dev/null +++ b/main.c @@ -0,0 +1,126 @@ +#include "wapp.h" +#include "raylib.h" +#include +#include + +#define WIDTH 1280 +#define HEIGHT 720 +#define HALF_WIDTH (WIDTH * 0.5f) +#define HALF_HEIGHT (HEIGHT * 0.5f) +#define MAX_OBJ_DIM 80 +#define MIN_OBJ_DIM 20 +#define BG_COLOR (Color){.r = 0xea, .g = 0xf2, .b = 0xe3, .a = 0xff} +#define FG_COLOR (Color){.r = 0x42, .g = 0x4C, .b = 0x55, .a = 0xff} +#define OBJECT_COUNT 1 +#define MSG_BUF_LEN 4096 +#define abs(A) (A < 0 ? A * -1 : A) +#define min(A, B) (A < B ? A : B) +#define max(A, B) (A > B ? A : B) + +typedef struct Position Position; +struct Position { + f32 x; + f32 y; +}; + +typedef struct Scale Scale; +struct Scale { + f32 width; + f32 height; +}; + +typedef struct Velocity Velocity; +struct Velocity { + f32 x; + f32 y; +}; + +typedef struct Object Object; +struct Object { + Position position; + Scale scale; + Velocity velocity; +}; + +void init_object(Object *object, XOR256State *state); +void update_object(Object *object); +void move_object(Object *object); +f32 get_random_float(XOR256State *state); + +int main(void) { + InitWindow(WIDTH, HEIGHT, "Handle test"); + SetTargetFPS(120); + + Allocator arena = wapp_mem_arena_allocator_init(MB(10)); + XOR256State state = wapp_prng_xorshift_init_state(); + Object *objects = wapp_mem_allocator_alloc(&arena, sizeof(Object) * OBJECT_COUNT); + assert(objects != NULL); + + for (u64 i = 0; i < OBJECT_COUNT; ++i) { + Object *object = &(objects[i]); + init_object(object, &state); + } + + while (!WindowShouldClose()) { + for (u64 i = 0; i < OBJECT_COUNT; ++i) { + Object *object = &(objects[i]); + move_object(object); + } + + BeginDrawing(); + + ClearBackground(BG_COLOR); + + for (u64 i = 0; i < OBJECT_COUNT; ++i) { + Object *object = &(objects[i]); + DrawRectangle( + (i32)object->position.x, + (i32)object->position.y, + (i32)object->scale.width, + (i32)object->scale.height, + FG_COLOR + ); + } + + EndDrawing(); + } + + wapp_mem_arena_allocator_destroy(&arena); + + CloseWindow(); + + return 0; +} + +void init_object(Object *object, XOR256State *state) { + object->position = (Position){ + .x = wapp_prng_xorshift_256(state) % WIDTH, + .y = wapp_prng_xorshift_256(state) % HEIGHT, + }; + object->scale = (Scale){ + .width = max(wapp_prng_xorshift_256(state) % MAX_OBJ_DIM, MIN_OBJ_DIM), + .height = max(wapp_prng_xorshift_256(state) % MAX_OBJ_DIM, MIN_OBJ_DIM), + }; + object->velocity = (Velocity){ + .x = get_random_float(state), + // .y = get_random_float(state), + .y = 0.0f, + }; +} + +void move_object(Object *object) { + object->position.x += object->velocity.x; + object->position.y += object->velocity.y; + + if (object->position.x > WIDTH || + object->position.x + object->scale.width < 0 || + object->position.y > HEIGHT || + object->position.y + object->scale.height < 0 + ) { + } +} + +f32 get_random_float(XOR256State *state) { + i64 random = (i64)wapp_prng_xorshift_256(state) - INT64_MAX; + return (f32)(random) / (f32)(INT64_MAX); +} diff --git a/raylib-src b/raylib-src new file mode 160000 index 0000000..c1ab645 --- /dev/null +++ b/raylib-src @@ -0,0 +1 @@ +Subproject commit c1ab645ca298a2801097931d1079b10ff7eb9df8 diff --git a/wapp b/wapp new file mode 160000 index 0000000..7416471 --- /dev/null +++ b/wapp @@ -0,0 +1 @@ +Subproject commit 74164717d01f66de47d5fad9104630b9aabc45b5