diff --git a/CMakeLists.txt b/CMakeLists.txt index 99230dd586ac1d108791ec3e30d5d720f748ccd4..53d113f2bf2d8fbb01937144ea08cfde8b717618 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,11 +5,12 @@ set(CMAKE_CXX_STANDARD 17) file(GLOB_RECURSE HEADERS include/*h) file(GLOB_RECURSE SOURCES src/*cpp) -#set(SFML_STATIC_LIBRARIES TRUE) +set(SFML_STATIC_LIBRARIES TRUE) set(BUILD_SHARED_LIBS FALSE) -#FetchContent_Declare(SFML GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_TAG 2.6.1) -#FetchContent_MakeAvailable(SFML) +include(FetchContent) +FetchContent_Declare(SFML GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_TAG 2.6.1) +FetchContent_MakeAvailable(SFML) add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES}) -#target_link_libraries(${PROJECT_NAME} PRIVATE sfml-system sfml-window sfml-graphics) \ No newline at end of file +target_link_libraries(${PROJECT_NAME} PRIVATE sfml-system sfml-window sfml-graphics) \ No newline at end of file diff --git a/include/Application.h b/include/Application.h index b5f6a7052230db8c51ea8f6ed85d75fb659359fe..a65c7e389e9905a84e7334c2438622d2aa19b056 100644 --- a/include/Application.h +++ b/include/Application.h @@ -15,6 +15,6 @@ private: ~Application() override = default; void set_next_state(std::unique_ptr<IState> state) override { m_ptr_state_next = std::move(state); }; void apply_deffer_state_change(); - std::unique_ptr<IState> m_ptr_state_current = std::make_unique<ExitState>(*this); + std::unique_ptr<IState> m_ptr_state_current = std::make_unique<SelectState>(*this, sf::VideoMode{100, 50}, sf::String{"Select state"}); std::unique_ptr<IState> m_ptr_state_next; }; \ No newline at end of file diff --git a/include/States/States.h b/include/States/States.h index f98dd036c5c4185221d50da64f6bfa01e148f49a..060ff8796950e2182387a717415751b56e87e7eb 100644 --- a/include/States/States.h +++ b/include/States/States.h @@ -1,7 +1,39 @@ #pragma once +#include <iostream> #include "IState.h" +#include <SFML/Graphics.hpp> + +class IWindowKeeper { +public: + IWindowKeeper(const sf::VideoMode& video_mode, const sf::String& window_title) {}; + virtual ~IWindowKeeper() = default; +protected: + virtual void event_handling() = 0; + virtual void update() = 0; + virtual void render() = 0; + sf::RenderWindow m_window; +}; struct ExitState : IState { explicit ExitState(IStateManager& state_manager) : IState(state_manager) {} - bool do_step() override { return false; } + bool do_step() override { + std::cout << "Exiting..." << std::endl; + return false; + } +}; + +struct SelectState : IState, IWindowKeeper { + explicit SelectState(IStateManager& state_manager, const sf::VideoMode& video_mode, const sf::String& window_title) : IState(state_manager), IWindowKeeper(video_mode, window_title) {} + bool do_step() override; + void event_handling() override {}; + void update() override {}; + void render() override {}; +}; + +struct GameState : IState, IWindowKeeper { + explicit GameState(IStateManager& state_manager, const sf::VideoMode& video_mode, const sf::String& window_title) : IState(state_manager), IWindowKeeper(video_mode, window_title) {} + bool do_step() override; + void event_handling() override {}; + void update() override {}; + void render() override {}; }; \ No newline at end of file diff --git a/src/States/GameState.cpp b/src/States/GameState.cpp new file mode 100644 index 0000000000000000000000000000000000000000..78783d722ca5ef6de97cd39ba61757ec67fd9be0 --- /dev/null +++ b/src/States/GameState.cpp @@ -0,0 +1,7 @@ +#include "../../include/States/States.h" + +bool GameState::do_step() { + std::cout << "Game state" << std::endl; + m_state_manager.set_next_state(std::make_unique<ExitState>(m_state_manager)); + return true; +} \ No newline at end of file diff --git a/src/States/SelectState.cpp b/src/States/SelectState.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c8a7aa060bf50c67747eb15f0adcdf17518eb1a7 --- /dev/null +++ b/src/States/SelectState.cpp @@ -0,0 +1,7 @@ +#include "../../include/States/States.h" + +bool SelectState::do_step() { + std::cout << "Select state" << std::endl; + m_state_manager.set_next_state(std::make_unique<GameState>(m_state_manager, sf::VideoMode{100, 50}, sf::String{"Game state"})); + return true; +} \ No newline at end of file