From 28ed6105138e43b50ed2ef88ed08d09d48d9d660 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 17 Apr 2022 01:07:35 +0200 Subject: Fleshed out skeleton with Game and Screen classes --- CMakeLists.txt | 9 +++++++-- Game.cpp | 32 ++++++++++++++++++++++++++++++++ Game.h | 17 +++++++++++++++++ Screen.h | 8 ++++++++ TitleScreen.cpp | 16 ++++++++++++++++ TitleScreen.h | 10 ++++++++++ main.cpp | 19 +++++++++++++------ 7 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 Game.cpp create mode 100644 Game.h create mode 100644 Screen.h create mode 100644 TitleScreen.cpp create mode 100644 TitleScreen.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ce53a0..5abb82d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,14 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_EXTENSIONS No) if(EMSCRIPTEN) set(CMAKE_PREFIX_PATH "$ENV{HOME}/.emscripten_cache/sysroot;/usr/lib/emscripten/system") - set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY") set(raylib_USE_STATIC_LIBS ON) endif() find_package(raylib 3 REQUIRED) -add_executable(${PROJECT_NAME} main.cpp) +add_executable( + ${PROJECT_NAME} + Game.cpp + main.cpp + TitleScreen.cpp +) target_link_libraries(${PROJECT_NAME} raylib) diff --git a/Game.cpp b/Game.cpp new file mode 100644 index 0000000..13790d5 --- /dev/null +++ b/Game.cpp @@ -0,0 +1,32 @@ +#include "Game.h" + +#include +#include + +#include + +#include "Screen.h" + + +void +Game::set(std::unique_ptr screen) +{ + m_screen = std::move(screen); +} + + +void +Game::update(const float dt) +{ + if (m_screen) + m_screen->update(dt); +} + + +void +Game::draw() +{ + ClearBackground(BLACK); + if (m_screen) + m_screen->draw(); +} diff --git a/Game.h b/Game.h new file mode 100644 index 0000000..b047336 --- /dev/null +++ b/Game.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +#include "Screen.h" + + +class Game +{ +public: + void set(std::unique_ptr screen); + void update(float dt); + void draw(); + +private: + std::unique_ptr m_screen; +}; diff --git a/Screen.h b/Screen.h new file mode 100644 index 0000000..d875165 --- /dev/null +++ b/Screen.h @@ -0,0 +1,8 @@ +#pragma once + + +struct Screen +{ + virtual void update(float dt) = 0; + virtual void draw() = 0; +}; diff --git a/TitleScreen.cpp b/TitleScreen.cpp new file mode 100644 index 0000000..3faf48f --- /dev/null +++ b/TitleScreen.cpp @@ -0,0 +1,16 @@ +#include "TitleScreen.h" + +#include + + +void +TitleScreen::update(const float dt) +{ +} + + +void +TitleScreen::draw() +{ + DrawText("Bullet HELL 2022", 190, 200, 20, LIGHTGRAY); +} diff --git a/TitleScreen.h b/TitleScreen.h new file mode 100644 index 0000000..a0ec64f --- /dev/null +++ b/TitleScreen.h @@ -0,0 +1,10 @@ +#pragma once + +#include "Screen.h" + + +struct TitleScreen : public Screen +{ + void update(float dt) override; + void draw() override; +}; diff --git a/main.cpp b/main.cpp index 6b7a251..9f216e5 100644 --- a/main.cpp +++ b/main.cpp @@ -1,24 +1,31 @@ -#include "raylib.h" +#include + +#include #ifdef PLATFORM_WEB #include #endif +#include "Game.h" +#include "TitleScreen.h" + + +static Game s_game; + void Loop(); int main() { - InitWindow(800, 600, "bullethell2022"); + InitWindow(800, 600, "Bullet Hell 2022"); + s_game.set(std::make_unique()); #ifdef PLATFORM_WEB emscripten_set_main_loop(Loop, 0, 1); #else SetTargetFPS(60); while (!WindowShouldClose()) - { Loop(); - } #endif // PLATFORM_WEB CloseWindow(); } @@ -26,8 +33,8 @@ int main() void Loop() { + s_game.update(GetFrameTime()); BeginDrawing(); - ClearBackground(RAYWHITE); - DrawText("bullethell2022", 190, 200, 20, LIGHTGRAY); + s_game.draw(); EndDrawing(); } -- cgit v1.1