Commit 1a1bcb94 authored by Max Kobelt's avatar Max Kobelt
Browse files

Add relative scaling and "PLAY" "button"

parent c75a2b8e
......@@ -2,26 +2,39 @@
#include <stddef.h>
#define min(a, b) ((a)<(b)? (a) : (b))
int main() {
InitWindow(GetScreenWidth(), GetScreenHeight(), "Space Intruders");
ToggleFullscreen();
SetTargetFPS(60);
const int gameScreenWidth = 400, gameScreenHeight = 400;
RenderTexture2D target = LoadRenderTexture(gameScreenWidth, gameScreenHeight);
SetTextureFilter(target.texture, FILTER_BILINEAR);
while (!WindowShouldClose()) {
if (IsKeyPressed(KEY_F11)) {
ToggleFullscreen();
}
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
float scale = min((float) GetScreenWidth() / gameScreenWidth, (float) GetScreenHeight() / gameScreenHeight);
BeginDrawing();
ClearBackground(BLACK);
BeginTextureMode(target);
DrawText("PLAY", (gameScreenWidth - MeasureText("PLAY", 50)) / 2, gameScreenHeight / 5, 50, RED);
EndTextureMode();
DrawTexturePro(target.texture, (Rectangle){ 0.0f, 0.0f, (float) target.texture.width, (float) -target.texture.height },
(Rectangle){ (GetScreenWidth() - ((float) gameScreenWidth * scale)) * 0.5, (GetScreenHeight() - ((float) gameScreenHeight*scale)) * 0.5,
(float) gameScreenWidth * scale, (float) gameScreenHeight * scale }, (Vector2){ 0, 0 }, 0.0f, WHITE);
EndDrawing();
}
UnloadRenderTexture(target);
CloseWindow();
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment