]> _ Git - basic-rhythm.git/commitdiff
Makefile, basic window!! main
authorparking_turkeys <roya1060wien@gmail.com>
Sat, 28 Nov 2026 04:02:07 +0000 (23:02 -0500)
committerparking_turkeys <roya1060wien@gmail.com>
Sat, 28 Nov 2026 04:02:07 +0000 (23:02 -0500)
Makefile [new file with mode: 0644]
game.h [new file with mode: 0644]
main.c [new file with mode: 0644]
window.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
index 0000000..8c977e6
--- /dev/null
+++ b/game.h
@@ -0,0 +1,20 @@
+#include "raylib.h"
+#include <stdio.h>
+
+
+/* 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 (file)
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 (file)
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;
+}