mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-21 05:45:10 +00:00
bumperComponent + fix map
This commit is contained in:
@@ -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
|
||||
|
||||
17
sources/Component/BumperTimer/BumperTimerComponent.cpp
Normal file
17
sources/Component/BumperTimer/BumperTimerComponent.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
41
sources/Component/BumperTimer/BumperTimerComponent.hpp
Normal file
41
sources/Component/BumperTimer/BumperTimerComponent.hpp
Normal 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;
|
||||
};
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Models/Callback.hpp>
|
||||
#include "Component/Component.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "System/Collision/CollisionSystem.hpp"
|
||||
#include "Map.hpp"
|
||||
#include <Component/Tag/TagComponent.hpp>
|
||||
#include <Component/BumperTimer/BumperTimerComponent.hpp>
|
||||
|
||||
namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
|
||||
@@ -17,10 +18,14 @@ namespace BBM
|
||||
CollisionComponent::CollidedAxis collidedAxis)
|
||||
{
|
||||
auto *movable = entity.tryGetComponent<MovableComponent>();
|
||||
auto *bumperTimer = entity.tryGetComponent<BumperTimerComponent>();
|
||||
|
||||
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<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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<CollisionSystem>()
|
||||
.addSystem<MovableSystem>()
|
||||
.addSystem<GravitySystem>()
|
||||
.addSystem<BumperTimerSystem>()
|
||||
.addSystem<PlayerSoundManagerSystem>()
|
||||
.addSystem<MusicSystem>();
|
||||
}
|
||||
@@ -92,7 +95,7 @@ namespace BBM
|
||||
//{SoundComponent::DEATH, "assets/sounds/death.ogg"}
|
||||
};
|
||||
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<ControllableComponent>()
|
||||
.addComponent<AnimatorComponent>()
|
||||
@@ -106,6 +109,7 @@ namespace BBM
|
||||
.addComponent<SoundComponent>(soundPath)
|
||||
.addComponent<GravityComponent>()
|
||||
.addComponent<BombHolderComponent>()
|
||||
.addComponent<BumperTimerComponent>()
|
||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
||||
auto &animation = entity.getComponent<AnimationsComponent>();
|
||||
animation.setAnimIndex(5);
|
||||
|
||||
25
sources/System/BumperTimer/BumperTimerSystem.cpp
Normal file
25
sources/System/BumperTimer/BumperTimerSystem.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
sources/System/BumperTimer/BumperTimerSystem.hpp
Normal file
29
sources/System/BumperTimer/BumperTimerSystem.hpp
Normal 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;
|
||||
};
|
||||
}
|
||||
@@ -16,6 +16,6 @@ namespace BBM
|
||||
auto &position = entity.get<PositionComponent>();
|
||||
|
||||
if (position.getY() > 0)
|
||||
movable.addForce(Vector3f(0, -0.5, 0));
|
||||
movable.addForce(Vector3f(0, -0.1, 0));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user