INITIAL COMMIT
This commit is contained in:
		
							
								
								
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
.cache
 | 
			
		||||
compile_commands.json
 | 
			
		||||
main
 | 
			
		||||
test
 | 
			
		||||
*.png
 | 
			
		||||
raylib
 | 
			
		||||
							
								
								
									
										6
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
							
								
								
									
										12
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
			
		||||
							
								
								
									
										126
									
								
								main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										126
									
								
								main.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,126 @@
 | 
			
		||||
#include "wapp.h"
 | 
			
		||||
#include "raylib.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
 | 
			
		||||
#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);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								raylib-src
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								raylib-src
									
									
									
									
									
										Submodule
									
								
							 Submodule raylib-src added at c1ab645ca2
									
								
							
							
								
								
									
										1
									
								
								wapp
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								wapp
									
									
									
									
									
										Submodule
									
								
							 Submodule wapp added at 74164717d0
									
								
							
		Reference in New Issue
	
	Block a user