mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-22 22:35:12 +00:00
basic gravity
This commit is contained in:
@@ -92,6 +92,8 @@ 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.cpp
|
||||||
|
sources/System/Gravity/GravitySystem.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(bomberman
|
add_executable(bomberman
|
||||||
|
|||||||
17
sources/Component/Gravity/GravityComponent.cpp
Normal file
17
sources/Component/Gravity/GravityComponent.cpp
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
sources/Component/Gravity/GravityComponent.hpp
Normal file
32
sources/Component/Gravity/GravityComponent.hpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// Created by Tom Augier on 2021-05-20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Models/Callback.hpp>
|
||||||
|
#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;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -39,6 +39,8 @@
|
|||||||
#include "Component/Sound/SoundComponent.hpp"
|
#include "Component/Sound/SoundComponent.hpp"
|
||||||
#include "System/Sound/PlayerSoundManagerSystem.hpp"
|
#include "System/Sound/PlayerSoundManagerSystem.hpp"
|
||||||
#include "System/Music/MusicSystem.hpp"
|
#include "System/Music/MusicSystem.hpp"
|
||||||
|
#include "Component/Gravity/GravityComponent.hpp"
|
||||||
|
#include "System/Gravity/GravitySystem.hpp"
|
||||||
|
|
||||||
namespace RAY3D = RAY::Drawables::Drawables3D;
|
namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||||
namespace RAY2D = RAY::Drawables::Drawables2D;
|
namespace RAY2D = RAY::Drawables::Drawables2D;
|
||||||
@@ -66,6 +68,7 @@ namespace BBM
|
|||||||
.addSystem<HealthSystem>()
|
.addSystem<HealthSystem>()
|
||||||
.addSystem<CollisionSystem>()
|
.addSystem<CollisionSystem>()
|
||||||
.addSystem<MovableSystem>()
|
.addSystem<MovableSystem>()
|
||||||
|
.addSystem<GravitySystem>()
|
||||||
.addSystem<PlayerSoundManagerSystem>()
|
.addSystem<PlayerSoundManagerSystem>()
|
||||||
.addSystem<MusicSystem>();
|
.addSystem<MusicSystem>();
|
||||||
}
|
}
|
||||||
@@ -101,6 +104,7 @@ namespace BBM
|
|||||||
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
|
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
|
||||||
.addComponent<MovableComponent>()
|
.addComponent<MovableComponent>()
|
||||||
.addComponent<SoundComponent>(soundPath)
|
.addComponent<SoundComponent>(soundPath)
|
||||||
|
.addComponent<GravityComponent>()
|
||||||
.addComponent<BombHolderComponent>()
|
.addComponent<BombHolderComponent>()
|
||||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
||||||
auto &animation = entity.getComponent<AnimationsComponent>();
|
auto &animation = entity.getComponent<AnimationsComponent>();
|
||||||
|
|||||||
21
sources/System/Gravity/GravitySystem.cpp
Normal file
21
sources/System/Gravity/GravitySystem.cpp
Normal file
@@ -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<GravityComponent, MovableComponent, PositionComponent> &entity)
|
||||||
|
{
|
||||||
|
auto &movable = entity.get<MovableComponent>();
|
||||||
|
auto &position = entity.get<PositionComponent>();
|
||||||
|
|
||||||
|
if (position.getY() > 0)
|
||||||
|
movable.addForce(Vector3f(0, -0.5, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
30
sources/System/Gravity/GravitySystem.hpp
Normal file
30
sources/System/Gravity/GravitySystem.hpp
Normal file
@@ -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<GravityComponent, MovableComponent, PositionComponent>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! @inherit
|
||||||
|
void onFixedUpdate(WAL::ViewEntity<GravityComponent, MovableComponent, PositionComponent> &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;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user