diff --git a/CMakeLists.txt b/CMakeLists.txt index 86fed3b9..167bdb48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,14 @@ set(SOURCES sources/Parser/ParserYaml.cpp sources/Exception/Error.hpp sources/Exception/Error.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 sources/System/Bomb/BombSystem.cpp sources/System/Bomb/BombSystem.hpp sources/Component/IntroAnimation/IntroAnimationComponent.hpp 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..a0b8c958 --- /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 rest. This variable is used to reset the nextReset value. + std::chrono::nanoseconds resetRate = 1500ms; + //! @brief The number of nanosecond before the next bumper reset for the player. + 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.cpp b/sources/Component/Gravity/GravityComponent.cpp new file mode 100644 index 00000000..a6ee1db4 --- /dev/null +++ b/sources/Component/Gravity/GravityComponent.cpp @@ -0,0 +1,17 @@ +// +// Created by Tom Augier on 2021-05-20. +// + +#include "GravityComponent.hpp" + +namespace BBM +{ + GravityComponent::GravityComponent(WAL::Entity &entity) + : WAL::Component(entity) + {} + + WAL::Component *GravityComponent::clone(WAL::Entity &entity) const + { + return new GravityComponent(entity); + } +} \ No newline at end of file diff --git a/sources/Component/Gravity/GravityComponent.hpp b/sources/Component/Gravity/GravityComponent.hpp new file mode 100644 index 00000000..59f7cc89 --- /dev/null +++ b/sources/Component/Gravity/GravityComponent.hpp @@ -0,0 +1,31 @@ +// +// Created by Tom Augier on 2021-05-20. +// + +#pragma once + +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" + +namespace BBM +{ + class GravityComponent : public WAL::Component + { + public: + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Constructor + GravityComponent(WAL::Entity &entity); + + //! @brief A Gravity component can't be instantiated, it should be derived. + GravityComponent(const GravityComponent &) = default; + + //! @brief default destructor + ~GravityComponent() override = default; + + //! @brief A Gravity component can't be assigned + GravityComponent &operator=(const GravityComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 5530f9b6..f5a44c00 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -9,15 +9,41 @@ #include #include #include -#include "Component/Movable/MovableComponent.hpp" #include #include +#include namespace RAY3D = RAY::Drawables::Drawables3D; using namespace std::chrono_literals; namespace BBM { + void MapGenerator::bumperCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis) + { + auto *movable = entity.tryGetComponent(); + auto *bumperTimer = entity.tryGetComponent(); + + if (!movable || !bumperTimer) + return; + if (!bumperTimer->_isReseting) { + movable->_velocity.y = 1.5; + bumperTimer->_isReseting = true; + } + } + + void MapGenerator::holeCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis) + { + auto *health = entity.tryGetComponent(); + + if (!health) + return; + health->takeDmg(health->getHealthPoint()); + } + void MapGenerator::wallCollided(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis) @@ -125,7 +151,6 @@ namespace BBM .addComponent(i, 0, height + 1) .addComponent>(); } - scene->addEntity("Bottom Wall") .addComponent(Vector3f((width + 1) / 2, 0, -1)) .addComponent( @@ -168,7 +193,7 @@ namespace BBM for (int i = 0; i < width + 1; i++) { for (int j = 0; j < height + 1; j++) { if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, -1, j)] != BUMPER) - scene->addEntity("Floor") + scene->addEntity("Ground") .addComponent(Vector3f(i, -1, j)) .addComponent(floorObj, false, std::make_pair(MAP_DIFFUSE, floorPng)); @@ -186,6 +211,7 @@ namespace BBM {UPPERFLOOR, &createUpperFloor}, }; + std::cout << "blockType: " << blockType << std::endl; if (blockType == NOTHING || blockType == SPAWNER) return; auto element = elements.at(blockType); @@ -207,17 +233,6 @@ namespace BBM .addComponent(breakableObj, false, std::make_pair(MAP_DIFFUSE, breakablePng)); } - void MapGenerator::createFloor(Vector3f coords, std::shared_ptr scene) - { - static const std::string floorObj = floorPath + objExtension; - static const std::string floorPng = floorPath + imageExtension; - - scene->addEntity("Floor") - .addComponent(Vector3f(coords)) - //.addComponent(1) - .addComponent(floorObj, false, std::make_pair(MAP_DIFFUSE, floorPng)); - } - void MapGenerator::createUpperFloor(Vector3f coords, std::shared_ptr scene) { static const std::string floorObj = secondFloorPath + objExtension; @@ -253,19 +268,16 @@ namespace BBM WAL::Entity &holeEntity = scene->addEntity("Hole Block"); - holeEntity.addComponent(Vector3f(coords.x, coords.y - 1, coords.z)); - + holeEntity.addComponent(Vector3f(coords.x, coords.y - 1, coords.z)) + .addComponent( + WAL::Callback(), + &MapGenerator::holeCollide, Vector3f(0.25, 0.25, 0.25),Vector3f(0.75, 1.75, 0.75)); if (coords.y == 0) holeEntity.addComponent(holeObj, false, std::make_pair(MAP_DIFFUSE, holePng)); else holeEntity.addComponent(secondFloorObj, false, std::make_pair(MAP_DIFFUSE, secondFloorPng)); - /*.addComponent([](WAL::Entity &other, const WAL::Entity &entity) { - if (other.hasComponent()) { - auto &health = other.getComponent(); - health.takeDmg(health.getHealthPoint()); - } - }, [](WAL::Entity &other, const WAL::Entity &entity){}); */ + } void MapGenerator::createBumper(Vector3f coords, std::shared_ptr scene) @@ -275,13 +287,10 @@ namespace BBM scene->addEntity("Bumper Block") .addComponent(Vector3f(coords.x, coords.y, coords.z)) - .addComponent(bumperObj, false, std::make_pair(MAP_DIFFUSE, bumperPng)); - /* .addComponent([](const WAL::Entity &entity, WAL::Entity &other) { - if (other.hasComponent()) { - auto &movable = other.getComponent(); - movable.addForce(Vector3f(0, 5, 0)); - } - }); */ + .addComponent(bumperObj, false,std::make_pair(MAP_DIFFUSE, bumperPng)) + .addComponent( + WAL::Callback(), + &MapGenerator::bumperCollide, Vector3f(0.25, 0.25, 0.25),Vector3f(0.75, 0.75, 0.75)); } bool MapGenerator::isCloseToBlockType(std::map, BlockType> map, int x, int y, int z, @@ -297,7 +306,7 @@ namespace BBM { double rnd = static_cast(std::rand()) / RAND_MAX; - if (rnd > 0.95) + if (rnd > 0.98) return HOLE; if (rnd > 0.25) return BREAKABLE; @@ -308,7 +317,7 @@ namespace BBM { double rnd = static_cast(std::rand()) / RAND_MAX; - if (rnd > 0.60) { + if (rnd > 0.01) { for (int i = 0; i < width + 1; i++) { map[std::make_tuple(i, 1, height)] = map[std::make_tuple(i, 0, height)]; map[std::make_tuple(i, 0, height)] = UPPERFLOOR; @@ -321,12 +330,10 @@ namespace BBM map[std::make_tuple(width, -1, 1)] = BUMPER; map[std::make_tuple(width / 2, -1, height - 1)] = BUMPER; map[std::make_tuple(width / 2, -1, 1)] = BUMPER; - } - if (rnd > 0.30) { + } + if (rnd > 0.01) { for (int i = width / 2 - width / 4; i < width / 2 + width / 4 + 1; i++) { for (int j = height / 2 - height / 4; j < height / 2 + height / 4 + 1; j++) { - if (map[std::make_tuple(i, 0, j)] == FLOOR) - continue; map[std::make_tuple(i, 1, j)] = map[std::make_tuple(i, 0, j)]; map[std::make_tuple(i, 0, j)] = UPPERFLOOR; } @@ -355,26 +362,60 @@ 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); } - MapGenerator::MapBlock MapGenerator::createMap(int width, int height) + MapGenerator::MapBlock MapGenerator::createClassicUnbreakable(MapBlock map, int width, int height) + { + for (int i = 0; i < width + 1; i++) { + for (int j = 0; j < height + 1; j++) { + if (!((i + 1) % 2) && !((j + 1) % 2)) + map[std::make_tuple(i, 0, j)] = UNBREAKABLE; + } + } + return (map); + } + + MapGenerator::MapBlock MapGenerator::createLongClassicUnbreakable(MapBlock map, int width, int height) + { + int placedSpace = 0; + + for (int i = 1; i < width; i++) { + placedSpace = 0; + for (int j = 1; j < height; j++) { + if (!(j % 2)) + continue; + if (i < (width / 2 - width / 10) || i > (width / 2 + width / 10)) + map[std::make_tuple(i, 0, j)] = UNBREAKABLE; + else + placedSpace++; + } + } + return (map); + } + + + MapGenerator::MapBlock MapGenerator::createMap(int width, int height, bool isHeight, bool isNotClassic) { MapBlock map; width = width % 2 ? width + 1 : width; height = height % 2 ? height + 1 : height; - for (int i = 0; i < width; i++) - for (int j = 0; j < height; j++) + for (int i = 0; i < width + 1; i++) + for (int j = 0; j < height + 1; j++) { map[std::make_tuple(i, 0, j)] = NOTHING; + map[std::make_tuple(i, 1, j)] = NOTHING; + } map = createSpawner(map, width, height); for (int i = 0; i < width + 1; i++) { for (int j = 0; j < height + 1; j++) { if (map[std::make_tuple(i, 0, j)] == SPAWNER) continue; if (isCloseToBlockType(map, i, 0, j, SPAWNER)) { - map[std::make_tuple(i, 0, j)] = NOTHING; + map[std::make_tuple(i, isNotClassic ? -1 : 0, j)] = isNotClassic ? BUMPER : NOTHING; } else { map[std::make_tuple(i, 0, j)] = getRandomBlockType(); } @@ -382,17 +423,59 @@ namespace BBM map[std::make_tuple(i, 0, j)] = BREAKABLE; } } - for (int i = 0; i < width + 1; i++) - for (int j = 0; j < height + 1; j++) - if (!((i + 1) % 2) && !((j + 1) % 2)) - map[std::make_tuple(i, 0, j)] = UNBREAKABLE; - map = createHeight(map, width, height); + if (!isNotClassic) + map = createClassicUnbreakable(map, width, height); + else + map = createLongClassicUnbreakable(map, width, height); + if (isHeight) + map = createHeight(map, width, height); map = cleanBreakable(map, width, height); return (map); } + void MapGenerator::generateHeightCollision(MapBlock map, int width, int height, std::shared_ptr scene) + { + int floor = 2; + + for (int i = 0; i < width + 1; i++) { + if (map[std::make_tuple(i, 0, height)] == NOTHING && map[std::make_tuple(i, 0, 0)] == NOTHING) { + floor -= 1; + break; + } + } + for (int i = width / 2 - width / 4; i < width / 2 + width / 4 + 1; i++) { + for (int j = height / 2 - height / 4; j < height / 2 + height / 4 + 1; j++) { + if (map[std::make_tuple(i, 0, i)] == NOTHING) { + floor -= 1; + break; + } + } + if (floor <= 0) + break; + } + if (floor >= 1) { + scene->addEntity("FloorBot Hitbox") + .addComponent(Vector3f(0, 0, 0)) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollided, Vector3f(0.25, 0.25, 0.25), Vector3f(width, 0.75, 0.75)); + scene->addEntity("FloorUp Hitbox") + .addComponent(Vector3f(0, 0, height)) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollided, Vector3f(0.25, 0.25, 0.25),Vector3f(width, 0.75, 0.75)); + } + if (floor >= 2) + scene->addEntity("Middle Hitbox") + .addComponent(Vector3f(width / 2 - width / 4, 0, height / 2 - height / 4)) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollided, Vector3f(0.25, 0.25, 0.25),Vector3f(width, 0.75, height / 2 + height / 4)); + } + void MapGenerator::loadMap(int width, int height, MapBlock map, const std::shared_ptr &scene) - { + { + //generateHeightCollision(map, width, height, scene); generateWall(width, height, scene); generateFloor(map, width, height, scene); for (int x = 0; x < width + 1; x++) diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index ed73cf42..380fa809 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -38,7 +38,6 @@ namespace BBM BREAKABLE, HOLE, UPPERFLOOR, - FLOOR, BUMPER, SPAWNER, UNBREAKABLE, @@ -52,11 +51,20 @@ namespace BBM CollisionComponent::CollidedAxis collidedAxis); static void wallDestroyed(WAL::Entity &entity, WAL::Wal &wal); + static void holeCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis); + + static void bumperCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis); + + //! @param width Width of the map //! @param height Height of the map //! @brief Generate map of block to be loaded - static MapBlock createMap(int width, int height); + static MapBlock createMap(int width, int height, bool isHeight = false, bool isNotClassic = false); //! @param width Width of the map //! @param height Height of the map @@ -122,16 +130,30 @@ namespace BBM //! @brief Create bumper of the map static void createBumper(Vector3f coords, std::shared_ptr scene); - //! @param coords coords of the element - //! @param scene Scene where the map is instanced - //! @brief Create floor of the map - static void createFloor(Vector3f coords, std::shared_ptr scene); - //! @param coords coords of the element //! @param scene Scene where the map is instanced //! @brief Create upper floor of the map static void createUpperFloor(Vector3f coords, std::shared_ptr scene); + //! @param width Width of the map + //! @param height Height of the map + //! @param scene Scene where the map is instanced + //! @brief Generate the height hitbox of the map + static void generateHeightCollision(MapBlock map, int width, int height, + std::shared_ptr scene); + + //! @param map Map to load with block declared inside + //! @param width Width of the map + //! @param height Height of the map + //! @brief Generate unbreakable block on the map + static MapBlock createClassicUnbreakable(MapBlock map, int width, int height); + + //! @param map Map to load with block declared inside + //! @param width Width of the map + //! @param height Height of the map + //! @brief Generate unbreakable block on map + static MapBlock createLongClassicUnbreakable(MapBlock map, int width, int height); + //! @param map Map to load with block declared inside //! @param width Width of the map //! @param height Height of the map diff --git a/sources/Parser/ParserYaml.cpp b/sources/Parser/ParserYaml.cpp index 872be65c..779b8e60 100644 --- a/sources/Parser/ParserYaml.cpp +++ b/sources/Parser/ParserYaml.cpp @@ -249,6 +249,7 @@ namespace BBM { _loadBlock(scene, lines, index, map); index--; } + std::cout << "Test LoadMap" << std::endl; MapGenerator::loadMap(Runner::width, Runner::height, map, scene); } diff --git a/sources/Parser/ParserYaml.hpp b/sources/Parser/ParserYaml.hpp index 60e2e193..7a57a995 100644 --- a/sources/Parser/ParserYaml.hpp +++ b/sources/Parser/ParserYaml.hpp @@ -11,32 +11,87 @@ namespace BBM { class ParserYAML { private: + + //!@brief file block of the parser static std::string _block; + //!@brief file bonus of the parser static std::string _bonus; + //!@brief file player of the parser static std::string _player; + //!@param entity entity to save + //!@brief save block in _block static void _saveBlock(const WAL::Entity &entity); + //!@param entity entity to save + //!@brief save bonus in _bonus static void _saveBonus(const WAL::Entity &entity); + //!@param entity entity to save + //!@brief save player in _player static void _savePlayer(const WAL::Entity &entity); + //!@param blockName block name + //!@brief transform block name static std::string _getBlockType(std::string blockName); + //!@param blockName bonus name + //!@brief transform bonus name static std::string _getBonusType(std::string bonusName); + //!@param line to parse + //!@param entity to update + //!@brief parse entity name static WAL::Entity &_parseEntityName(std::string line, WAL::Entity &entity); + //!@param line to parse + //!@brief return max bomb parsed static int _parseMaxBomb(std::string &filename); + //!@param line to parse + //!@brief return explosion radius parsed static float _parseExplosionRadius(std::string &filename); + //!@param line to parse + //!@brief return vector3f of position parsed static Vector3f _parsePosition(std::string &filename); + //!@param blockType to parse + //!@brief return BlockType of type parsed static MapGenerator::BlockType _parseBlockType(std::string blockType); + //!@param bonusType to parse + //!@brief return bonusType of type parsed static Bonus::BonusType _parseBonusType(std::string bonusType); + //!@param scene Scene to update + //!@param lines Lines of the file + //!@param index index of the vector + //!@brief add player into scene static void _loadPlayer(std::shared_ptr scene, std::vector lines, int &index); + //!@param scene Scene to update + //!@param lines Lines of the file + //!@param index index of the vector + //!@param map map of all the block + //!@brief add block into scene static void _loadBlock(std::shared_ptr scene, std::vector lines, int &index, MapGenerator::MapBlock &map); + //!@param scene Scene to update + //!@param lines Lines of the file + //!@param index index of the vector + //!@brief add bonus into scene static void _loadBonus(std::shared_ptr scene, std::vector lines, int &index); + //!@param scene Scene to update + //!@param filename filename of the file to read + //!@brief load all players into scene static void _loadPlayers(std::shared_ptr scene, std::string filename); + //!@param scene Scene to update + //!@param filename filename of the file to read + //!@brief load all blocks into scene static void _loadBlocks(std::shared_ptr scene, std::string filename); + //!@param scene Scene to update + //!@param filename filename of the file to read + //!@brief load all blocks into scene static void _loadBonuses(std::shared_ptr scene, std::string filename); public: + //!@param scene Scene to update + //!@param filename filename of the file to read + //!@brief save yaml static void save(std::shared_ptr scene, std::string filename); + //!@param scene Scene to update + //!@param filename filename of the file to read + //!@brief load yaml static void load(std::shared_ptr scene, std::string filename); }; diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 4c284bb4..ebf8abd3 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -21,6 +21,8 @@ #include "Component/Renderer/Drawable3DComponent.hpp" #include "Component/Button/ButtonComponent.hpp" #include "Drawables/2D/Text.hpp" +#include "Component/Gravity/GravityComponent.hpp" +#include "Component/BumperTimer/BumperTimerComponent.hpp" #include "Model/Model.hpp" #include "Map/Map.hpp" @@ -41,10 +43,12 @@ namespace BBM //{SoundComponent::DEATH, "assets/sounds/death.ogg"} }; /*scene->addEntity("Player") - .addComponent() + .addComponent(0, 1.01, 0) .addComponent("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent() .addComponent() + .addComponent() + .addComponent() .addComponent() .addComponent("assets/shaders/glsl330/predator.fs") .addComponent>() diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 8c072cf8..5601600a 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -32,6 +32,8 @@ #include #include "System/Sound/PlayerSoundManagerSystem.hpp" #include "System/Sound/MenuSoundManagerSystem.hpp" +#include "System/Gravity/GravitySystem.hpp" +#include "System/BumperTimer/BumperTimerSystem.hpp" #include "System/Music/MusicSystem.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; @@ -85,6 +87,8 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() + .addSystem() .addSystem(); } diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index c7fc11e7..c5631190 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -75,4 +75,4 @@ namespace BBM //! @brief A bomb holder system is not assignable. BombHolderSystem &operator=(const BombHolderSystem &) = delete; }; -} +} \ No newline at end of file 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 new file mode 100644 index 00000000..a61e4220 --- /dev/null +++ b/sources/System/Gravity/GravitySystem.cpp @@ -0,0 +1,21 @@ +// +// Created by Tom Augier on 2021-06-09. +// + +#include "GravitySystem.hpp" + +namespace BBM +{ + GravitySystem::GravitySystem(WAL::Wal &wal) + : System(wal) + {} + + void GravitySystem::onFixedUpdate(WAL::ViewEntity &entity) + { + auto &movable = entity.get(); + auto &position = entity.get(); + + if (position.getY() > 0) + movable.addForce(Vector3f(0, -0.1, 0)); + } +} \ No newline at end of file diff --git a/sources/System/Gravity/GravitySystem.hpp b/sources/System/Gravity/GravitySystem.hpp new file mode 100644 index 00000000..59963ac7 --- /dev/null +++ b/sources/System/Gravity/GravitySystem.hpp @@ -0,0 +1,30 @@ +// +// Created by Tom Augier on 2021-06-09. +// + +#pragma once + +#include "Component/Movable/MovableComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/Gravity/GravityComponent.hpp" +#include "System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle Gravity entities. + class GravitySystem : public WAL::System + { + public: + //! @inherit + void onFixedUpdate(WAL::ViewEntity &entity) override; + + //! @brief A default constructor + explicit GravitySystem(WAL::Wal &wal); + //! @brief A Gravity system is copy constructable + GravitySystem(const GravitySystem &) = default; + //! @brief A default destructor + ~GravitySystem() override = default; + //! @brief A system is not assignable. + GravitySystem &operator=(const GravitySystem &) = delete; + }; +} \ No newline at end of file