Skip to content

Commit

Permalink
feat(Components): Add new components: NetworkEvent, Collider, and Spa…
Browse files Browse the repository at this point in the history
…wned
  • Loading branch information
MasterLaplace committed Jan 14, 2024
1 parent ce6d10b commit d045fe3
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 3 deletions.
41 changes: 41 additions & 0 deletions Flakkari/Engine/EntityComponentSystem/Components/2D/Collider.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2023-01-14
** File description:
** Collider
*/

#ifndef COLLIDER_HPP_
#define COLLIDER_HPP_

#include <string>
#include "../../../Math/Vector.hpp"

#include "Network/Packed.hpp"

namespace Flakkari::Engine::ECS::Components::_2D {
PACKED_START

/**
* @brief Collider component for ECS entities that have a script attached to them
*
* @details This component is used to store the path to the script that will be executed
*/
struct Collider {
Math::Vector2f _size;

Collider() : _size() {}
Collider(Math::Vector2f nsize) : _size(nsize) {}
Collider(const Collider &other) : _size(other._size) {}

std::size_t size() const {
return sizeof(_size);
}
};

PACKED_END
} // namespace Flakkari::Engine::ECS::Components::_2D

#endif /* !COLLIDER_HPP_ */
44 changes: 44 additions & 0 deletions Flakkari/Engine/EntityComponentSystem/Components/2D/RigidBody.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2023-01-14
** File description:
** RigidBody
*/

#ifndef RIGIDBODY_HPP_
#define RIGIDBODY_HPP_

#include "../../../Math/Vector.hpp"

#include "Network/Packed.hpp"

namespace Flakkari::Engine::ECS::Components::_2D {
PACKED_START

/**
* @brief RigidBody represent the physical properties of a rigid body in a game engine
*
*/
struct RigidBody {
float mass;
float restitution;
float friction;
float gravityScale;
bool isGravityAffected = true;
bool isKinematic = false;

RigidBody() : mass(0), restitution(0), friction(0), gravityScale(0), isGravityAffected(false), isKinematic(false) {};
RigidBody(const RigidBody &other) : mass(other.mass), restitution(other.restitution), friction(other.friction), gravityScale(other.gravityScale), isGravityAffected(other.isGravityAffected), isKinematic(other.isKinematic) {};
RigidBody(float mass, float restitution, float friction, float gravityScale) : mass(mass), restitution(restitution), friction(friction), gravityScale(gravityScale), isGravityAffected(true), isKinematic(false) {};

std::size_t size() const {
return sizeof(*this);
}
};

PACKED_END
} // namespace Flakkari::Engine::ECS::Components::_2D

#endif /* !RIGIDBODY_HPP_ */
43 changes: 43 additions & 0 deletions Flakkari/Engine/EntityComponentSystem/Components/Common/Health.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2023-01-14
** File description:
** Health
*/

#ifndef Health_HPP_
#define Health_HPP_

#include <cstddef>

#include "Network/Packed.hpp"

namespace Flakkari::Engine::ECS::Components::Common {
PACKED_START

/**
* @brief Health is a structure that represents the life of an "living object"
*
*/
struct Health {
unsigned int currentHealth;
unsigned int maxHealth = 100;
unsigned int shield = 0;
unsigned int maxShield = 100;

Health() : currentHealth(100), maxHealth(100), shield(0), maxShield(100) {};
Health(unsigned int currentHealth, unsigned int maxHealth, unsigned int shield, unsigned int maxShield) :
currentHealth(currentHealth), maxHealth(maxHealth), shield(shield), maxShield(maxShield) {};
Health(const Health &other) : currentHealth(other.currentHealth), maxHealth(other.maxHealth), shield(other.shield), maxShield(other.maxShield) {};

unsigned int size() const {
return sizeof(*this);
}
};

PACKED_END
} // namespace Flakkari::Engine::ECS::Components::Common

#endif /* !Health_HPP_ */
51 changes: 51 additions & 0 deletions Flakkari/Engine/EntityComponentSystem/Components/Common/Level.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2023-01-14
** File description:
** Level
*/

#ifndef LEVEL_HPP
#define LEVEL_HPP

#include <string>
#include <cstring>

#include "Network/Packed.hpp"

namespace Flakkari::Engine::ECS::Components::Common {
PACKED_START

/**
* @brief FontInfo is a structure that holds information about a Font
*
*/
struct Level {
unsigned int level;
const char *currentWeapon;
unsigned int currentExp;
unsigned int requiredExp;

Level() : level(1), currentWeapon(""), currentExp(0), requiredExp(100) {}
Level(unsigned int level, std::string currentWeapon, unsigned int currentExp, unsigned int requiredExp)
: level(level),
currentWeapon(currentWeapon.c_str()),
currentExp(currentExp),
requiredExp(requiredExp) {}
Level(const Level &other)
: level(other.level),
currentWeapon(other.currentWeapon),
currentExp(other.currentExp),
requiredExp(other.requiredExp) {}

std::size_t size() const {
return sizeof(level) + std::strlen(currentWeapon) + sizeof(currentExp) + sizeof(requiredExp);
}
};

PACKED_END
} // namespace Flakkari::Engine::ECS::Components::Common

#endif //LEVEL_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2023-01-14
** File description:
** NetworkEvent
*/

#ifndef NETWORKEVENT_HPP_
#define NETWORKEVENT_HPP_

#include <vector>

namespace Flakkari::Engine::ECS::Components::Common {

struct NetworkEvent {
std::vector<unsigned short> events;

NetworkEvent() = default;
NetworkEvent(const NetworkEvent &other) : events(other.events) {};
NetworkEvent(const std::vector<unsigned short> &events) : events(events) {};

std::size_t size() const {
return events.size() * sizeof(unsigned short);
}
};

} /* namespace Flakkari::Engine::ECS::Components::Common */

#endif /* !NETWORKEVENT_HPP_ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2023-01-14
** File description:
** Spawned
*/

#ifndef SPAWNED_HPP_
#define SPAWNED_HPP_

#include <string>
#include <cstring>

#include "Network/Packed.hpp"

namespace Flakkari::Engine::ECS::Components::Common {
PACKED_START

/**
* @brief Spawned component for ECS entities that have a script attached to them
*
* @details This component is used to store the path to the script that will be executed
*/
struct Spawned {
bool has_spawned;

Spawned() : has_spawned(false) {}
Spawned(bool spawed) : has_spawned(spawed) {}
Spawned(const Spawned &other) : has_spawned(other.has_spawned) {}

std::size_t size() const {
return sizeof(has_spawned);
}
};

PACKED_END
} // namespace Flakkari::Engine::ECS::Components::Common

#endif /* !SPAWNED_HPP_ */
55 changes: 55 additions & 0 deletions Flakkari/Engine/EntityComponentSystem/Components/Common/Weapon.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2023-01-14
** File description:
** Weapon
*/

#ifndef WEAPON_HPP_
#define WEAPON_HPP_

#include <string>
#include <cstring>

#include "Network/Packed.hpp"

namespace Flakkari::Engine::ECS::Components::Common {
PACKED_START

/**
* @brief Weapon is a structure that defines the characteristics of a weapon.
*
* @details
* The Weapon structure is used to define the characteristics of a weapon.
* It is used by the WeaponComponent to handle the firing and reloading logic.
*
* @param
* damage: The amount of damage dealt by the weapon.
* fireRate: The rate of fire, shots per second.
* currentAmmo: Current ammunition in the magazine.
* reloadTime: Time it takes to reload the weapon in seconds.
* timeSinceLastShot: Time elapsed since the last shot was fired.
* isReloading: Is the weapon currently reloading.
* maxAmmo: Maximum ammunition the weapon can hold.
*/
struct Weapon {
unsigned int damage;
float fireRate;
unsigned int level;

Weapon() = default;
Weapon(const Weapon &other) = default;
Weapon(unsigned int dmg, float rate, unsigned int lvl)
: damage(dmg), fireRate(rate), level(lvl){};

unsigned int size() const {
return sizeof(*this);
};
};

PACKED_END
} // namespace Flakkari::Engine::ECS::Components::Common

#endif /* !WEAPON_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Flakkari Library is a C++ Library for Network.
* @file Components2D.hpp
* @brief Components2D header. Contains all 2D components.
* (Collider, Movable, RigidBody, Transform)
* (Collider, Control, Movable, RigidBody, Transform)
*
* Flakkari Library is under MIT License.
* https://opensource.org/licenses/MIT
Expand All @@ -16,9 +16,10 @@
#ifndef FLAKKARI_COMPONENTS2D_HPP_
#define FLAKKARI_COMPONENTS2D_HPP_

// #include "2D/Collider.hpp" // Collider component (shape, position, rotation, scale)
#include "2D/Collider.hpp" // Collider component (size)
#include "2D/Control.hpp" // Control component (up, down, left, right, shoot)
#include "2D/Movable.hpp" // Movable component (velocity, angularVelocity, acceleration, angularAcceleration)
#include "2D/RigidBody.hpp" // RigidBody component (mass, inertia, restitution, friction)
#include "2D/Transform.hpp" // Transform component (position, rotation, scale)

#endif /* !FLAKKARI_COMPONENTS2D_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* Flakkari Library is a C++ Library for Network.
* @file ComponentsCommon.hpp
* @brief ComponentsCommon header. Contains all common components.
* (Parent, Tag)
* (Parent, Tag, Id, Template, Child, Evolve, Health, Level,
* Script, Spawned, Weapon)
*
* Flakkari Library is under MIT License.
* https://opensource.org/licenses/MIT
Expand All @@ -18,9 +19,15 @@

#include "Common/Child.hpp" // Child component (name)
#include "Common/Evolve.hpp" // Evolve component (name)
#include "Common/Health.hpp" // Health component (health)
#include "Common/Id.hpp" // Id component (id)
#include "Common/Level.hpp" // Level component (level)
#include "Common/Parent.hpp" // Parent component (entity)
#include "Common/Spawned.hpp" // Spawned component (spawned)
#include "Common/Tag.hpp" // Tag component (tag)
#include "Common/Template.hpp" // Template component (name)
#include "Common/Weapon.hpp" // Weapon component (name)

#include "Common/NetworkEvent.hpp" // NetworkEvent component (event)

#endif /* !FLAKKARI_COMPONENTSCOMMON_HPP_ */
Loading

0 comments on commit d045fe3

Please sign in to comment.