From 95e5465308cbaabc91803cc7594249362159d403 Mon Sep 17 00:00:00 2001 From: Wynd Date: Fri, 29 Aug 2025 19:32:05 +0300 Subject: [PATCH] Got a project setup with the basic rendering done --- .clang-format | 4 +++ .gitignore | 5 ++++ Makefile | 6 +++++ main.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.c diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..adb946a --- /dev/null +++ b/.clang-format @@ -0,0 +1,4 @@ +UseTab: Always +IndentWidth: 4 +TabWidth: 4 +ColumnLimit: 120 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5331464 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +* +!.gitignore +!*.c +!.clang-format +!Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d58901e --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ + +build: + cc main.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -o breakout + +run: build + ./breakout diff --git a/main.c b/main.c new file mode 100644 index 0000000..3de9ea8 --- /dev/null +++ b/main.c @@ -0,0 +1,74 @@ +#include "raylib.h" +#include "raymath.h" +#include + +#define VIRTUAL_WIDTH 800 +#define VIRTUAL_HEIGHT 600 + +#define FONT_SIZE 20 + +#define PADDLE_SPEED 4.0 +#define PADDLE_WIDTH VIRTUAL_WIDTH / 8.0 +#define PADDLE_HEIGHT VIRTUAL_HEIGHT / 30.0 + +int main() { + InitWindow(0, 0, "Breakout"); + ToggleFullscreen(); + + const int currentMonitor = GetCurrentMonitor(); + const int monitorWidth = GetMonitorWidth(currentMonitor); + const int monitorHeight = GetMonitorHeight(currentMonitor); + + SetTargetFPS(60); + + Camera2D camera = {0}; // Game world camera + // camera.offset = (Vector2){SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT / 2.0f}; + camera.zoom = 1.0f; + + const RenderTexture2D renderTexture = LoadRenderTexture(VIRTUAL_WIDTH, VIRTUAL_HEIGHT); + const Rectangle renderTextureSrc = (Rectangle){0.0f, 0.0f, VIRTUAL_WIDTH, -VIRTUAL_HEIGHT}; + const Rectangle renderTextureDest = (Rectangle){0.0f, 0.0f, monitorWidth, monitorHeight}; + const Vector2 renderTextureOrig = {0}; + + float paddleX = 0; + Vector2 ballPos = (Vector2){VIRTUAL_WIDTH / 2.0f, VIRTUAL_HEIGHT / 2.0f}; + int score = 0; + + while (!WindowShouldClose()) { + Vector2 mouseDelta = GetMouseDelta(); + + DisableCursor(); + + paddleX = Clamp(paddleX + mouseDelta.x, 0, VIRTUAL_WIDTH - PADDLE_WIDTH); + + BeginTextureMode(renderTexture); + { + ClearBackground(BLACK); + DrawRectangle(paddleX, VIRTUAL_HEIGHT - PADDLE_HEIGHT - 10, PADDLE_WIDTH, PADDLE_HEIGHT, RAYWHITE); + } + EndTextureMode(); + + BeginDrawing(); + { + ClearBackground(BLACK); + BeginMode2D(camera); + { + DrawCircle(ballPos.x, ballPos.y, 20, RAYWHITE); + + DrawTexturePro(renderTexture.texture, renderTextureSrc, renderTextureDest, renderTextureOrig, 0, WHITE); + } + EndMode2D(); + + // char score[] = "Score"; + const char *scoreText = TextFormat("Score %08i", score); + float scoreWidth = MeasureText(scoreText, FONT_SIZE) + 10; + DrawText(scoreText, 10, 10, FONT_SIZE, RAYWHITE); + + DrawFPS(GetScreenWidth() - 80, 5); + // DrawText(TextFormat("%ix%i", monitorWidth, monitorHeight), 10, 40, FONT_SIZE, GOLD); + } + EndDrawing(); + } + + CloseWindow(); +}