Files
orni-attack/source/game/entities/enemy_registry.cpp
T
JailDesigner bc41169176 feat(enemy): afegir tipus STAR (estrella de 5 puntes) i 3 nous shapes
- Nou enemic STAR amb shape star_5.shp, escala 0.7 i color groc pur.
  Reusa el comportament zigzag del Pentagon i carrega via EnemyRegistry.
- DistribucioEnemics estesa amb camp 'star' opcional (default 0) per
  mantenir compat amb stages antics.
- Stage 1 reconfigurat a 25/25/25/25 per mostrar els 4 tipus.
- Afegits també shapes bullet_long.shp i bullet_double.shp (encara no
  utilitzats; preparats per futures variants de bala).
2026-05-25 12:36:26 +02:00

67 lines
2.0 KiB
C++

// enemy_registry.cpp - Implementació del registre estàtic d'enemics
// © 2026 JailDesigner
#include "game/entities/enemy_registry.hpp"
#include <cstdlib>
#include <iostream>
#include <string>
#include "core/entities/entity_loader.hpp"
EnemyConfig EnemyRegistry::pentagon_config;
EnemyConfig EnemyRegistry::square_config;
EnemyConfig EnemyRegistry::pinwheel_config;
EnemyConfig EnemyRegistry::star_config;
bool EnemyRegistry::loaded = false;
namespace {
auto loadOne(const std::string& name, EnemyType expected_type, EnemyConfig& out) -> bool {
auto yaml = Entities::EntityLoader::load(name);
if (!yaml) {
std::cerr << "[EnemyRegistry] Error: no s'ha pogut carregar " << name << ".yaml\n";
return false;
}
auto cfg = EnemyConfig::fromYaml(*yaml, expected_type);
if (!cfg) {
std::cerr << "[EnemyRegistry] Error: format invàlid a " << name << ".yaml\n";
return false;
}
out = *cfg;
return true;
}
} // namespace
auto EnemyRegistry::loadAll() -> bool {
const bool OK = loadOne("pentagon", EnemyType::PENTAGON, pentagon_config) &&
loadOne("square", EnemyType::SQUARE, square_config) &&
loadOne("pinwheel", EnemyType::PINWHEEL, pinwheel_config) &&
loadOne("star", EnemyType::STAR, star_config);
loaded = OK;
if (OK) {
std::cout << "[EnemyRegistry] 4 configuracions d'enemic carregades.\n";
}
return OK;
}
auto EnemyRegistry::get(EnemyType type) -> const EnemyConfig& {
if (!loaded) {
std::cerr << "[EnemyRegistry] FATAL: get() abans de loadAll()\n";
std::exit(EXIT_FAILURE);
}
switch (type) {
case EnemyType::PENTAGON:
return pentagon_config;
case EnemyType::SQUARE:
return square_config;
case EnemyType::PINWHEEL:
return pinwheel_config;
case EnemyType::STAR:
return star_config;
}
std::cerr << "[EnemyRegistry] FATAL: tipus desconegut\n";
std::exit(EXIT_FAILURE);
}