#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(); }