diff options
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rw-r--r-- | Game.cpp | 32 | ||||
-rw-r--r-- | Game.h | 17 | ||||
-rw-r--r-- | Screen.h | 8 | ||||
-rw-r--r-- | TitleScreen.cpp | 16 | ||||
-rw-r--r-- | TitleScreen.h | 10 | ||||
-rw-r--r-- | main.cpp | 19 |
7 files changed, 103 insertions, 8 deletions
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 <memory> +#include <utility> + +#include <raylib.h> + +#include "Screen.h" + + +void +Game::set(std::unique_ptr<Screen> 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(); +} @@ -0,0 +1,17 @@ +#pragma once + +#include <memory> + +#include "Screen.h" + + +class Game +{ +public: + void set(std::unique_ptr<Screen> screen); + void update(float dt); + void draw(); + +private: + std::unique_ptr<Screen> 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 <raylib.h> + + +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; +}; @@ -1,24 +1,31 @@ -#include "raylib.h" +#include <memory> + +#include <raylib.h> #ifdef PLATFORM_WEB #include <emscripten/emscripten.h> #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<TitleScreen>()); #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(); } |