# HG changeset patch # User June Park # Date 1760017309 25200 # Node ID a58a663dae6859295a78ff154fa893b801fe6e78 # Parent 342726584be24c5cb8cde96ebce3c483417a6573 [Sori] Making a simple game. diff -r 342726584be2 -r a58a663dae68 sori/BUILD --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sori/BUILD Thu Oct 09 06:41:49 2025 -0700 @@ -0,0 +1,11 @@ +load("//third_party/raylib:raylib.bzl", "raylib_binary") + +raylib_binary( + name = "game", + srcs = ["main.c"], + deps = [ + "//dowa:dowa", + "//third_party/raylib:raylib", + ], +) + diff -r 342726584be2 -r a58a663dae68 sori/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sori/main.c Thu Oct 09 06:41:49 2025 -0700 @@ -0,0 +1,141 @@ +#include +#include "dowa/dowa.h" +#include "third_party/raylib/include/raylib.h" +#include "third_party/raylib/include/raymath.h" + +typedef struct { + char *texts; + Vector2 position; +} PopUpText; + +typedef struct { + Vector2 position; + Vector2 size; + Vector2 velocity; +} Entity; + +Entity *Shoot(Entity *player) +{ + Entity *box = malloc(sizeof(Entity)); + box->velocity = (Vector2){ .x=1, .y=-10 }; + box->position = player->position; + box->size = (Vector2){ .x=10, .y=2 }; + return box; +} + +void Entity_Update(Entity *player, Entity *object) +{ + int gravity = 1; + player->velocity.y += gravity; + player->position = Vector2Add(player->position, player->velocity); + + if ( + player->position.y + player->size.y > object->position.y + ) + { + player->position.y = object->position.y - player->size.y; + } +} + +int main() +{ + char mouse_position[256]; + + InitWindow(800, 450, "Sori the game"); + SetTargetFPS(120); + + Entity player = { + .size = (Vector2){ .x = 20, .y = 20 }, + .position = (Vector2){ .x = 10, .y = 10}, + .velocity = (Vector2){ .x = 0, .y = 0}, + }; + + Entity ground = { + .size = (Vector2){ .x = 800, .y = 100 }, + .position = (Vector2){ .x = 0, .y = 350}, + .velocity = (Vector2){ .x = 0, .y = 0}, + }; + Entity *bullet; + Entity **bullets = malloc(sizeof(Entity) * 100); + + PopUpText *curr_values = malloc(sizeof(PopUpText) * 100); + int size_bullets = 0; + int size_texts = 0; + int frame = 0; + + while (!WindowShouldClose()) + { + BeginDrawing(); + ClearBackground(RAYWHITE); + int x = GetMouseX(); + int y = GetMouseY(); + + sprintf( + mouse_position, + "Mouse position %d, %d", + x, y + ); + if (IsMouseButtonPressed(0)) + { + curr_values[size_texts].texts = "hello good sir"; + curr_values[size_texts].position = (Vector2){ + .x = (float)x, + .y = (float)y, + }; + size_texts++; + + Entity *bullet = Shoot(&player); + bullets[size_bullets] = bullet; + size_bullets++; + } + + if (frame > 2) + { + Entity_Update(&player, &ground); + frame = 0; + for (uint32 i = 0; i < size_texts; i++) + { + Entity_Update(bullets[i], &ground); + } + } + + int key = GetKeyPressed(); + + if (IsKeyDown(KEY_W)) + { + player.position.y -= 1; + } + + if (IsKeyDown(KEY_S)) + { + player.position.y += 1; + } + + if (IsKeyDown(KEY_A)) + { + player.position.x -= 1; + } + + if (IsKeyDown(KEY_D)) + { + player.position.x += 1; + } + + DrawRectangleV(player.position, player.size, RED); + DrawRectangleV(ground.position, ground.size, BLUE); + + for (uint32 i = 0; i < size_texts; i++) + { + DrawText(curr_values[i].texts, curr_values[i].position.x, curr_values[i].position.y, + 20, LIGHTGRAY); + DrawRectangleV(bullets[i]->position, bullets[i]->size, BLACK); + } + DrawText(mouse_position, 190, 200, 20, LIGHTGRAY); + EndDrawing(); + + frame++; + } + CloseWindow(); + return 0; +} + diff -r 342726584be2 -r a58a663dae68 third_party/raylib/raylib.bzl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/third_party/raylib/raylib.bzl Thu Oct 09 06:41:49 2025 -0700 @@ -0,0 +1,59 @@ +def raylib_binary( + name, + srcs, + deps = [], + deps_macos = [], + deps_linux = [], + linkopts_macos = [ + "-framework CoreVideo", + "-framework IOKit", + "-framework Cocoa", + "-framework GLUT", + "-framework OpenGL", + ], + linkopts_linux = [ + "-lGL", + "-lm", + "-lpthread", + "-ldl", + "-lrt", + "-lX11", + ]): + """ + Raylib specific cross platform rules. + + Args: + name: The logical name of the binary (alias). + srcs: List of source files (common). + deps: Mutual dependency. + deps_macos: Extra deps for macOS. + deps_linux: Extra deps for Linux. + linkopts_macos: Extra linkopts for macOS. + linkopts_linux: Extra linkopts for Linux. + """ + + macos_bin = name + "_macos" + linux_bin = name + "_linux" + + native.cc_binary( + name = macos_bin, + srcs = srcs, + deps = deps + deps_macos, + linkopts = linkopts_macos, + ) + + native.cc_binary( + name = linux_bin, + srcs = srcs, + deps = deps + deps_linux, + linkopts = linkopts_linux, + ) + + native.alias( + name = name, + actual = select({ + "//config:macos": ":" + macos_bin, + "//config:linux": ":" + linux_bin, + "//conditions:default": ":" + linux_bin, # fallback + }), + )