4#include "Components.hpp"
10 std::cout <<
"Collision Player Missile" << std::endl;
14 healths[entity1]->current -= 1;
17 if (healths[entity1]->current == 0) {
29 std::cout <<
"Collision Monster Missile" << std::endl;
32 healths[entity1]->current -= 1;
35 if (healths[entity1]->current == 0) {
51 std::cout <<
"Collision Player Obstacle" << std::endl;
64 std::cout <<
"Collision Player Powerup" << std::endl;
67 healths[entity1]->current = healths[entity1]->max;
72 powerups[entity1]->
enabled =
true;
79 std::cout <<
"Collision Obstacle Missile" << std::endl;
86 struct hash<
std::pair<type_enum, type_enum>> {
87 std::size_t
operator()(
const std::pair<type_enum, type_enum>& p)
const {
88 return (hash<type_enum>()(p.first) ^ (hash<type_enum>()(p.second) << 1));
93const std::unordered_map<std::pair<type_enum, type_enum>, std::function<void(
Registry &, std::size_t &, std::size_t &)>>
collisions = {
104 for (
auto &&[idx1, pos1, col1, type1] :
IndexedZipper(positions, colliders, types)) {
105 if (!pos1 || !col1 || !type1)
continue;
107 for (
auto &&[idx2, pos2, col2, type2] :
IndexedZipper(positions, colliders, types)) {
108 if (!pos2 || !col2 || !type2 || idx1 == idx2)
continue;
110 auto key = std::make_pair(type1->type, type2->type);
112 float dx = (pos1->X - pos2->X);
113 float dy = (pos1->Y - pos2->Y);
114 float distance_squared = dx * dx + dy * dy;
115 float radius_sum = col1->radius + col2->radius;
116 if (distance_squared <= radius_sum * radius_sum)
void collision_system(Registry &r, ComponentContainer< Position > &positions, ComponentContainer< Collider > &colliders, ComponentContainer< Type > &types)
Collision detection and resolution system.
void collision_monster_obstacle(Registry &r, std::size_t &entity1, std::size_t &entity2)
const std::unordered_map< std::pair< type_enum, type_enum >, std::function< void(Registry &, std::size_t &, std::size_t &)> > collisions
void collision_obstacle_missile(Registry &r, std::size_t &entity1, std::size_t &entity2)
void collision_player_powerup(Registry &r, std::size_t &entity1, std::size_t &entity2)
void collision_player_missile(Registry &r, std::size_t &entity1, std::size_t &entity2)
void collision_monster_missile(Registry &r, std::size_t &entity1, std::size_t &entity2)
void collision_player_obstacle(Registry &r, std::size_t &entity1, std::size_t &entity2)
@ P_BUFF
Represents a buff event.
@ P_HEAL
Represents a healing event.
@ P_DAMAGE
Represents a damage event.
@ P_KILL
Represents a kill event.
Manages a collection of components associated with entities in an ECS (Entity-Component-System) archi...
Represents an entity in an Entity-Component-System (ECS) architecture.
void notify(const GameMessage &event)
Notifies the subscribed listener of an event.
Combines multiple containers into a single iterable unit, iterating over corresponding elements from ...
Manages entities and their associated components, enabling the creation, deletion,...
void kill_entity(const Entity &entity)
Deletes an entity and removes all its components.
EventDispatcher * dispatcher
std::tuple< ComponentContainer< Components > &... > get_component_array()
Retrieves component containers for multiple component types.
ComponentContainer< Component > & get_components()
Retrieves the component container for a specific type.
Represents the health of an entity, including current and maximum health values.
Represents a loot drop with a specific loot type.
Represents the position of an entity in a 2D space.
Represents a power-up item and its enabled state.
Represents the team affiliation of an entity.
std::size_t operator()(const std::pair< type_enum, type_enum > &p) const