diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ae95107..6fc419f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,8 +92,14 @@ set(SOURCES sources/System/Sound/PlayerSoundManagerSystem.hpp sources/System/Music/MusicSystem.hpp sources/System/Music/MusicSystem.cpp + sources/Component/Gravity/GravityComponent.hpp sources/Component/Gravity/GravityComponent.cpp + sources/System/Gravity/GravitySystem.hpp sources/System/Gravity/GravitySystem.cpp + sources/Component/BumperTimer/BumperTimerComponent.hpp + sources/Component/BumperTimer/BumperTimerComponent.cpp + sources/System/BumperTimer/BumperTimerSystem.hpp + sources/System/BumperTimer/BumperTimerSystem.cpp ) add_executable(bomberman diff --git a/sources/Component/BumperTimer/BumperTimerComponent.cpp b/sources/Component/BumperTimer/BumperTimerComponent.cpp new file mode 100644 index 00000000..1d661395 --- /dev/null +++ b/sources/Component/BumperTimer/BumperTimerComponent.cpp @@ -0,0 +1,17 @@ +// +// Created by Tom Augier on 2021-05-20. +// + +#include "BumperTimerComponent.hpp" + +namespace BBM +{ + BumperTimerComponent::BumperTimerComponent(WAL::Entity &entity) + : WAL::Component(entity) + {} + + WAL::Component *BumperTimerComponent::clone(WAL::Entity &entity) const + { + return new BumperTimerComponent(entity); + } +} \ No newline at end of file diff --git a/sources/Component/BumperTimer/BumperTimerComponent.hpp b/sources/Component/BumperTimer/BumperTimerComponent.hpp new file mode 100644 index 00000000..dbeba275 --- /dev/null +++ b/sources/Component/BumperTimer/BumperTimerComponent.hpp @@ -0,0 +1,41 @@ +// +// Created by Tom Augier on 2021-05-20. +// + +#pragma once + +#include +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" + +using namespace std::chrono_literals; + +namespace BBM +{ + class BumperTimerComponent : public WAL::Component + { + public: + + + bool _isReseting = false; + //! @brief The number of seconds of each refill. This variable is used to reset the nextBombRefill value. + std::chrono::nanoseconds resetRate = 1500ms; + //! @brief The number of nanosecond before the next bomb refill. + std::chrono::nanoseconds nextReset = resetRate; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Constructor + BumperTimerComponent(WAL::Entity &entity); + + //! @brief A BumperTimer component can't be instantiated, it should be derived. + BumperTimerComponent(const BumperTimerComponent &) = default; + + //! @brief default destructor + ~BumperTimerComponent() override = default; + + //! @brief A BumperTimer component can't be assigned + BumperTimerComponent &operator=(const BumperTimerComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Component/Gravity/GravityComponent.hpp b/sources/Component/Gravity/GravityComponent.hpp index f2b6a368..59f7cc89 100644 --- a/sources/Component/Gravity/GravityComponent.hpp +++ b/sources/Component/Gravity/GravityComponent.hpp @@ -4,7 +4,6 @@ #pragma once -#include #include "Component/Component.hpp" #include "Entity/Entity.hpp" diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index fb26dd2f..9d76bf45 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -7,6 +7,7 @@ #include "System/Collision/CollisionSystem.hpp" #include "Map.hpp" #include +#include namespace RAY3D = RAY::Drawables::Drawables3D; @@ -17,10 +18,14 @@ namespace BBM CollisionComponent::CollidedAxis collidedAxis) { auto *movable = entity.tryGetComponent(); + auto *bumperTimer = entity.tryGetComponent(); - if (!movable) + if (!movable || !bumperTimer) return; - movable->_velocity.y = 0.5; + if (!bumperTimer->_isReseting) { + movable->_velocity.y = 1.5; + bumperTimer->_isReseting = true; + } } void MapGenerator::holeCollide(WAL::Entity &entity, @@ -197,7 +202,10 @@ namespace BBM scene->addEntity("Upper Floor") .addComponent(Vector3f(coords)) - .addComponent(floorObj, std::make_pair(MAP_DIFFUSE, floorPng)); + .addComponent(floorObj, std::make_pair(MAP_DIFFUSE, floorPng)) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, 0.25, 0.75); } @@ -308,9 +316,25 @@ namespace BBM MapGenerator::MapBlock MapGenerator::createSpawner(MapBlock map, int width, int height) { map[std::make_tuple(0, 0, 0)] = SPAWNER; + map[std::make_tuple(0, 0, 1)] = SPAWNER; + map[std::make_tuple(0, 0, 2)] = SPAWNER; + map[std::make_tuple(1, 0, 0)] = SPAWNER; + map[std::make_tuple(2, 0, 0)] = SPAWNER; map[std::make_tuple(width, 0, 0)] = SPAWNER; + map[std::make_tuple(width - 1, 0, 0)] = SPAWNER; + map[std::make_tuple(width - 2, 0, 0)] = SPAWNER; + map[std::make_tuple(width, 0, 1)] = SPAWNER; + map[std::make_tuple(width, 0, 2)] = SPAWNER; map[std::make_tuple(0, 0, height)] = SPAWNER; + map[std::make_tuple(1, 0, height)] = SPAWNER; + map[std::make_tuple(2, 0, height)] = SPAWNER; + map[std::make_tuple(0, 0, height - 1)] = SPAWNER; + map[std::make_tuple(0, 0, height - 2)] = SPAWNER; map[std::make_tuple(width, 0, height)] = SPAWNER; + map[std::make_tuple(width, 0, height - 1)] = SPAWNER; + map[std::make_tuple(width, 0, height - 2)] = SPAWNER; + map[std::make_tuple(width - 1, 0, height)] = SPAWNER; + map[std::make_tuple(width - 2, 0, height)] = SPAWNER; return map; } @@ -321,6 +345,8 @@ namespace BBM for (int j = 0; j < height; j++) { if (map[std::make_tuple(i, 0, j)] == BREAKABLE && map[std::make_tuple(i, -1, j)] == BUMPER) map[std::make_tuple(i, 0, j)] = NOTHING; + if (map[std::make_tuple(i, 1, j)] == BREAKABLE && isCloseToBlockType(map, i, -1, j, BUMPER)) + map[std::make_tuple(i, 1, j)] = NOTHING; } return (map); } diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index de4c821f..5cdcbd3a 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -41,6 +41,8 @@ #include "System/Music/MusicSystem.hpp" #include "Component/Gravity/GravityComponent.hpp" #include "System/Gravity/GravitySystem.hpp" +#include "Component/BumperTimer/BumperTimerComponent.hpp" +#include "System/BumperTimer/BumperTimerSystem.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY2D = RAY::Drawables::Drawables2D; @@ -69,6 +71,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem() .addSystem(); } @@ -92,7 +95,7 @@ namespace BBM //{SoundComponent::DEATH, "assets/sounds/death.ogg"} }; scene->addEntity("player") - .addComponent() + .addComponent(0, 1.01, 0) .addComponent("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent() .addComponent() @@ -106,6 +109,7 @@ namespace BBM .addComponent(soundPath) .addComponent() .addComponent() + .addComponent() .addComponent(1, [](WAL::Entity &entity) { auto &animation = entity.getComponent(); animation.setAnimIndex(5); diff --git a/sources/System/BumperTimer/BumperTimerSystem.cpp b/sources/System/BumperTimer/BumperTimerSystem.cpp new file mode 100644 index 00000000..36c8b93f --- /dev/null +++ b/sources/System/BumperTimer/BumperTimerSystem.cpp @@ -0,0 +1,25 @@ +// +// Created by Tom Augier on 2021-06-09. +// + +#include "BumperTimerSystem.hpp" + +namespace BBM +{ + BumperTimerSystem::BumperTimerSystem(WAL::Wal &wal) + : System(wal) + {} + + void BumperTimerSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) + { + auto &bumperTimer = entity.get(); + + if (bumperTimer._isReseting) { + bumperTimer.nextReset -= dtime; + if (bumperTimer.nextReset <= 0ns) { + bumperTimer.nextReset = bumperTimer.resetRate; + bumperTimer._isReseting = false; + } + } + } +} \ No newline at end of file diff --git a/sources/System/BumperTimer/BumperTimerSystem.hpp b/sources/System/BumperTimer/BumperTimerSystem.hpp new file mode 100644 index 00000000..d1bbe2e8 --- /dev/null +++ b/sources/System/BumperTimer/BumperTimerSystem.hpp @@ -0,0 +1,29 @@ +// +// Created by Tom Augier on 2021-06-09. +// + +#pragma once + +#include "Component/Movable/MovableComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/BumperTimer/BumperTimerComponent.hpp" +#include "System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle BumperTimer entities. + class BumperTimerSystem : public WAL::System + { + public: + //! @inherit + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; + //! @brief A default constructor + explicit BumperTimerSystem(WAL::Wal &wal); + //! @brief A BumperTimer system is copy constructable + BumperTimerSystem(const BumperTimerSystem &) = default; + //! @brief A default destructor + ~BumperTimerSystem() override = default; + //! @brief A system is not assignable. + BumperTimerSystem &operator=(const BumperTimerSystem &) = delete; + }; +} \ No newline at end of file diff --git a/sources/System/Gravity/GravitySystem.cpp b/sources/System/Gravity/GravitySystem.cpp index 8e0801e1..6459ed79 100644 --- a/sources/System/Gravity/GravitySystem.cpp +++ b/sources/System/Gravity/GravitySystem.cpp @@ -16,6 +16,6 @@ namespace BBM auto &position = entity.get(); if (position.getY() > 0) - movable.addForce(Vector3f(0, -0.5, 0)); + movable.addForce(Vector3f(0, -0.1, 0)); } } \ No newline at end of file