#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 30 #define MIN_OBJ_DIM 15 #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 10 #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) #define OBJECT_COMMON struct {Position position; Scale scale;} 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 Wanderer Wanderer; struct Wanderer { OBJECT_COMMON; Velocity velocity; }; typedef struct SlowZone SlowZone; struct SlowZone { OBJECT_COMMON; }; void init_wanderer(Wanderer *wanderer, XOR256State *state); void move_wanderer(Wanderer *wanderer); f32 get_random_float(XOR256State *state); int main(void) { InitWindow(WIDTH, HEIGHT, "DOD test"); SetTargetFPS(120); Allocator arena = wapp_mem_arena_allocator_init(MB(10)); XOR256State state = wapp_prng_xorshift_init_state(); Wanderer *objects = wapp_mem_allocator_alloc(&arena, sizeof(Wanderer) * OBJECT_COUNT); assert(objects != NULL); for (u64 i = 0; i < OBJECT_COUNT; ++i) { Wanderer *object = &(objects[i]); init_wanderer(object, &state); } while (!WindowShouldClose()) { for (u64 i = 0; i < OBJECT_COUNT; ++i) { Wanderer *object = &(objects[i]); move_wanderer(object); } BeginDrawing(); ClearBackground(BG_COLOR); for (u64 i = 0; i < OBJECT_COUNT; ++i) { Wanderer *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_wanderer(Wanderer *wanderer, XOR256State *state) { wanderer->position = (Position){ .x = wapp_prng_xorshift_256(state) % WIDTH, .y = wapp_prng_xorshift_256(state) % HEIGHT, }; f32 scale = (f32)((wapp_prng_xorshift_256(state) % (MAX_OBJ_DIM + 1 - MIN_OBJ_DIM)) + MIN_OBJ_DIM); wanderer->scale = (Scale){ .width = scale, .height = scale, }; wanderer->velocity = (Velocity){ .x = get_random_float(state), // .y = get_random_float(state), .y = 0.0f, }; } void move_wanderer(Wanderer *wanderer) { wanderer->position.x += wanderer->velocity.x; wanderer->position.y += wanderer->velocity.y; if (wanderer->position.x > WIDTH || wanderer->position.x + wanderer->scale.width < 0 || wanderer->position.y > HEIGHT || wanderer->position.y + wanderer->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); }