diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/api/LoopManager.cpp | 14 | ||||
-rw-r--r-- | src/crepe/system/AISystem.cpp | 6 | ||||
-rw-r--r-- | src/crepe/system/AISystem.h | 14 | ||||
-rw-r--r-- | src/crepe/system/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/example/AITest.cpp | 45 |
5 files changed, 62 insertions, 19 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index 7edf4d1..cd602d8 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -1,5 +1,6 @@ #include "../facade/SDLContext.h" +#include "../system/AISystem.h" #include "../system/AnimatorSystem.h" #include "../system/CollisionSystem.h" #include "../system/ParticleSystem.h" @@ -20,6 +21,7 @@ LoopManager::LoopManager() { this->load_system<PhysicsSystem>(); this->load_system<RenderSystem>(); this->load_system<ScriptSystem>(); + this->load_system<AISystem>(); } void LoopManager::process_input() { @@ -51,6 +53,11 @@ void LoopManager::loop() { this->render(); timer.enforce_frame_rate(); + + // Stop the game after 5 seconds, for testing purposes + if (timer.get_current_time() > 5) { + this->game_running = false; + } } } @@ -58,6 +65,7 @@ void LoopManager::setup() { this->game_running = true; LoopTimer::get_instance().start(); LoopTimer::get_instance().set_fps(200); + this->scene_manager.load_next_scene(); } void LoopManager::render() { @@ -66,4 +74,8 @@ void LoopManager::render() { } } -void LoopManager::update() { LoopTimer & timer = LoopTimer::get_instance(); } +void LoopManager::update() { + LoopTimer & timer = LoopTimer::get_instance(); + this->get_system<AnimatorSystem>().update(); + this->get_system<AISystem>().update(); +} diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp new file mode 100644 index 0000000..012f4fa --- /dev/null +++ b/src/crepe/system/AISystem.cpp @@ -0,0 +1,6 @@ +#include "AISystem.h" +#include <iostream> + +using namespace crepe; + +void AISystem::update() { std::cout << "AI System update" << std::endl; } diff --git a/src/crepe/system/AISystem.h b/src/crepe/system/AISystem.h new file mode 100644 index 0000000..4138e01 --- /dev/null +++ b/src/crepe/system/AISystem.h @@ -0,0 +1,14 @@ +#pragma once + +#include "System.h" + +namespace crepe { + +class AISystem : public System { +public: + using System::System; + + void update() override; +}; + +} // namespace crepe diff --git a/src/crepe/system/CMakeLists.txt b/src/crepe/system/CMakeLists.txt index d658b25..ca89d4d 100644 --- a/src/crepe/system/CMakeLists.txt +++ b/src/crepe/system/CMakeLists.txt @@ -6,6 +6,7 @@ target_sources(crepe PUBLIC CollisionSystem.cpp RenderSystem.cpp AnimatorSystem.cpp + AISystem.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -15,4 +16,5 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES CollisionSystem.h RenderSystem.h AnimatorSystem.h + AISystem.h ) diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp index ccf5a85..3998ff4 100644 --- a/src/example/AITest.cpp +++ b/src/example/AITest.cpp @@ -1,32 +1,41 @@ +#include <SDL2/SDL_timer.h> +#include <chrono> +#include <crepe/ComponentManager.h> #include <crepe/api/Camera.h> #include <crepe/api/Color.h> -#include <crepe/api/Texture.h> -#include <crepe/api/Sprite.h> -#include <crepe/ComponentManager.h> #include <crepe/api/GameObject.h> +#include <crepe/api/LoopManager.h> +#include <crepe/api/Scene.h> +#include <crepe/api/Sprite.h> +#include <crepe/api/Texture.h> #include <crepe/system/RenderSystem.h> -#include <SDL2/SDL_timer.h> -#include <chrono> using namespace crepe; +using namespace std; -int main() { - ComponentManager mgr; - GameObject game_object1 = mgr.new_object("", "", vec2{0, 0}, 0, 1); - GameObject game_object2 = mgr.new_object("", "", vec2{0, 0}, 0, 1); - - Texture img = Texture("asset/texture/test_ap43.png"); - game_object1.add_component<Sprite>(img, Color::MAGENTA, Sprite::FlipSettings{false, false}, 1, 1, 195); +class Scene1 : public Scene { +public: + void load_scene() override { + ComponentManager & mgr = this->component_manager; - game_object2.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, vec2{1036, 780}, 1.0f); + GameObject game_object1 = mgr.new_object("", "", vec2{0, 0}, 0, 1); + GameObject game_object2 = mgr.new_object("", "", vec2{0, 0}, 0, 1); - RenderSystem sys{mgr}; + Texture img = Texture("asset/texture/test_ap43.png"); + game_object1.add_component<Sprite>(img, Color::MAGENTA, + Sprite::FlipSettings{false, false}, 1, 1, 195); - auto start = std::chrono::steady_clock::now(); - while (std::chrono::steady_clock::now() - start < std::chrono::seconds(5)) { - sys.update(); - SDL_Delay(10); + game_object2.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, vec2{1036, 780}, + 1.0f); } + string get_name() const override { return "Scene1"; } +}; + +int main() { + LoopManager engine; + engine.add_scene<Scene1>(); + engine.start(); + return 0; } |