Commit 258b7049 authored by Max Kobelt's avatar Max Kobelt
Browse files

Separate menu from main.c

parent 1a1bcb94
......@@ -29,8 +29,5 @@ if (NOT raylib_FOUND) # If there's none, fetch and build raylib
endif()
# This is the main part:
add_executable(${PROJECT_NAME} main.c)
add_subdirectory(src)
#set(raylib_VERBOSE 1)
target_link_libraries(${PROJECT_NAME} raylib)
add_executable(${PROJECT_NAME} "")
target_link_libraries(${PROJECT_NAME} raylib)
target_sources(${PROJECT_NAME}
PRIVATE
main.c
menu.h
menu.c
)
#include "menu.h"
#include <raylib.h>
#include <stddef.h>
#define min(a, b) ((a)<(b)? (a) : (b))
const int GAME_SCREEN_WIDTH = 400, GAME_SCREEN_HEIGHT = 400;
int main() {
InitWindow(GetScreenWidth(), GetScreenHeight(), "Space Intruders");
ToggleFullscreen();
SetTargetFPS(60);
const int gameScreenWidth = 400, gameScreenHeight = 400;
RenderTexture2D target = LoadRenderTexture(gameScreenWidth, gameScreenHeight);
RenderTexture2D target = LoadRenderTexture(GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT);
SetTextureFilter(target.texture, FILTER_BILINEAR);
enum { MENU, GAME } state = MENU;
while (!WindowShouldClose()) {
if (IsKeyPressed(KEY_F11)) {
ToggleFullscreen();
}
float scale = min((float) GetScreenWidth() / gameScreenWidth, (float) GetScreenHeight() / gameScreenHeight);
float scale = min((float) GetScreenWidth() / GAME_SCREEN_WIDTH, (float) GetScreenHeight() / GAME_SCREEN_HEIGHT);
BeginDrawing();
ClearBackground(BLACK);
BeginTextureMode(target);
DrawText("PLAY", (gameScreenWidth - MeasureText("PLAY", 50)) / 2, gameScreenHeight / 5, 50, RED);
if (state == MENU) {
drawMenu();
} else if (state == GAME) {
// todo
}
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);
(Rectangle){ (GetScreenWidth() - ((float) GAME_SCREEN_WIDTH * scale)) * 0.5, (GetScreenHeight() - ((float) GAME_SCREEN_HEIGHT * scale)) * 0.5,
(float) GAME_SCREEN_WIDTH * scale, (float) GAME_SCREEN_HEIGHT * scale }, (Vector2){ 0, 0 }, 0.0f, WHITE);
EndDrawing();
}
......
#include "raylib.h"
extern const int GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT;
void drawMenu() {
DrawText("PLAY", (GAME_SCREEN_WIDTH + - MeasureText("PLAY", 50)) / 2, GAME_SCREEN_HEIGHT / 5, 50, RED);
}
void drawMenu();
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