mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-05 02:49:57 +00:00
+5
-1
@@ -69,11 +69,15 @@ set(SOURCES
|
||||
sources/Component/Collision/CollisionComponent.hpp
|
||||
sources/System/Collision/CollisionSystem.hpp
|
||||
sources/System/Collision/CollisionSystem.cpp
|
||||
sources/Component/Animator/AnimatorComponent.cpp
|
||||
sources/Component/Animator/AnimatorComponent.hpp
|
||||
sources/System/Animator/AnimatorSystem.cpp
|
||||
sources/System/Animator/AnimatorSystem.hpp
|
||||
)
|
||||
add_executable(bomberman
|
||||
sources/main.cpp
|
||||
${SOURCES}
|
||||
)
|
||||
)
|
||||
target_include_directories(bomberman PUBLIC sources)
|
||||
target_link_libraries(bomberman PUBLIC wal ray)
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by hbenjamin on 03/06/2021.
|
||||
//
|
||||
|
||||
#include "AnimatorComponent.hpp"
|
||||
|
||||
namespace BBM {
|
||||
AnimatorComponent::AnimatorComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity)
|
||||
{}
|
||||
|
||||
WAL::Component *AnimatorComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new AnimatorComponent(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by hbenjamin on 03/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Entity/Entity.hpp>
|
||||
|
||||
namespace BBM {
|
||||
class AnimatorComponent : public WAL::Component
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief An Animator component can't be instantiated, it should be derived.
|
||||
explicit AnimatorComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief An Animator component can't be instantiated, it should be derived.
|
||||
AnimatorComponent(const AnimatorComponent &) = default;
|
||||
|
||||
//! @brief default destructor
|
||||
~AnimatorComponent() override = default;
|
||||
|
||||
//! @brief An Animator component can't be assigned
|
||||
AnimatorComponent &operator=(const AnimatorComponent &) = delete;
|
||||
};
|
||||
}
|
||||
@@ -6,16 +6,14 @@
|
||||
|
||||
#include "HealthComponent.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity),
|
||||
_healthPoint()
|
||||
{}
|
||||
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity, unsigned int healthPoint)
|
||||
: WAL::Component(entity),
|
||||
_healthPoint(healthPoint)
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity, unsigned int healthPoint, std::function<void (WAL::Entity &)> callback)
|
||||
: WAL::Component(entity),
|
||||
_healthPoint(healthPoint),
|
||||
onDeath(std::move(callback))
|
||||
{}
|
||||
|
||||
WAL::Component *HealthComponent::clone(WAL::Entity &entity) const
|
||||
|
||||
@@ -34,12 +34,9 @@ namespace BBM
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief A Health component can't be instantiated, it should be derived.
|
||||
explicit HealthComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief Constructor
|
||||
HealthComponent(WAL::Entity &entity, unsigned int healthPoint);
|
||||
explicit HealthComponent(WAL::Entity &entity, unsigned int healthPoint = 1, std::function<void (WAL::Entity &)> callback = {});
|
||||
|
||||
//! @brief A Health component can't be instantiated, it should be derived.
|
||||
HealthComponent(const HealthComponent &) = default;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <cmath>
|
||||
#include "Vector/Vector2.hpp"
|
||||
|
||||
#define PI_NUMBER 3.14159265359
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A Vector2 data type. (templated to allow any kind of vector2)
|
||||
@@ -120,6 +122,13 @@ namespace BBM
|
||||
return std::sqrt(std::pow(this->x - o.x, 2) + std::pow(this->y - o.y, 2));
|
||||
}
|
||||
|
||||
double angle(const Vector2<T> &o) const
|
||||
{
|
||||
float dot = this->x * o.x + this->y * o.y;
|
||||
float det = this->x * o.y - this->y * o.x;
|
||||
return (std::atan2(det, dot) * (180.0f / PI_NUMBER));
|
||||
}
|
||||
|
||||
double magnitude() const
|
||||
{
|
||||
return std::sqrt(std::pow(this->x, 2) + std::pow(this->y, 2));
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "Runner.hpp"
|
||||
#include "Models/GameState.hpp"
|
||||
#include <Model/ModelAnimations.hpp>
|
||||
#include <Component/Animator/AnimatorComponent.hpp>
|
||||
#include <System/Animator/AnimatorSystem.hpp>
|
||||
#include "Component/Animation/AnimationsComponent.hpp"
|
||||
#include "System/Animation/AnimationsSystem.hpp"
|
||||
#include "Map/Map.hpp"
|
||||
@@ -54,6 +56,7 @@ namespace BBM
|
||||
RAY::TraceLog::setLevel(LOG_WARNING);
|
||||
RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE);
|
||||
wal.addSystem<AnimationsSystem>()
|
||||
.addSystem<AnimatorSystem>()
|
||||
.addSystem<RenderSystem>(window);
|
||||
}
|
||||
|
||||
@@ -64,11 +67,15 @@ namespace BBM
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<AnimatorComponent>()
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
|
||||
.addComponent<CollisionComponent>(1)
|
||||
.addComponent<MovableComponent>();
|
||||
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
||||
auto &animation = entity.getComponent<AnimationsComponent>();
|
||||
animation.setAnimIndex(5);
|
||||
});
|
||||
scene->addEntity("camera")
|
||||
.addComponent<PositionComponent>(8, 20, 7)
|
||||
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by hbenjamin on 03/06/2021.
|
||||
//
|
||||
|
||||
#include <Component/Animator/AnimatorComponent.hpp>
|
||||
#include <Component/Keyboard/KeyboardComponent.hpp>
|
||||
#include <Controllers/Keyboard.hpp>
|
||||
#include <Model/Model.hpp>
|
||||
#include <Component/Animation/AnimationsComponent.hpp>
|
||||
#include <Component/Controllable/ControllableComponent.hpp>
|
||||
#include "AnimatorSystem.hpp"
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
|
||||
using Keyboard = RAY::Controller::Keyboard;
|
||||
namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
using Key = RAY::Controller::Keyboard::Key;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
AnimatorSystem::AnimatorSystem(WAL::Wal &wal)
|
||||
: System(wal)
|
||||
{}
|
||||
|
||||
void AnimatorSystem::onFixedUpdate(WAL::ViewEntity<AnimationsComponent, ControllableComponent, Drawable3DComponent> &entity)
|
||||
{
|
||||
const auto &controllable = entity.get<ControllableComponent>();
|
||||
auto drawable = entity.get<Drawable3DComponent>().drawable.get();
|
||||
auto &animation = entity.get<AnimationsComponent>();
|
||||
auto anim = dynamic_cast<RAY3D::Model *>(drawable);
|
||||
if (anim && controllable.move != Vector2f(0, 0)) {
|
||||
anim->setRotationAngle(controllable.move.angle(Vector2f(-1, 0)));
|
||||
animation.setAnimIndex(0);
|
||||
return;
|
||||
}
|
||||
animation.setAnimIndex(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by hbenjamin on 03/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Component/Renderer/Drawable3DComponent.hpp>
|
||||
#include "Component/Animation/AnimationsComponent.hpp"
|
||||
#include "System/System.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A system to handle Animator entities.
|
||||
class AnimatorSystem : public WAL::System<AnimationsComponent, ControllableComponent, Drawable3DComponent>
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::ViewEntity<AnimationsComponent, ControllableComponent, Drawable3DComponent> &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
AnimatorSystem(WAL::Wal &wal);
|
||||
//! @brief An Animator system is copy constructable
|
||||
AnimatorSystem(const AnimatorSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~AnimatorSystem() override = default;
|
||||
//! @brief An Animator system is assignable.
|
||||
AnimatorSystem &operator=(const AnimatorSystem &) = default;
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#include <Component/Animation/AnimationsComponent.hpp>
|
||||
#include "HealthSystem.hpp"
|
||||
#include "Component/Health/HealthComponent.hpp"
|
||||
#include "Component/Controllable/ControllableComponent.hpp"
|
||||
@@ -18,7 +19,8 @@ namespace BBM
|
||||
{
|
||||
auto &health = entity.get<HealthComponent>();
|
||||
|
||||
if (health.getHealthPoint() == 0)
|
||||
if (health.getHealthPoint() == 0) {
|
||||
health.onDeath(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user