From 69b867e31f7d614e6905a3073d0293b766e62fc0 Mon Sep 17 00:00:00 2001 From: parking_turkeys Date: Fri, 27 Nov 2026 23:02:07 -0500 Subject: [PATCH] Makefile, basic window!! --- Makefile | 11 +++++++++++ game.h | 20 ++++++++++++++++++++ main.c | 27 +++++++++++++++++++++++++++ window.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 Makefile create mode 100644 game.h create mode 100644 main.c create mode 100644 window.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..85cdc16 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ + +files = $(wildcard *.c) $(wildcard *.h) +warning_options = -std=c89 -Wall -Wno-unused-label -Werror -pedantic +windows_libraries = -lraylib -lgdi32 -lwinmm -lm +linux_libraries = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 + +linux: $(files) + gcc $(files) $(linux_libraries) $(warning_options) +windows: $(files) + gcc $(files) $(windows_libraries) $(warning_options) + diff --git a/game.h b/game.h new file mode 100644 index 0000000..8c977e6 --- /dev/null +++ b/game.h @@ -0,0 +1,20 @@ +#include "raylib.h" +#include + + +/* defines */ + +#define RENDERWIDTH 640.0 +#define RENDERHEIGHT 480.0 +#define WINDOWTITLE "Rhythm game!" +#define FPS 30 + +/* macros */ +#define MIN(a, b) ((a)<(b)? (a) : (b)) + +/* functions */ + +/* window.c : resizeable window w/letterbox */ +int setupWindow(RenderTexture2D *tar); +int drawTexture(RenderTexture2D *tar); +int closeWindow(RenderTexture2D *tar); diff --git a/main.c b/main.c new file mode 100644 index 0000000..cd0f91c --- /dev/null +++ b/main.c @@ -0,0 +1,27 @@ +/* rhythm game */ +#include "game.h" + + + +int main(void) +{ + RenderTexture2D tar; + + setupWindow(&tar); + + while (!WindowShouldClose()) { + + BeginTextureMode(tar); + ClearBackground(RAYWHITE); + + EndTextureMode(); + + BeginDrawing(); + drawTexture(&tar); + EndDrawing(); + }; + + closeWindow(&tar); + + return 0; +} diff --git a/window.c b/window.c new file mode 100644 index 0000000..cc7a4d6 --- /dev/null +++ b/window.c @@ -0,0 +1,55 @@ +/* Resizeable window. c89 + * Very heavily based off of the "letterbox" example */ +#include "game.h" + +int setupWindow(RenderTexture2D *tar) +{ + SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT); + InitWindow(RENDERWIDTH, RENDERHEIGHT, WINDOWTITLE); + SetTargetFPS(FPS); + + *tar = LoadRenderTexture(RENDERWIDTH, RENDERHEIGHT); + + return 0; +} + +const Vector2 origin = {0, 0}; + +int drawTexture(RenderTexture2D *tar) +{ + Rectangle srcrec, dstrec; + float scale; + + ClearBackground(BLACK); + + scale = MIN((float)GetScreenWidth()/RENDERWIDTH, + (float)GetScreenHeight()/RENDERHEIGHT); + printf("%f\n", scale); + + srcrec.x = 0.0f; + srcrec.y = 0.0f; + srcrec.width = tar->texture.width; + srcrec.height = -tar->texture.height; + + dstrec.x = (GetScreenWidth() - RENDERWIDTH*scale)*0.5f; + dstrec.y = (GetScreenHeight() - RENDERHEIGHT*scale)*0.5f; + dstrec.width = RENDERWIDTH*scale; + dstrec.height = RENDERHEIGHT*scale; + + DrawTexturePro( + tar->texture, + srcrec, + dstrec, + origin, + 0.0f, + WHITE + ); + + return 0; +} + +int closeWindow(RenderTexture2D *tar) +{ + UnloadRenderTexture(*tar); + return 0; +} -- 2.47.3