28 , _entitySystem(entitySystem)
29 , _roomSystem(roomSystem)
30 , _networkSync(networkSync)
43 log::warning(
"No level path registered for level {}", levelId);
50 log::error(
"Failed to load level {}: {}", levelId, error);
65 active.
data = std::move(level.value());
67 log::info(
"Loaded level {} for room {}", levelId, roomId);
77 constexpr float scrollSpeed = 120.0f;
87 auto getFrontPlayerX = [&]() ->
float {
94 for (
auto &&[tf, type, room] : view) {
98 if (tf.position.x > maxX) {
105 while (active.nextSpawn < active.data.spawns.size() &&
106 active.data.spawns[active.nextSpawn].atTime <= active.elapsed) {
107 const auto& spawn = active.data.spawns[active.nextSpawn];
108 Vec2f startPos = spawn.startPosition;
109 const int patternIndex =
static_cast<int>(active.nextSpawn % 5);
110 const float xOffsets[5] = {0.0f, 100.0f, -40.0f, 80.0f, -80.0f};
111 startPos.
x += xOffsets[patternIndex];
112 const float frontX = getFrontPlayerX();
116 if (startPos.
x < frontX + minAhead) {
117 startPos.
x = frontX + minAhead;
120 roomId, startPos, spawn.pattern,
121 spawn.speed, spawn.amplitude, spawn.frequency, spawn.type);
126 const float shieldRadius = 250.0f;
128 const float angles[4] = {120.0f, 150.0f, 210.0f, 240.0f};
130 for (
int i = 0; i < 4; i++) {
131 float angleRad = angles[i] * 3.14159f / 180.0f;
133 startPos.
x + shieldRadius * std::cos(angleRad),
134 startPos.
y + shieldRadius * std::sin(angleRad)
138 roomId, shieldPos, spawn.pattern,
139 spawn.speed, spawn.amplitude, spawn.frequency,
148 while (active.nextPowerup < active.data.powerups.size() &&
149 active.data.powerups[active.nextPowerup].atTime <= active.elapsed) {
150 const auto& powerup = active.data.powerups[active.nextPowerup];
152 roomId, powerup.position, powerup.type, powerup.value, powerup.duration);
157 active.nextPowerup++;
160 while (active.nextObstacle < active.data.obstacles.size() &&
161 active.data.obstacles[active.nextObstacle].atTime <= active.elapsed) {
162 const auto& obstacle = active.data.obstacles[active.nextObstacle];
164 roomId, obstacle.position, obstacle.size, obstacle.health, obstacle.type);
169 active.nextObstacle++;
185 const auto players = room->getPlayers();
186 if (players.empty()) {
190 std::vector<uint32_t> sessions;
191 sessions.reserve(players.size());
192 for (
const auto& player : players) {
193 sessions.push_back(player->getId());
200 if (!transformRes || !typeRes || !netRes) {
201 log::error(
"Missing component array for level spawn");
205 auto &transforms = transformRes->get();
206 auto &types = typeRes->get();
207 auto &nets = netRes->get();
208 auto *boxes = boxRes ? &boxRes->get() :
nullptr;
209 if (!transforms.has(entity) || !types.has(entity) || !nets.has(entity)) {
210 log::error(
"Level spawned entity {} missing Transform/EntityType/NetworkId", entity.
index());
214 const auto &transform = transforms[entity];
215 const auto &type = types[entity];
216 const auto &
net = nets[entity];
219 if (boxes && boxes->has(entity)) {
220 const auto &box = (*boxes)[entity];
228 static_cast<uint8_t
>(type.type),
229 transform.position.x,
230 transform.position.y,
244 return &it->second.data;
Logger declaration with support for multiple log levels.
Represents an entity in the ECS (Entity-Component-System) architecture.
constexpr std::uint32_t index(void) const
auto add(Entity entity, Args &&...args) -> std::expected< std::reference_wrapper< T >, rtp::Error >
auto get(this const Self &self) -> std::expected< std::reference_wrapper< ConstLike< Self, SparseArray< T > > >, rtp::Error >
auto zipView(this Self &self)
Network packet with header and serializable body.
Base class for systems that operate on entities in the ECS.
ecs::Entity createObstacleEntity(uint32_t roomId, const Vec2f &pos, const Vec2f &size, int health, net::EntityType type=net::EntityType::Obstacle)
Create a new obstacle entity in the ECS.
ecs::Entity createEnemyEntity(uint32_t roomId, const Vec2f &pos, ecs::components::Patterns pattern, float speed, float amplitude, float frequency, net::EntityType type=net::EntityType::Scout)
Create a new enemy entity in the ECS.
ecs::Entity createPowerupEntity(uint32_t roomId, const Vec2f &pos, ecs::components::PowerupType type, float value, float duration)
Create a new powerup entity in the ECS.
void stopLevelForRoom(uint32_t roomId)
Stop the level for a specific room.
const LevelData * getLevelData(uint32_t roomId) const
Get the level data for a specific room.
LevelSystem(ecs::Registry ®istry, EntitySystem &entitySystem, RoomSystem &roomSystem, NetworkSyncSystem &networkSync)
Constructor for LevelSystem.
void spawnEntityForRoom(uint32_t roomId, const ecs::Entity &entity)
Spawn an entity for a specific room.
RoomSystem & _roomSystem
Reference to the RoomSystem.
std::unordered_map< uint32_t, std::string > _levelPaths
Level file paths mapped by level ID.
void startLevelForRoom(uint32_t roomId, uint32_t levelId)
Start a level for a specific room.
std::optional< LevelData > loadLevel(uint32_t levelId) const
Load level data from a file.
NetworkSyncSystem & _networkSync
Reference to the NetworkSyncSystem.
ecs::Registry & _registry
Reference to the entity registry.
void registerLevelPath(uint32_t levelId, const std::string &path)
Register a level file path with a level ID.
EntitySystem & _entitySystem
Reference to the EntitySystem.
void update(float dt)
Update system logic for one frame.
std::unordered_map< uint32_t, ActiveLevel > _activeLevels
Active levels mapped by room ID.
System to handle network-related operations on the server side.
void sendPacketToSessions(const std::vector< uint32_t > &sessions, const net::Packet &packet, net::NetworkMode mode)
Send a packet to multiple sessions.
System to handle room-related operations on the server side.
std::shared_ptr< Room > getRoom(uint32_t roomId)
Get a room by its ID.
@ InGame
Game in progress.
File : Network.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue.hajjar-llauquen@epit...
void error(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an error message.
void warning(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log a warning message.
void info(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an informational message.
@ EntitySpawn
Entity spawn notification.
File : GameManager.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
std::optional< LevelData > loadLevelFromFile(const std::string &path, std::string &error)
Component representing a network identifier for an entity.
Component representing a network identifier for an entity.
Component representing a 2D velocity.
Entity spawn notification data.
Struct to hold active level data for a room.