mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-21 22:05:10 +00:00
Creating the timer system
This commit is contained in:
@@ -56,11 +56,18 @@ set(SOURCES
|
||||
sources/Component/Renderer/CameraComponent.hpp
|
||||
sources/System/Renderer/Render2DScreenSystem.cpp
|
||||
sources/System/Renderer/Render2DScreenSystem.hpp
|
||||
sources/System/BombHolder/BombHolderSystem.cpp sources/System/BombHolder/BombHolderSystem.hpp sources/Component/Timer/TimerComponent.cpp sources/Component/Timer/TimerComponent.hpp)
|
||||
sources/System/BombHolder/BombHolderSystem.cpp
|
||||
sources/System/BombHolder/BombHolderSystem.hpp
|
||||
sources/Component/Timer/TimerComponent.cpp
|
||||
sources/Component/Timer/TimerComponent.hpp
|
||||
sources/System/Timer/TimerSystem.cpp
|
||||
sources/System/Timer/TimerSystem.hpp
|
||||
)
|
||||
|
||||
add_executable(bomberman
|
||||
sources/main.cpp
|
||||
${SOURCES})
|
||||
${SOURCES}
|
||||
)
|
||||
target_include_directories(bomberman PUBLIC sources)
|
||||
target_link_libraries(bomberman PUBLIC wal ray)
|
||||
|
||||
@@ -71,7 +78,8 @@ add_executable(unit_tests EXCLUDE_FROM_ALL
|
||||
tests/MainTest.cpp
|
||||
tests/EngineTests.cpp
|
||||
tests/CallbackTest.cpp
|
||||
tests/MoveTests.cpp)
|
||||
tests/MoveTests.cpp
|
||||
)
|
||||
target_include_directories(unit_tests PUBLIC sources)
|
||||
target_link_libraries(unit_tests PUBLIC wal ray)
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Model/Model.hpp>
|
||||
#include <Drawables/2D/Rectangle.hpp>
|
||||
#include <TraceLog.hpp>
|
||||
#include "System/Timer/TimerSystem.hpp"
|
||||
#include "Component/BombHolder/BombHolderComponent.hpp"
|
||||
#include "System/BombHolder/BombHolderSystem.hpp"
|
||||
#include "System/Renderer/Renderer3DSystem.hpp"
|
||||
@@ -42,7 +43,8 @@ namespace BBM
|
||||
|
||||
void addSystems(WAL::Wal &wal)
|
||||
{
|
||||
wal.addSystem<KeyboardSystem>()
|
||||
wal.addSystem<TimerSystem>()
|
||||
.addSystem<KeyboardSystem>()
|
||||
.addSystem<GamepadSystem>()
|
||||
.addSystem<ControllableSystem>()
|
||||
.addSystem<BombHolderSystem>(wal)
|
||||
|
||||
27
sources/System/Timer/TimerSystem.cpp
Normal file
27
sources/System/Timer/TimerSystem.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/31/21.
|
||||
//
|
||||
|
||||
#include "TimerSystem.hpp"
|
||||
#include "Component/Timer/TimerComponent.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
TimerSystem::TimerSystem()
|
||||
: WAL::System({
|
||||
typeid(TimerComponent)
|
||||
})
|
||||
{}
|
||||
|
||||
void TimerSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &timer = entity.getComponent<TimerComponent>();
|
||||
timer.ringIn -= dtime;
|
||||
if (timer.ringIn <= 0ns) {
|
||||
timer.setDisable(true);
|
||||
timer.callback(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
26
sources/System/Timer/TimerSystem.hpp
Normal file
26
sources/System/Timer/TimerSystem.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/31/21.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <System/System.hpp>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class TimerSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
TimerSystem();
|
||||
//! @brief A timer system is copy constructable.
|
||||
TimerSystem(const TimerSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~TimerSystem() override = default;
|
||||
//! @breief A timer system is assignable.
|
||||
TimerSystem &operator=(const TimerSystem &) = default;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user