bumperComponent + fix map

This commit is contained in:
Askou
2021-06-10 11:24:47 +02:00
parent 69563ad075
commit 4a1e7b085f
9 changed files with 153 additions and 6 deletions

View File

@@ -92,8 +92,14 @@ set(SOURCES
sources/System/Sound/PlayerSoundManagerSystem.hpp sources/System/Sound/PlayerSoundManagerSystem.hpp
sources/System/Music/MusicSystem.hpp sources/System/Music/MusicSystem.hpp
sources/System/Music/MusicSystem.cpp sources/System/Music/MusicSystem.cpp
sources/Component/Gravity/GravityComponent.hpp
sources/Component/Gravity/GravityComponent.cpp sources/Component/Gravity/GravityComponent.cpp
sources/System/Gravity/GravitySystem.hpp
sources/System/Gravity/GravitySystem.cpp 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 add_executable(bomberman

View File

@@ -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);
}
}

View File

@@ -0,0 +1,41 @@
//
// Created by Tom Augier on 2021-05-20.
//
#pragma once
#include <chrono>
#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;
};
}

View File

@@ -4,7 +4,6 @@
#pragma once #pragma once
#include <Models/Callback.hpp>
#include "Component/Component.hpp" #include "Component/Component.hpp"
#include "Entity/Entity.hpp" #include "Entity/Entity.hpp"

View File

@@ -7,6 +7,7 @@
#include "System/Collision/CollisionSystem.hpp" #include "System/Collision/CollisionSystem.hpp"
#include "Map.hpp" #include "Map.hpp"
#include <Component/Tag/TagComponent.hpp> #include <Component/Tag/TagComponent.hpp>
#include <Component/BumperTimer/BumperTimerComponent.hpp>
namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY3D = RAY::Drawables::Drawables3D;
@@ -17,10 +18,14 @@ namespace BBM
CollisionComponent::CollidedAxis collidedAxis) CollisionComponent::CollidedAxis collidedAxis)
{ {
auto *movable = entity.tryGetComponent<MovableComponent>(); auto *movable = entity.tryGetComponent<MovableComponent>();
auto *bumperTimer = entity.tryGetComponent<BumperTimerComponent>();
if (!movable) if (!movable || !bumperTimer)
return; return;
movable->_velocity.y = 0.5; if (!bumperTimer->_isReseting) {
movable->_velocity.y = 1.5;
bumperTimer->_isReseting = true;
}
} }
void MapGenerator::holeCollide(WAL::Entity &entity, void MapGenerator::holeCollide(WAL::Entity &entity,
@@ -197,7 +202,10 @@ namespace BBM
scene->addEntity("Upper Floor") scene->addEntity("Upper Floor")
.addComponent<PositionComponent>(Vector3f(coords)) .addComponent<PositionComponent>(Vector3f(coords))
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj, std::make_pair(MAP_DIFFUSE, floorPng)); .addComponent<Drawable3DComponent, RAY3D::Model>(floorObj, std::make_pair(MAP_DIFFUSE, floorPng))
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, 0.75);
} }
@@ -308,9 +316,25 @@ namespace BBM
MapGenerator::MapBlock MapGenerator::createSpawner(MapBlock map, int width, int height) MapGenerator::MapBlock MapGenerator::createSpawner(MapBlock map, int width, int height)
{ {
map[std::make_tuple(0, 0, 0)] = SPAWNER; 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, 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(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)] = 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; return map;
} }
@@ -321,6 +345,8 @@ namespace BBM
for (int j = 0; j < height; j++) { for (int j = 0; j < height; j++) {
if (map[std::make_tuple(i, 0, j)] == BREAKABLE && map[std::make_tuple(i, -1, j)] == BUMPER) 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; 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); return (map);
} }

View File

@@ -41,6 +41,8 @@
#include "System/Music/MusicSystem.hpp" #include "System/Music/MusicSystem.hpp"
#include "Component/Gravity/GravityComponent.hpp" #include "Component/Gravity/GravityComponent.hpp"
#include "System/Gravity/GravitySystem.hpp" #include "System/Gravity/GravitySystem.hpp"
#include "Component/BumperTimer/BumperTimerComponent.hpp"
#include "System/BumperTimer/BumperTimerSystem.hpp"
namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY3D = RAY::Drawables::Drawables3D;
namespace RAY2D = RAY::Drawables::Drawables2D; namespace RAY2D = RAY::Drawables::Drawables2D;
@@ -69,6 +71,7 @@ namespace BBM
.addSystem<CollisionSystem>() .addSystem<CollisionSystem>()
.addSystem<MovableSystem>() .addSystem<MovableSystem>()
.addSystem<GravitySystem>() .addSystem<GravitySystem>()
.addSystem<BumperTimerSystem>()
.addSystem<PlayerSoundManagerSystem>() .addSystem<PlayerSoundManagerSystem>()
.addSystem<MusicSystem>(); .addSystem<MusicSystem>();
} }
@@ -92,7 +95,7 @@ namespace BBM
//{SoundComponent::DEATH, "assets/sounds/death.ogg"} //{SoundComponent::DEATH, "assets/sounds/death.ogg"}
}; };
scene->addEntity("player") scene->addEntity("player")
.addComponent<PositionComponent>() .addComponent<PositionComponent>(0, 1.01, 0)
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
.addComponent<ControllableComponent>() .addComponent<ControllableComponent>()
.addComponent<AnimatorComponent>() .addComponent<AnimatorComponent>()
@@ -106,6 +109,7 @@ namespace BBM
.addComponent<SoundComponent>(soundPath) .addComponent<SoundComponent>(soundPath)
.addComponent<GravityComponent>() .addComponent<GravityComponent>()
.addComponent<BombHolderComponent>() .addComponent<BombHolderComponent>()
.addComponent<BumperTimerComponent>()
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) { .addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
auto &animation = entity.getComponent<AnimationsComponent>(); auto &animation = entity.getComponent<AnimationsComponent>();
animation.setAnimIndex(5); animation.setAnimIndex(5);

View File

@@ -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<BumperTimerComponent> &entity, std::chrono::nanoseconds dtime)
{
auto &bumperTimer = entity.get<BumperTimerComponent>();
if (bumperTimer._isReseting) {
bumperTimer.nextReset -= dtime;
if (bumperTimer.nextReset <= 0ns) {
bumperTimer.nextReset = bumperTimer.resetRate;
bumperTimer._isReseting = false;
}
}
}
}

View File

@@ -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<BumperTimerComponent>
{
public:
//! @inherit
void onUpdate(WAL::ViewEntity<BumperTimerComponent> &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;
};
}

View File

@@ -16,6 +16,6 @@ namespace BBM
auto &position = entity.get<PositionComponent>(); auto &position = entity.get<PositionComponent>();
if (position.getY() > 0) if (position.getY() > 0)
movable.addForce(Vector3f(0, -0.5, 0)); movable.addForce(Vector3f(0, -0.1, 0));
} }
} }