fix: tidy namespace Scenes::/Info:: PascalCase i locals UPPER_CASE
This commit is contained in:
@@ -334,5 +334,5 @@ auto Jd8::fadeTickStep() -> bool {
|
||||
// eliminats a Phase B.2: feien un bucle de 32 iteracions amb `Jd8::flip`
|
||||
// entre cada una que només funcionava mentre l'entorn tenia fibers i
|
||||
// `Jd8::flip` cedia el control al Director. Ara tot fade es fa tick a
|
||||
// tick via `scenes::PaletteFade` (que encapsula `Jd8::fadeStartOut` /
|
||||
// tick via `Scenes::PaletteFade` (que encapsula `Jd8::fadeStartOut` /
|
||||
// `Jd8::fadeStartToPal` + `Jd8::fadeTickStep`).
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Jd8 {
|
||||
// (32 passos en total). El caller és responsable de fer el Flip entre
|
||||
// passos si el vol veure animat. `fadeIsActive` permet saber si hi ha
|
||||
// un fade en curs per a enllaçar-lo amb un altre subsistema.
|
||||
// L'embolcall `scenes::PaletteFade` ho fa més idiomàtic per a escenes.
|
||||
// L'embolcall `Scenes::PaletteFade` ho fa més idiomàtic per a escenes.
|
||||
void fadeStartOut();
|
||||
void fadeStartToPal(const Color* pal);
|
||||
auto fadeTickStep() -> bool;
|
||||
|
||||
@@ -33,9 +33,9 @@ void Jg::setUpdateTicks(Uint32 milliseconds) {
|
||||
}
|
||||
|
||||
auto Jg::shouldUpdate() -> bool {
|
||||
const Uint32 now = SDL_GetTicks();
|
||||
if (now - update_time > update_ticks) {
|
||||
update_time = now;
|
||||
const Uint32 NOW = SDL_GetTicks();
|
||||
if (NOW - update_time > update_ticks) {
|
||||
update_time = NOW;
|
||||
cycle_counter++;
|
||||
return true;
|
||||
}
|
||||
@@ -50,8 +50,8 @@ auto Jg::getCycleCounter() -> Uint32 {
|
||||
}
|
||||
|
||||
auto Jg::getDeltaMs() -> Uint32 {
|
||||
const Uint32 now = SDL_GetTicks();
|
||||
const Uint32 delta = now - last_delta_time;
|
||||
last_delta_time = now;
|
||||
return delta;
|
||||
const Uint32 NOW = SDL_GetTicks();
|
||||
const Uint32 DELTA = NOW - last_delta_time;
|
||||
last_delta_time = NOW;
|
||||
return DELTA;
|
||||
}
|
||||
|
||||
@@ -231,28 +231,28 @@ void Screen::present(Uint32* pixel_data) {
|
||||
// no trencar la selecció de l'usuari.
|
||||
Rendering::PostFXParams clean{};
|
||||
shader_backend_->setPostFXParams(clean);
|
||||
const auto prev_shader = shader_backend_->getActiveShader();
|
||||
if (prev_shader != Rendering::ShaderType::POSTFX) {
|
||||
const auto PREV_SHADER = shader_backend_->getActiveShader();
|
||||
if (PREV_SHADER != Rendering::ShaderType::POSTFX) {
|
||||
shader_backend_->setActiveShader(Rendering::ShaderType::POSTFX);
|
||||
}
|
||||
shader_backend_->uploadPixels(pixel_data, GAME_WIDTH, GAME_HEIGHT);
|
||||
shader_backend_->render();
|
||||
if (prev_shader != Rendering::ShaderType::POSTFX) {
|
||||
shader_backend_->setActiveShader(prev_shader);
|
||||
if (PREV_SHADER != Rendering::ShaderType::POSTFX) {
|
||||
shader_backend_->setActiveShader(PREV_SHADER);
|
||||
}
|
||||
} else {
|
||||
// Fallback SDL_Renderer. A mult=1, flux directe original: logical
|
||||
// Fallback SDL_Renderer. A MULT=1, flux directe original: logical
|
||||
// presentation (setada per applyFallbackPresentation) + scale mode de
|
||||
// texture_ segons l'opció. A mult>1, la còpia intermèdia crea la
|
||||
// texture_ segons l'opció. A MULT>1, la còpia intermèdia crea la
|
||||
// font ampliada (NN via GPU), i es presenta via logical presentation
|
||||
// a la mida de la font intermèdia.
|
||||
SDL_UpdateTexture(texture_, nullptr, pixel_data, GAME_WIDTH * sizeof(Uint32));
|
||||
|
||||
const int mult = Options::video.internal_resolution;
|
||||
if (mult > 1) {
|
||||
const int MULT = Options::video.internal_resolution;
|
||||
if (MULT > 1) {
|
||||
ensureFallbackInternalTexture();
|
||||
if (internal_texture_sdl_ != nullptr) {
|
||||
// Còpia NN a la textura intermèdia (mult·game). Sampler NN
|
||||
// Còpia NN a la textura intermèdia (MULT·game). Sampler NN
|
||||
// per construcció: volem píxels grans i nets.
|
||||
SDL_SetTextureScaleMode(texture_, SDL_SCALEMODE_NEAREST);
|
||||
SDL_SetRenderTarget(renderer_, internal_texture_sdl_);
|
||||
@@ -261,7 +261,7 @@ void Screen::present(Uint32* pixel_data) {
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
|
||||
// Filtre global al pas final → finestra (via logical presentation
|
||||
// que applyFallbackPresentation ja configura amb mida game·mult).
|
||||
// que applyFallbackPresentation ja configura amb mida game·MULT).
|
||||
SDL_ScaleMode final_scale = (Options::video.texture_filter == Options::TextureFilter::LINEAR)
|
||||
? SDL_SCALEMODE_LINEAR
|
||||
: SDL_SCALEMODE_NEAREST;
|
||||
@@ -273,9 +273,9 @@ void Screen::present(Uint32* pixel_data) {
|
||||
}
|
||||
// Si la creació de la textura intermèdia ha fallat, caiem al path normal.
|
||||
}
|
||||
// mult=1 (o fallback-del-fallback): texture_ directament. El scale mode
|
||||
// MULT=1 (o fallback-del-fallback): texture_ directament. El scale mode
|
||||
// el manté applyFallbackPresentation — però el re-apliquem per si la
|
||||
// ruta mult>1 el va sobreescriure anteriorment.
|
||||
// ruta MULT>1 el va sobreescriure anteriorment.
|
||||
SDL_ScaleMode direct_scale = (Options::video.texture_filter == Options::TextureFilter::LINEAR)
|
||||
? SDL_SCALEMODE_LINEAR
|
||||
: SDL_SCALEMODE_NEAREST;
|
||||
@@ -632,16 +632,16 @@ void Screen::applyFallbackPresentation() {
|
||||
}
|
||||
// Amb resolució interna N > 1, la mida lògica creix proporcionalment
|
||||
// perquè SDL scale des de 320·N × 200·N a la finestra — menys aggressive linear.
|
||||
const int mult = Options::video.internal_resolution < 1 ? 1 : Options::video.internal_resolution;
|
||||
SDL_SetRenderLogicalPresentation(renderer_, GAME_WIDTH * mult, GAME_HEIGHT * mult, mode);
|
||||
const int MULT = Options::video.internal_resolution < 1 ? 1 : Options::video.internal_resolution;
|
||||
SDL_SetRenderLogicalPresentation(renderer_, GAME_WIDTH * MULT, GAME_HEIGHT * MULT, mode);
|
||||
}
|
||||
|
||||
void Screen::ensureFallbackInternalTexture() {
|
||||
if (renderer_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
const int mult = Options::video.internal_resolution;
|
||||
if (mult <= 1) {
|
||||
const int MULT = Options::video.internal_resolution;
|
||||
if (MULT <= 1) {
|
||||
// No cal textura intermèdia — recicla si la teníem.
|
||||
if (internal_texture_sdl_ != nullptr) {
|
||||
SDL_DestroyTexture(internal_texture_sdl_);
|
||||
@@ -650,7 +650,7 @@ void Screen::ensureFallbackInternalTexture() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (internal_texture_sdl_ != nullptr && internal_texture_mult_ == mult) {
|
||||
if (internal_texture_sdl_ != nullptr && internal_texture_mult_ == MULT) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -661,15 +661,15 @@ void Screen::ensureFallbackInternalTexture() {
|
||||
internal_texture_sdl_ = SDL_CreateTexture(renderer_,
|
||||
SDL_PIXELFORMAT_ABGR8888,
|
||||
SDL_TEXTUREACCESS_TARGET,
|
||||
GAME_WIDTH * mult,
|
||||
GAME_HEIGHT * mult);
|
||||
GAME_WIDTH * MULT,
|
||||
GAME_HEIGHT * MULT);
|
||||
if (internal_texture_sdl_ == nullptr) {
|
||||
std::cerr << "Screen: failed to create fallback internal texture (×" << mult << "): "
|
||||
std::cerr << "Screen: failed to create fallback internal texture (×" << MULT << "): "
|
||||
<< SDL_GetError() << '\n';
|
||||
internal_texture_mult_ = 0;
|
||||
return;
|
||||
}
|
||||
internal_texture_mult_ = mult;
|
||||
internal_texture_mult_ = MULT;
|
||||
}
|
||||
|
||||
void Screen::adjustWindowSize() {
|
||||
|
||||
@@ -906,8 +906,8 @@ namespace Rendering {
|
||||
|
||||
// ---- Calcular viewport (dimensions lògiques del canvas) ----
|
||||
// Si 4:3 actiu, effective_height ja és 240 (la textura estirada)
|
||||
const auto logical_w = static_cast<float>(game_width_);
|
||||
const auto logical_h = static_cast<float>(effective_height);
|
||||
const auto LOGICAL_W = static_cast<float>(game_width_);
|
||||
const auto LOGICAL_H = static_cast<float>(effective_height);
|
||||
|
||||
float vx = 0.0F;
|
||||
float vy = 0.0F;
|
||||
@@ -916,8 +916,8 @@ namespace Rendering {
|
||||
switch (scaling_mode_) {
|
||||
case Options::ScalingMode::DISABLED:
|
||||
// 1:1, sense escala (pot ser diminut en finestres grans)
|
||||
vw = logical_w;
|
||||
vh = logical_h;
|
||||
vw = LOGICAL_W;
|
||||
vh = LOGICAL_H;
|
||||
break;
|
||||
case Options::ScalingMode::STRETCH:
|
||||
// Omple tota la finestra, escala no uniforme
|
||||
@@ -925,23 +925,23 @@ namespace Rendering {
|
||||
vh = static_cast<float>(sh);
|
||||
break;
|
||||
case Options::ScalingMode::LETTERBOX: {
|
||||
const float SCALE = std::min(static_cast<float>(sw) / logical_w,
|
||||
static_cast<float>(sh) / logical_h);
|
||||
vw = logical_w * SCALE;
|
||||
vh = logical_h * SCALE;
|
||||
const float SCALE = std::min(static_cast<float>(sw) / LOGICAL_W,
|
||||
static_cast<float>(sh) / LOGICAL_H);
|
||||
vw = LOGICAL_W * SCALE;
|
||||
vh = LOGICAL_H * SCALE;
|
||||
break;
|
||||
}
|
||||
case Options::ScalingMode::OVERSCAN: {
|
||||
const float SCALE = std::max(static_cast<float>(sw) / logical_w,
|
||||
static_cast<float>(sh) / logical_h);
|
||||
vw = logical_w * SCALE;
|
||||
vh = logical_h * SCALE;
|
||||
const float SCALE = std::max(static_cast<float>(sw) / LOGICAL_W,
|
||||
static_cast<float>(sh) / LOGICAL_H);
|
||||
vw = LOGICAL_W * SCALE;
|
||||
vh = LOGICAL_H * SCALE;
|
||||
break;
|
||||
}
|
||||
case Options::ScalingMode::INTEGER: {
|
||||
const int SCALE = std::max(1, std::min(static_cast<int>(sw) / static_cast<int>(logical_w), static_cast<int>(sh) / static_cast<int>(logical_h)));
|
||||
vw = logical_w * static_cast<float>(SCALE);
|
||||
vh = logical_h * static_cast<float>(SCALE);
|
||||
const int SCALE = std::max(1, std::min(static_cast<int>(sw) / static_cast<int>(LOGICAL_W), static_cast<int>(sh) / static_cast<int>(LOGICAL_H)));
|
||||
vw = LOGICAL_W * static_cast<float>(SCALE);
|
||||
vh = LOGICAL_H * static_cast<float>(SCALE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ namespace Resource {
|
||||
return true;
|
||||
}
|
||||
|
||||
const Uint64 start_ns = SDL_GetTicksNS();
|
||||
const Uint64 budget_ns = static_cast<Uint64>(budget_ms) * 1'000'000ULL;
|
||||
const Uint64 START_NS = SDL_GetTicksNS();
|
||||
const Uint64 BUDGET_NS = static_cast<Uint64>(budget_ms) * 1'000'000ULL;
|
||||
const auto* list = List::get();
|
||||
|
||||
while (stage_ != LoadStage::DONE) {
|
||||
@@ -173,7 +173,7 @@ namespace Resource {
|
||||
case LoadStage::DONE:
|
||||
break;
|
||||
}
|
||||
if ((SDL_GetTicksNS() - start_ns) >= budget_ns) {
|
||||
if ((SDL_GetTicksNS() - START_NS) >= BUDGET_NS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace ResourceHelper {
|
||||
bool fallback_enabled_ = true;
|
||||
|
||||
auto readFromDisk(const std::string& relative_path) -> std::vector<uint8_t> {
|
||||
const std::string full = std::string(Jf::getResourceFolder()) + relative_path;
|
||||
std::ifstream file(full, std::ios::binary | std::ios::ate);
|
||||
const std::string FULL = std::string(Jf::getResourceFolder()) + relative_path;
|
||||
std::ifstream file(FULL, std::ios::binary | std::ios::ate);
|
||||
if (!file) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -37,42 +37,42 @@ std::unique_ptr<Director> Director::instance_;
|
||||
Director::~Director() = default;
|
||||
|
||||
void Director::initGameContext() {
|
||||
info::ctx.num_habitacio = Options::game.habitacio_inicial;
|
||||
info::ctx.num_piramide = Options::game.piramide_inicial;
|
||||
info::ctx.diners = Options::game.diners_inicial;
|
||||
info::ctx.diamants = Options::game.diamants_inicial;
|
||||
info::ctx.vida = Options::game.vides;
|
||||
info::ctx.momies = 0;
|
||||
info::ctx.nou_personatge = false;
|
||||
info::ctx.pepe_activat = false;
|
||||
Info::ctx.num_habitacio = Options::game.habitacio_inicial;
|
||||
Info::ctx.num_piramide = Options::game.piramide_inicial;
|
||||
Info::ctx.diners = Options::game.diners_inicial;
|
||||
Info::ctx.diamants = Options::game.diamants_inicial;
|
||||
Info::ctx.vida = Options::game.vides;
|
||||
Info::ctx.momies = 0;
|
||||
Info::ctx.nou_personatge = false;
|
||||
Info::ctx.pepe_activat = false;
|
||||
|
||||
FILE* ini = fopen("trick.ini", "rb");
|
||||
if (ini != nullptr) {
|
||||
info::ctx.nou_personatge = true;
|
||||
Info::ctx.nou_personatge = true;
|
||||
fclose(ini);
|
||||
}
|
||||
}
|
||||
|
||||
auto Director::createNextScene() const -> std::unique_ptr<scenes::Scene> {
|
||||
auto Director::createNextScene() const -> std::unique_ptr<Scenes::Scene> {
|
||||
// Mentre el Resource::Cache no haja acabat de precarregar, executem
|
||||
// el BootLoaderScene — pinta una barra de progrés i avança la
|
||||
// càrrega per pressupost de temps. Quan acaba, retorna i tornem ací
|
||||
// amb el cache plenament disponible per a la resta d'escenes.
|
||||
if (Resource::Cache::get() != nullptr && !Resource::Cache::get()->isLoadDone()) {
|
||||
return std::make_unique<scenes::BootLoaderScene>();
|
||||
return std::make_unique<Scenes::BootLoaderScene>();
|
||||
}
|
||||
if (game_state_ == 0) {
|
||||
// Gameplay. ModuleGame és una scenes::Scene des de la Phase A.
|
||||
// Gameplay. ModuleGame és una Scenes::Scene des de la Phase A.
|
||||
return std::make_unique<ModuleGame>();
|
||||
}
|
||||
// game_state_ == 1: dispatch al registry per num_piramide. Replica
|
||||
// del redirect que el vell ModuleSequence::Go() feia: si el jugador
|
||||
// arriba a la Secreta (6) sense prou diners, salta als slides de
|
||||
// fracàs (7) abans de buscar l'escena al registry.
|
||||
if (info::ctx.num_piramide == 6 && info::ctx.diners < 200) {
|
||||
info::ctx.num_piramide = 7;
|
||||
if (Info::ctx.num_piramide == 6 && Info::ctx.diners < 200) {
|
||||
Info::ctx.num_piramide = 7;
|
||||
}
|
||||
return scenes::SceneRegistry::instance().tryCreate(info::ctx.num_piramide);
|
||||
return Scenes::SceneRegistry::instance().tryCreate(Info::ctx.num_piramide);
|
||||
}
|
||||
|
||||
void Director::init() {
|
||||
@@ -80,34 +80,34 @@ void Director::init() {
|
||||
Gamepad::init();
|
||||
|
||||
// Registre d'escenes. Cada entrada = un state_key (`num_piramide`)
|
||||
// amb una factory de `scenes::Scene`. iterate() consulta aquest
|
||||
// amb una factory de `Scenes::Scene`. iterate() consulta aquest
|
||||
// registry per a tots els states de seqüència (game_state_ == 1); si
|
||||
// una clau no apareix ací, Director surt ordenadament.
|
||||
auto& registry = scenes::SceneRegistry::instance();
|
||||
registry.registerScene(0, [] { return std::make_unique<scenes::MenuScene>(); });
|
||||
registry.registerScene(100, [] { return std::make_unique<scenes::MortScene>(); });
|
||||
auto& registry = Scenes::SceneRegistry::instance();
|
||||
registry.registerScene(0, [] { return std::make_unique<Scenes::MenuScene>(); });
|
||||
registry.registerScene(100, [] { return std::make_unique<Scenes::MortScene>(); });
|
||||
// BannerScene cobreix les piràmides 2..5 (el vell doBanner decideix
|
||||
// pel switch intern llegint info::ctx.num_piramide).
|
||||
// pel switch intern llegint Info::ctx.num_piramide).
|
||||
for (int p = 2; p <= 5; ++p) {
|
||||
registry.registerScene(p, [] { return std::make_unique<scenes::BannerScene>(); });
|
||||
registry.registerScene(p, [] { return std::make_unique<Scenes::BannerScene>(); });
|
||||
}
|
||||
// SlidesScene cobreix els dos states on el vell `doSlides` s'invocava:
|
||||
// - num_piramide == 1: slides narratius inicials (entrada al joc)
|
||||
// - num_piramide == 7: slides de fracàs (ve del redirect 6→7 quan
|
||||
// l'usuari no té prou diners per a la Secreta)
|
||||
registry.registerScene(1, [] { return std::make_unique<scenes::SlidesScene>(); });
|
||||
registry.registerScene(7, [] { return std::make_unique<scenes::SlidesScene>(); });
|
||||
registry.registerScene(6, [] { return std::make_unique<scenes::SecretaScene>(); });
|
||||
registry.registerScene(8, [] { return std::make_unique<scenes::CreditsScene>(); });
|
||||
registry.registerScene(1, [] { return std::make_unique<Scenes::SlidesScene>(); });
|
||||
registry.registerScene(7, [] { return std::make_unique<Scenes::SlidesScene>(); });
|
||||
registry.registerScene(6, [] { return std::make_unique<Scenes::SecretaScene>(); });
|
||||
registry.registerScene(8, [] { return std::make_unique<Scenes::CreditsScene>(); });
|
||||
// State 255 (intro): dues variants segons `Options::game.use_new_logo`.
|
||||
// La factory tria a runtime — així es pot togglar des del menú sense
|
||||
// re-registrar. Les dues escenes construeixen una IntroSpritesScene
|
||||
// com a sub-escena per a la part d'animacions de sprites.
|
||||
registry.registerScene(255, []() -> std::unique_ptr<scenes::Scene> {
|
||||
registry.registerScene(255, []() -> std::unique_ptr<Scenes::Scene> {
|
||||
if (Options::game.use_new_logo) {
|
||||
return std::make_unique<scenes::IntroNewLogoScene>();
|
||||
return std::make_unique<Scenes::IntroNewLogoScene>();
|
||||
}
|
||||
return std::make_unique<scenes::IntroScene>();
|
||||
return std::make_unique<Scenes::IntroScene>();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -149,12 +149,12 @@ auto Director::iterate() -> bool {
|
||||
restart_requested_ = false;
|
||||
Audio::get()->stopMusic();
|
||||
Audio::get()->stopAllSounds();
|
||||
// Reinicialitza info::ctx des d'Options (vides, diners, diamants...)
|
||||
// Reinicialitza Info::ctx des d'Options (vides, diners, diamants...)
|
||||
// en lloc de ctx.reset() pla que deixaria vida=0 → jugador mort.
|
||||
initGameContext();
|
||||
// Força l'intro independentment de `piramide_inicial` (que pot estar
|
||||
// configurat a una piràmide intermèdia per a proves ràpides).
|
||||
info::ctx.num_piramide = 255;
|
||||
Info::ctx.num_piramide = 255;
|
||||
current_scene_.reset();
|
||||
game_state_ = 1; // 1 = dispatch via SceneRegistry per num_piramide
|
||||
has_frame_ = false;
|
||||
@@ -183,9 +183,9 @@ auto Director::iterate() -> bool {
|
||||
Audio::update();
|
||||
|
||||
// Dispara els crèdits cinematogràfics la primera vegada que el joc
|
||||
// arriba al menú del títol (info::ctx.num_piramide == 0).
|
||||
// arriba al menú del títol (Info::ctx.num_piramide == 0).
|
||||
static bool credits_triggered_ = false;
|
||||
if (!credits_triggered_ && info::ctx.num_piramide == 0) {
|
||||
if (!credits_triggered_ && Info::ctx.num_piramide == 0) {
|
||||
if (Options::game.show_title_credits) {
|
||||
Overlay::startCredits();
|
||||
}
|
||||
@@ -210,7 +210,7 @@ auto Director::iterate() -> bool {
|
||||
}
|
||||
|
||||
// Si no hi ha escena activa, construeix la pròxima segons
|
||||
// game_state_ i info::ctx. Si és impossible (game_state_ == -1,
|
||||
// game_state_ i Info::ctx. Si és impossible (game_state_ == -1,
|
||||
// quit, o state no registrat), eixim del loop.
|
||||
if (!current_scene_) {
|
||||
if (game_state_ == -1 || Jg::quitting()) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
// El Director és l'únic thread del runtime. Cada iterate() fa input →
|
||||
// tick de l'escena actual → Jd8::flip → overlay → present → sleep al frame
|
||||
// target. Totes les escenes (`scenes::Scene` i `ModuleGame`) són
|
||||
// target. Totes les escenes (`Scenes::Scene` i `ModuleGame`) són
|
||||
// tick-based i no bloquegen — no hi ha fibers, mutex ni condition_variable.
|
||||
// Compatible amb SDL_AppIterate i amb el futur port a emscripten.
|
||||
class Director {
|
||||
@@ -36,7 +36,7 @@ class Director {
|
||||
void requestQuit();
|
||||
[[nodiscard]] auto isQuitRequested() const -> bool { return quit_requested_; }
|
||||
|
||||
// Demana un reinici "suau": para música i sons, reseteja info::ctx i
|
||||
// Demana un reinici "suau": para música i sons, reseteja Info::ctx i
|
||||
// torna a l'intro (state 255). Es processa al començament del pròxim
|
||||
// iterate() per evitar manipular l'escena des d'una lambda del menú.
|
||||
void requestRestart();
|
||||
@@ -61,12 +61,12 @@ class Director {
|
||||
|
||||
void pollAllEvents(); // drenatge amb SDL_PollEvent, només per al bucle natiu
|
||||
|
||||
// Inicialitza info::ctx a partir de Options::game.* i comprova trick.ini.
|
||||
// Inicialitza Info::ctx a partir de Options::game.* i comprova trick.ini.
|
||||
// Es crida una sola vegada des d'iterate() a la primera invocació.
|
||||
static void initGameContext();
|
||||
// Construeix l'escena apropiada segons game_state_ i info::ctx.
|
||||
// Construeix l'escena apropiada segons game_state_ i Info::ctx.
|
||||
// Retorna nullptr si l'state actual no té escena registrada (bug).
|
||||
[[nodiscard]] auto createNextScene() const -> std::unique_ptr<scenes::Scene>;
|
||||
[[nodiscard]] auto createNextScene() const -> std::unique_ptr<Scenes::Scene>;
|
||||
|
||||
// Buffers persistents entre iteracions. Abans eren locals a run(),
|
||||
// ara són membres perquè iterate() els pot reutilitzar sense tornar-los
|
||||
@@ -77,7 +77,7 @@ class Director {
|
||||
|
||||
// Estat de l'escena actual. Abans vivia al stack del GameFiber; des
|
||||
// de la Phase B.2 de la migració viu directament al Director.
|
||||
std::unique_ptr<scenes::Scene> current_scene_;
|
||||
std::unique_ptr<Scenes::Scene> current_scene_;
|
||||
int game_state_{1}; // 0 = gameplay (ModuleGame), 1 = via SceneRegistry, -1 = quit
|
||||
Uint32 last_tick_ms_{0};
|
||||
bool context_initialized_{false};
|
||||
|
||||
@@ -48,8 +48,8 @@ void Bola::update() {
|
||||
// Comprovem si ha tocat a Sam
|
||||
if (this->x > (this->sam->x - 7) && this->x < (this->sam->x + 7) && this->y > (this->sam->y - 7) && this->y < (this->sam->y + 7)) {
|
||||
this->contador = 200;
|
||||
info::ctx.vida--;
|
||||
if (info::ctx.vida == 0) {
|
||||
Info::ctx.vida--;
|
||||
if (Info::ctx.vida == 0) {
|
||||
this->sam->o = 5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "game/info.hpp"
|
||||
|
||||
// La instància `info::ctx` està definida com a `inline` al header;
|
||||
// La instància `Info::ctx` està definida com a `inline` al header;
|
||||
// aquest fitxer es manté per a si cal afegir lògica addicional més endavant.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace info {
|
||||
namespace Info {
|
||||
|
||||
struct GameContext {
|
||||
int num_piramide = 0;
|
||||
@@ -17,8 +17,8 @@ namespace info {
|
||||
};
|
||||
|
||||
// Instància única de l'estat del joc. Reemplaça les variables soltes del
|
||||
// namespace `info::` per una struct encapsulada. A Fase 5 (single-threaded)
|
||||
// namespace `Info::` per una struct encapsulada. A Fase 5 (single-threaded)
|
||||
// es podrà passar per referència als mòduls en lloc d'accedir via singleton.
|
||||
inline GameContext ctx;
|
||||
|
||||
} // namespace info
|
||||
} // namespace Info
|
||||
|
||||
+14
-14
@@ -27,7 +27,7 @@ Mapa::~Mapa() {
|
||||
}
|
||||
|
||||
void Mapa::draw() {
|
||||
if (info::ctx.num_piramide != 4) {
|
||||
if (Info::ctx.num_piramide != 4) {
|
||||
switch (sam_->o) {
|
||||
case 0: // Down
|
||||
Jd8::blitCKToSurface(sam_->x, sam_->y, this->gfx_, 15, 125 + sam_->frame_pejades, 15, 1, this->fondo_, 255);
|
||||
@@ -93,7 +93,7 @@ auto Mapa::novaMomia() -> bool {
|
||||
void Mapa::preparaFondoEstatic() {
|
||||
// Prepara el fondo est�tic de l'habitaci�
|
||||
this->fondo_ = Jd8::newSurface();
|
||||
if (info::ctx.num_piramide == 6) {
|
||||
if (Info::ctx.num_piramide == 6) {
|
||||
Jd8::blitToSurface(9, 2, this->gfx_, 227, 185, 92, 7, this->fondo_); // Text "SECRETA"
|
||||
} else {
|
||||
Jd8::blitToSurface(9, 2, this->gfx_, 60, 185, 39, 7, this->fondo_); // Text "NIVELL"
|
||||
@@ -101,14 +101,14 @@ void Mapa::preparaFondoEstatic() {
|
||||
}
|
||||
Jd8::blitToSurface(130, 2, this->gfx_, 225, 192, 19, 8, this->fondo_); // Montonet de monedes + signe '='
|
||||
Jd8::blitToSurface(220, 2, this->gfx_, 160, 185, 48, 7, this->fondo_); // Text "ENERGIA"
|
||||
if (info::ctx.diners >= 200) {
|
||||
if (Info::ctx.diners >= 200) {
|
||||
Jd8::blitToSurface(175, 3, this->gfx_, 60, 193, 7, 6, this->fondo_);
|
||||
}
|
||||
|
||||
// Pinta taulells
|
||||
for (int y = 0; y < 11; y++) {
|
||||
for (int x = 0; x < 19; x++) {
|
||||
switch (info::ctx.num_piramide) {
|
||||
switch (Info::ctx.num_piramide) {
|
||||
case 1:
|
||||
Jd8::blitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx_, 0, 80, 15, 15, this->fondo_);
|
||||
break;
|
||||
@@ -154,7 +154,7 @@ void Mapa::preparaFondoEstatic() {
|
||||
// Pinta la porta
|
||||
Jd8::blitCKToSurface(150, 18, this->gfx_, 0, 143, 15, 12, this->fondo_, 255);
|
||||
|
||||
if (info::ctx.num_piramide == 2) {
|
||||
if (Info::ctx.num_piramide == 2) {
|
||||
Jd8::blitToSurface(5, 100, this->gfx_, 30, 140, 15, 15, this->fondo_);
|
||||
}
|
||||
}
|
||||
@@ -166,12 +166,12 @@ void swap(Uint8& a, Uint8& b) noexcept {
|
||||
}
|
||||
|
||||
void Mapa::preparaTombes() {
|
||||
const Uint8 contingut = info::ctx.num_piramide == 6 ? CONTE_DIAMANT : CONTE_RES;
|
||||
int cx = info::ctx.num_piramide == 6 ? 270 : 0;
|
||||
int cy = info::ctx.num_piramide == 6 ? 50 : 0;
|
||||
const Uint8 CONTINGUT = Info::ctx.num_piramide == 6 ? CONTE_DIAMANT : CONTE_RES;
|
||||
int cx = Info::ctx.num_piramide == 6 ? 270 : 0;
|
||||
int cy = Info::ctx.num_piramide == 6 ? 50 : 0;
|
||||
|
||||
for (auto& tombe : this->tombes) {
|
||||
tombe.contingut = contingut;
|
||||
tombe.contingut = CONTINGUT;
|
||||
tombe.oberta = false;
|
||||
tombe.costat[0] = false;
|
||||
tombe.costat[1] = false;
|
||||
@@ -180,7 +180,7 @@ void Mapa::preparaTombes() {
|
||||
tombe.x = cx;
|
||||
tombe.y = cy;
|
||||
}
|
||||
if (info::ctx.num_piramide == 6) {
|
||||
if (Info::ctx.num_piramide == 6) {
|
||||
return;
|
||||
}
|
||||
this->tombes[0].contingut = CONTE_FARAO;
|
||||
@@ -261,7 +261,7 @@ void Mapa::comprovaCaixa(Uint8 num) {
|
||||
break;
|
||||
case CONTE_TRESOR:
|
||||
this->tombes[num].x = 100;
|
||||
info::ctx.diners++;
|
||||
Info::ctx.diners++;
|
||||
break;
|
||||
case CONTE_FARAO:
|
||||
this->tombes[num].x = 150;
|
||||
@@ -281,9 +281,9 @@ void Mapa::comprovaCaixa(Uint8 num) {
|
||||
break;
|
||||
case CONTE_DIAMANT:
|
||||
this->tombes[num].y = 70;
|
||||
info::ctx.diamants++;
|
||||
info::ctx.diners += VALOR_DIAMANT;
|
||||
if (info::ctx.diamants == 16) {
|
||||
Info::ctx.diamants++;
|
||||
Info::ctx.diners += VALOR_DIAMANT;
|
||||
if (Info::ctx.diamants == 16) {
|
||||
this->farao_ = this->clau_ = true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -6,22 +6,22 @@ Marcador::Marcador(Jd8::Surface gfx, Prota* sam) {
|
||||
}
|
||||
|
||||
void Marcador::draw() {
|
||||
if (info::ctx.num_piramide < 6) {
|
||||
this->pintaNumero(55, 2, info::ctx.num_piramide);
|
||||
this->pintaNumero(80, 2, info::ctx.num_habitacio);
|
||||
if (Info::ctx.num_piramide < 6) {
|
||||
this->pintaNumero(55, 2, Info::ctx.num_piramide);
|
||||
this->pintaNumero(80, 2, Info::ctx.num_habitacio);
|
||||
}
|
||||
|
||||
this->pintaNumero(149, 2, info::ctx.diners / 100);
|
||||
this->pintaNumero(156, 2, (info::ctx.diners % 100) / 10);
|
||||
this->pintaNumero(163, 2, info::ctx.diners % 10);
|
||||
this->pintaNumero(149, 2, Info::ctx.diners / 100);
|
||||
this->pintaNumero(156, 2, (Info::ctx.diners % 100) / 10);
|
||||
this->pintaNumero(163, 2, Info::ctx.diners % 10);
|
||||
|
||||
if (this->sam->pergami) {
|
||||
Jd8::blitCK(190, 1, this->gfx, 209, 185, 15, 14, 255);
|
||||
}
|
||||
|
||||
Jd8::blitCK(271, 1, this->gfx, 0, 20, 15, info::ctx.vida * 3, 255);
|
||||
if (info::ctx.vida < 5) {
|
||||
Jd8::blitCK(271, 1 + (info::ctx.vida * 3), this->gfx, 75, 20, 15, 15 - (info::ctx.vida * 3), 255);
|
||||
Jd8::blitCK(271, 1, this->gfx, 0, 20, 15, Info::ctx.vida * 3, 255);
|
||||
if (Info::ctx.vida < 5) {
|
||||
Jd8::blitCK(271, 1 + (Info::ctx.vida * 3), this->gfx, 75, 20, 15, 15 - (Info::ctx.vida * 3), 255);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+28
-28
@@ -8,13 +8,13 @@
|
||||
#include "core/jail/jinput.hpp"
|
||||
|
||||
ModuleGame::ModuleGame() {
|
||||
this->gfx_ = Jd8::loadSurface(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif");
|
||||
this->gfx_ = Jd8::loadSurface(Info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif");
|
||||
Jg::setUpdateTicks(10);
|
||||
|
||||
this->sam_ = std::make_unique<Prota>(this->gfx_);
|
||||
this->mapa_ = std::make_unique<Mapa>(this->gfx_, this->sam_.get());
|
||||
this->marcador_ = std::make_unique<Marcador>(this->gfx_, this->sam_.get());
|
||||
if (info::ctx.num_piramide == 2) {
|
||||
if (Info::ctx.num_piramide == 2) {
|
||||
this->bola_ = std::make_unique<Bola>(this->gfx_, this->sam_.get());
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ void ModuleGame::onEnter() {
|
||||
// demanada, no fa res. Per això podem cridar-lo cada onEnter sense
|
||||
// desencadenar restarts indesitjats.
|
||||
const char* music_name = "piramide_1_4_5.ogg";
|
||||
if (info::ctx.num_piramide == 3) {
|
||||
if (Info::ctx.num_piramide == 3) {
|
||||
music_name = "piramide_3.ogg";
|
||||
} else if (info::ctx.num_piramide == 2) {
|
||||
} else if (Info::ctx.num_piramide == 2) {
|
||||
music_name = "piramide_2.ogg";
|
||||
} else if (info::ctx.num_piramide == 6) {
|
||||
} else if (Info::ctx.num_piramide == 6) {
|
||||
music_name = "secreta.ogg";
|
||||
}
|
||||
Audio::get()->playMusic(music_name);
|
||||
@@ -47,7 +47,7 @@ void ModuleGame::onEnter() {
|
||||
// Arranca el fade-in tick-based. El `PaletteFade` avança un pas (de
|
||||
// 32) per cada tick; durant aquesta fase el gameplay no corre,
|
||||
// només Draw+fade. Substituïx la crida bloquejant `JD8_FadeToPal`.
|
||||
fade_.startFadeTo(Jd8::loadPalette(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif"));
|
||||
fade_.startFadeTo(Jd8::loadPalette(Info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif"));
|
||||
phase_ = Phase::FADING_IN;
|
||||
}
|
||||
|
||||
@@ -95,9 +95,9 @@ auto ModuleGame::nextState() const -> int {
|
||||
if (Jg::quitting()) {
|
||||
return -1;
|
||||
}
|
||||
if (info::ctx.num_habitacio == 1 ||
|
||||
info::ctx.num_piramide == 100 ||
|
||||
info::ctx.num_piramide == 7) {
|
||||
if (Info::ctx.num_habitacio == 1 ||
|
||||
Info::ctx.num_piramide == 100 ||
|
||||
Info::ctx.num_piramide == 7) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -105,16 +105,16 @@ auto ModuleGame::nextState() const -> int {
|
||||
|
||||
void ModuleGame::applyFinalTransitions() const {
|
||||
if (this->final_ == 1) {
|
||||
info::ctx.num_habitacio++;
|
||||
if (info::ctx.num_habitacio == 6) {
|
||||
info::ctx.num_habitacio = 1;
|
||||
info::ctx.num_piramide++;
|
||||
Info::ctx.num_habitacio++;
|
||||
if (Info::ctx.num_habitacio == 6) {
|
||||
Info::ctx.num_habitacio = 1;
|
||||
Info::ctx.num_piramide++;
|
||||
}
|
||||
if (info::ctx.num_piramide == 6 && info::ctx.num_habitacio == 2) {
|
||||
info::ctx.num_piramide++;
|
||||
if (Info::ctx.num_piramide == 6 && Info::ctx.num_habitacio == 2) {
|
||||
Info::ctx.num_piramide++;
|
||||
}
|
||||
} else if (this->final_ == 2) {
|
||||
info::ctx.num_piramide = 100;
|
||||
Info::ctx.num_piramide = 100;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,23 +137,23 @@ void ModuleGame::update() {
|
||||
Ji::update();
|
||||
|
||||
this->final_ = this->sam_->update();
|
||||
const auto erased = std::erase_if(this->momies_, [](auto& m) { return m->update(); });
|
||||
info::ctx.momies -= static_cast<int>(erased);
|
||||
const auto ERASED = std::erase_if(this->momies_, [](auto& m) { return m->update(); });
|
||||
Info::ctx.momies -= static_cast<int>(ERASED);
|
||||
if (this->bola_) {
|
||||
this->bola_->update();
|
||||
}
|
||||
this->mapa_->update();
|
||||
if (this->mapa_->novaMomia()) {
|
||||
this->momies_.emplace_back(std::make_unique<Momia>(this->gfx_, true, 0, 0, this->sam_.get()));
|
||||
info::ctx.momies++;
|
||||
Info::ctx.momies++;
|
||||
}
|
||||
|
||||
if (Ji::cheatActivated("reviu")) {
|
||||
info::ctx.vida = 5;
|
||||
Info::ctx.vida = 5;
|
||||
}
|
||||
if (Ji::cheatActivated("alone")) {
|
||||
this->momies_.clear();
|
||||
info::ctx.momies = 0;
|
||||
Info::ctx.momies = 0;
|
||||
}
|
||||
if (Ji::cheatActivated("obert")) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
@@ -172,19 +172,19 @@ void ModuleGame::update() {
|
||||
}
|
||||
|
||||
void ModuleGame::iniciarMomies() {
|
||||
if (info::ctx.num_habitacio == 1) {
|
||||
info::ctx.momies = 1;
|
||||
if (Info::ctx.num_habitacio == 1) {
|
||||
Info::ctx.momies = 1;
|
||||
} else {
|
||||
info::ctx.momies++;
|
||||
Info::ctx.momies++;
|
||||
}
|
||||
if (info::ctx.num_piramide == 6) {
|
||||
info::ctx.momies = 8;
|
||||
if (Info::ctx.num_piramide == 6) {
|
||||
Info::ctx.momies = 8;
|
||||
}
|
||||
|
||||
int x = 20;
|
||||
int y = 170;
|
||||
bool dimonis = info::ctx.num_piramide == 6;
|
||||
for (int i = 0; i < info::ctx.momies; i++) {
|
||||
bool dimonis = Info::ctx.num_piramide == 6;
|
||||
for (int i = 0; i < Info::ctx.momies; i++) {
|
||||
this->momies_.emplace_back(std::make_unique<Momia>(this->gfx_, dimonis, x, y, this->sam_.get()));
|
||||
x += 65;
|
||||
if (x == 345) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
|
||||
// Escena de gameplay pur. Reemplaça el vell `Go()` bloquejant amb
|
||||
// l'interfície `scenes::Scene` tick-based: `onEnter()` arranca la
|
||||
// l'interfície `Scenes::Scene` tick-based: `onEnter()` arranca la
|
||||
// música i un fade-in, el `tick()` avança un frame (Draw + Update
|
||||
// gated per Jg::shouldUpdate), i quan la partida acaba fa un fade-out
|
||||
// abans de retornar el next state.
|
||||
@@ -27,7 +27,7 @@
|
||||
// 3. FADING_OUT — fade-out 32 passos mantenint l'últim frame visible
|
||||
// (substituïx el `JD8_FadeOut` bloquejant que feia el
|
||||
// destructor legacy).
|
||||
class ModuleGame : public scenes::Scene {
|
||||
class ModuleGame : public Scenes::Scene {
|
||||
public:
|
||||
ModuleGame();
|
||||
~ModuleGame() override;
|
||||
@@ -54,10 +54,10 @@ class ModuleGame : public scenes::Scene {
|
||||
void update(); // gated per Jg::shouldUpdate
|
||||
|
||||
void iniciarMomies();
|
||||
void applyFinalTransitions() const; // muta info::ctx quan final_ passa a !=0
|
||||
void applyFinalTransitions() const; // muta Info::ctx quan final_ passa a !=0
|
||||
|
||||
Phase phase_{Phase::FADING_IN};
|
||||
scenes::PaletteFade fade_;
|
||||
Scenes::PaletteFade fade_;
|
||||
Uint8 final_{0};
|
||||
Jd8::Surface gfx_{nullptr};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ Momia::Momia(Jd8::Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam)
|
||||
Frame f;
|
||||
f.w = 15;
|
||||
f.h = 15;
|
||||
if (info::ctx.num_piramide == 4) {
|
||||
if (Info::ctx.num_piramide == 4) {
|
||||
f.h -= 5;
|
||||
}
|
||||
f.x = (col * 15) + 75;
|
||||
@@ -73,7 +73,7 @@ void Momia::draw() {
|
||||
} else {
|
||||
Sprite::draw();
|
||||
|
||||
if (info::ctx.num_piramide == 4) {
|
||||
if (Info::ctx.num_piramide == 4) {
|
||||
if ((Jg::getCycleCounter() % 40) < 20) {
|
||||
Jd8::blitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255);
|
||||
} else {
|
||||
@@ -93,7 +93,7 @@ auto Momia::update() -> bool {
|
||||
return morta;
|
||||
}
|
||||
|
||||
if (this->sam->o < 4 && (this->dimoni || info::ctx.num_piramide == 5 || Jg::getCycleCounter() % 2 == 0)) {
|
||||
if (this->sam->o < 4 && (this->dimoni || Info::ctx.num_piramide == 5 || Jg::getCycleCounter() % 2 == 0)) {
|
||||
if ((this->x - 20) % 65 == 0 && (this->y - 30) % 35 == 0) {
|
||||
if (this->dimoni) {
|
||||
if (rand() % 2 == 0) {
|
||||
@@ -159,8 +159,8 @@ auto Momia::update() -> bool {
|
||||
if (this->sam->pergami) {
|
||||
this->sam->pergami = false;
|
||||
} else {
|
||||
info::ctx.vida--;
|
||||
if (info::ctx.vida == 0) {
|
||||
Info::ctx.vida--;
|
||||
if (Info::ctx.vida == 0) {
|
||||
this->sam->o = 5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ Prota::Prota(Jd8::Surface gfx)
|
||||
Frame f;
|
||||
f.w = 15;
|
||||
f.h = 15;
|
||||
if (info::ctx.num_piramide == 4) {
|
||||
if (Info::ctx.num_piramide == 4) {
|
||||
f.h -= 5;
|
||||
}
|
||||
f.x = x * 15;
|
||||
@@ -28,7 +28,7 @@ Prota::Prota(Jd8::Surface gfx)
|
||||
Frame f;
|
||||
f.w = 15;
|
||||
f.h = 30;
|
||||
if (info::ctx.num_piramide == 4) {
|
||||
if (Info::ctx.num_piramide == 4) {
|
||||
f.h -= 5;
|
||||
}
|
||||
f.x = x;
|
||||
@@ -42,7 +42,7 @@ Prota::Prota(Jd8::Surface gfx)
|
||||
Frame f;
|
||||
f.w = 15;
|
||||
f.h = 15;
|
||||
if (info::ctx.num_piramide == 4) {
|
||||
if (Info::ctx.num_piramide == 4) {
|
||||
f.h -= 5;
|
||||
}
|
||||
f.x = x;
|
||||
@@ -90,7 +90,7 @@ Prota::Prota(Jd8::Surface gfx)
|
||||
void Prota::draw() {
|
||||
Sprite::draw();
|
||||
|
||||
if (info::ctx.num_piramide == 4 && this->o != 4) {
|
||||
if (Info::ctx.num_piramide == 4 && this->o != 4) {
|
||||
if ((Jg::getCycleCounter() % 40) < 20) {
|
||||
Jd8::blitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255);
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "game/info.hpp"
|
||||
#include "game/scenes/scene_utils.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
void BannerScene::onEnter() {
|
||||
playMusic("music/banner.ogg");
|
||||
@@ -21,12 +21,12 @@ namespace scenes {
|
||||
Jd8::blit(39, 150, gfx_, 39, 175, 248, 20);
|
||||
|
||||
// Número de piràmide: les 4 variants del vell `doBanner` es reduïxen
|
||||
// a coordenades (sx,sy) calculades a partir de l'índex 0..3.
|
||||
const int idx = info::ctx.num_piramide - 2; // 2..5 → 0..3
|
||||
if (idx >= 0 && idx <= 3) {
|
||||
const int sx = (idx % 2) * 160;
|
||||
const int sy = (idx / 2) * 75;
|
||||
Jd8::blit(82, 60, gfx_, sx, sy, 160, 75);
|
||||
// a coordenades (SX,SY) calculades a partir de l'índex 0..3.
|
||||
const int IDX = Info::ctx.num_piramide - 2; // 2..5 → 0..3
|
||||
if (IDX >= 0 && IDX <= 3) {
|
||||
const int SX = (IDX % 2) * 160;
|
||||
const int SY = (IDX / 2) * 75;
|
||||
Jd8::blit(82, 60, gfx_, SX, SY, 160, 75);
|
||||
}
|
||||
|
||||
// PaletteFade copia internament amb memcpy; alliberem la paleta temporal.
|
||||
@@ -72,4 +72,4 @@ namespace scenes {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Banner pre-piràmide ("PIRÀMIDE X"). Reemplaça `ModuleSequence::doBanner()`.
|
||||
//
|
||||
// Flux:
|
||||
// 1. Arranca música "music/banner.ogg" i carrega gfx/ffase.gif.
|
||||
// 2. Pinta títol, subtítol i número de piràmide segons info::ctx.num_piramide.
|
||||
// 2. Pinta títol, subtítol i número de piràmide segons Info::ctx.num_piramide.
|
||||
// 3. Fade-in de paleta.
|
||||
// 4. Mostra ~5s o fins que es polse una tecla.
|
||||
// 5. Ja::fadeOutMusic(250) + fade-out de paleta.
|
||||
@@ -39,4 +39,4 @@ namespace scenes {
|
||||
int remaining_ms_{5000};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "core/resources/resource_cache.hpp"
|
||||
#include "game/options.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
namespace {
|
||||
constexpr int SCREEN_W = 320;
|
||||
@@ -42,8 +42,8 @@ namespace scenes {
|
||||
return;
|
||||
}
|
||||
|
||||
const float pct = Resource::Cache::get()->getProgress();
|
||||
const int filled = static_cast<int>(static_cast<float>(BAR_W) * pct);
|
||||
const float PCT = Resource::Cache::get()->getProgress();
|
||||
const int FILLED = static_cast<int>(static_cast<float>(BAR_W) * PCT);
|
||||
|
||||
// Vora de la barra (línia 1 píxel a dalt i a baix).
|
||||
Jd8::fillRect(BAR_X - 1, BAR_Y - 1, BAR_W + 2, 1, BAR_COLOR);
|
||||
@@ -52,9 +52,9 @@ namespace scenes {
|
||||
Jd8::fillRect(BAR_X + BAR_W, BAR_Y, 1, BAR_H, BAR_COLOR);
|
||||
|
||||
// Ompliment proporcional al progrés.
|
||||
if (filled > 0) {
|
||||
Jd8::fillRect(BAR_X, BAR_Y, filled, BAR_H, BAR_COLOR);
|
||||
if (FILLED > 0) {
|
||||
Jd8::fillRect(BAR_X, BAR_Y, FILLED, BAR_H, BAR_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "game/scenes/scene.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Escena de boot que conduix la càrrega incremental del Resource::Cache.
|
||||
// tick() crida loadStep amb un pressupost de ~8ms i pinta una barra
|
||||
@@ -23,4 +23,4 @@ namespace scenes {
|
||||
bool done_{false};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// No toquem la paleta activa: SetScreenPalette n'ha pres ownership.
|
||||
CreditsScene::~CreditsScene() = default;
|
||||
@@ -80,7 +80,7 @@ namespace scenes {
|
||||
|
||||
// Fons: 4 capes parallax + cotxe només si l'usuari ha aconseguit
|
||||
// tots els diamants (final "bo"). Altrament fons estàtic.
|
||||
if (info::ctx.diamants == 16) {
|
||||
if (Info::ctx.diamants == 16) {
|
||||
Jd8::blitCKScroll(50, vaddr3_, ((contador_ >> 3) % 320) + 1, 0, 50, 255);
|
||||
Jd8::blitCKScroll(50, vaddr3_, ((contador_ >> 2) % 320) + 1, 50, 50, 255);
|
||||
Jd8::blitCKScroll(50, vaddr3_, ((contador_ >> 1) % 320) + 1, 100, 50, 255);
|
||||
@@ -104,7 +104,7 @@ namespace scenes {
|
||||
std::fwrite("1", 1, 1, ini);
|
||||
std::fclose(ini);
|
||||
}
|
||||
info::ctx.nou_personatge = true;
|
||||
Info::ctx.nou_personatge = true;
|
||||
}
|
||||
|
||||
void CreditsScene::tick(int delta_ms) {
|
||||
@@ -132,7 +132,7 @@ namespace scenes {
|
||||
case Phase::FADING_OUT:
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) {
|
||||
info::ctx.num_piramide = 255;
|
||||
Info::ctx.num_piramide = 255;
|
||||
phase_ = Phase::DONE;
|
||||
}
|
||||
break;
|
||||
@@ -142,4 +142,4 @@ namespace scenes {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Crèdits finals del joc. Reemplaça `ModuleSequence::doCredits()`.
|
||||
//
|
||||
@@ -16,10 +16,10 @@ namespace scenes {
|
||||
// 1. Carrega gfx/final.gif (sprites de crèdits) i gfx/finals.gif (fons).
|
||||
// 2. Mostra els crèdits amb scroll vertical de 2 columnes durant
|
||||
// ~62 segons (contador 0..3100 × 20 ms).
|
||||
// 3. Si `info::ctx.diamants == 16`, pinta addicionalment un parallax
|
||||
// 3. Si `Info::ctx.diamants == 16`, pinta addicionalment un parallax
|
||||
// de 4 capes amb cotxe animat (8 frames). Si no, 2 blits fixos.
|
||||
// 4. Al acabar (per tecla o per contador), crea el fitxer `trick.ini`
|
||||
// i activa `info::ctx.nou_personatge`.
|
||||
// i activa `Info::ctx.nou_personatge`.
|
||||
// 5. Fade-out de paleta. Torna a la intro (num_piramide = 255).
|
||||
//
|
||||
// Registrada al SceneRegistry amb state_key = 8.
|
||||
@@ -50,4 +50,4 @@ namespace scenes {
|
||||
int contador_acc_ms_{0};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
FrameAnimator::FrameAnimator(int num_frames, int frame_ms, bool loop)
|
||||
: num_frames_(std::max(1, num_frames)),
|
||||
@@ -35,4 +35,4 @@ namespace scenes {
|
||||
finished_ = false;
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Cicla per un conjunt de frames numerats (0..num_frames-1) avançant un
|
||||
// frame cada `frame_ms` mil·lisegons. No carrega ni dibuixa cap sprite —
|
||||
@@ -31,4 +31,4 @@ namespace scenes {
|
||||
bool finished_{false};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
IntroNewLogoScene::IntroNewLogoScene() = default;
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace scenes {
|
||||
// deixem que la sub-escena gestione el seu propi skip (que a més
|
||||
// respecta la fase "final" no skippable de la variant 0).
|
||||
if (phase_ != Phase::SPRITES && phase_ != Phase::DONE && Ji::anyKey()) {
|
||||
info::ctx.num_piramide = 0;
|
||||
Info::ctx.num_piramide = 0;
|
||||
phase_ = Phase::DONE;
|
||||
return;
|
||||
}
|
||||
@@ -218,7 +218,7 @@ namespace scenes {
|
||||
// El vell `Go()` post-switch feia `num_piramide = 0`
|
||||
// per passar al menú. Sense açò el while del fiber
|
||||
// tornaria a crear IntroNewLogoScene infinitament.
|
||||
info::ctx.num_piramide = 0;
|
||||
Info::ctx.num_piramide = 0;
|
||||
phase_ = Phase::DONE;
|
||||
}
|
||||
break;
|
||||
@@ -228,4 +228,4 @@ namespace scenes {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Intro "moderna" del logo Jailgames amb revelat lletra-a-lletra +
|
||||
// ciclo de paleta final. Reemplaça `ModuleSequence::doIntroNewLogo()`.
|
||||
@@ -65,4 +65,4 @@ namespace scenes {
|
||||
int palette_step_{0};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
IntroScene::IntroScene() = default;
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace scenes {
|
||||
// la sub-escena gestione el seu propi skip internament, que a més
|
||||
// respecta la fase "final" no skippable de la variant 0.
|
||||
if (phase_ != Phase::SPRITES && phase_ != Phase::DONE && Ji::anyKey()) {
|
||||
info::ctx.num_piramide = 0;
|
||||
Info::ctx.num_piramide = 0;
|
||||
phase_ = Phase::DONE;
|
||||
return;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ namespace scenes {
|
||||
// Equivalent al vell `Go()` post-switch: passem al menú.
|
||||
// Sense açò el while del fiber tornaria a crear IntroScene
|
||||
// infinitament amb num_piramide encara a 255.
|
||||
info::ctx.num_piramide = 0;
|
||||
Info::ctx.num_piramide = 0;
|
||||
phase_ = Phase::DONE;
|
||||
}
|
||||
break;
|
||||
@@ -230,4 +230,4 @@ namespace scenes {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Intro "legacy" del wordmark JAILGAMES lletra a lletra + cicle de paleta.
|
||||
// Reemplaça `ModuleSequence::doIntro()`. S'activa quan
|
||||
@@ -63,4 +63,4 @@ namespace scenes {
|
||||
int palette_step_{0};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -314,7 +314,7 @@ namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
IntroSpritesScene::IntroSpritesScene(SurfaceHandle&& gfx)
|
||||
: gfx_(std::move(gfx)) {}
|
||||
@@ -367,4 +367,4 @@ namespace scenes {
|
||||
phases[phase_].render(gfx_.get(), phaseCurrentI(phases[phase_], phase_step_));
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Sub-escena de sprites de la intro (prota + momia + mapa + etc).
|
||||
// Reemplaça `ModuleSequence::doIntroSprites()`. No es registra al
|
||||
@@ -39,4 +39,4 @@ namespace scenes {
|
||||
bool done_{false};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "core/jail/jinput.hpp"
|
||||
#include "game/info.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
void MenuScene::onEnter() {
|
||||
fondo_ = SurfaceHandle("gfx/menu.gif");
|
||||
@@ -49,10 +49,10 @@ namespace scenes {
|
||||
// "Polsa tecla" parpallejant. Al vell `contador % 100 > 30` amb
|
||||
// updateTicks=20 ms, el cicle són 2000 ms amb un llindar de 600 ms:
|
||||
// amagat els primers 600 ms, visible els següents 1400 ms.
|
||||
const bool blink_on = (blink_ms_ % 2000) > 600;
|
||||
if (blink_on) {
|
||||
const bool BLINK_ON = (blink_ms_ % 2000) > 600;
|
||||
if (BLINK_ON) {
|
||||
Jd8::blitCK(98, 130, gfx_, 161, 92, 127, 9, 255);
|
||||
if (info::ctx.nou_personatge) {
|
||||
if (Info::ctx.nou_personatge) {
|
||||
Jd8::blitCK(68, 141, gfx_, 128, 105, 189, 9, 255);
|
||||
}
|
||||
}
|
||||
@@ -96,12 +96,12 @@ namespace scenes {
|
||||
render();
|
||||
|
||||
// Qualsevol tecla tanca el menú. Llegim 'P' explícitament abans
|
||||
// de reiniciar el flag de input perquè `info::ctx.pepe_activat`
|
||||
// de reiniciar el flag de input perquè `Info::ctx.pepe_activat`
|
||||
// reflecteixca si l'usuari estava polsant P al moment d'eixir.
|
||||
if (Ji::anyKey() || Ji::keyPressed(SDL_SCANCODE_P)) {
|
||||
info::ctx.pepe_activat = Ji::keyPressed(SDL_SCANCODE_P);
|
||||
Info::ctx.pepe_activat = Ji::keyPressed(SDL_SCANCODE_P);
|
||||
Ji::disableKeyboard(60);
|
||||
info::ctx.num_piramide = 1;
|
||||
Info::ctx.num_piramide = 1;
|
||||
fade_.startFadeOut();
|
||||
phase_ = Phase::FADING_OUT;
|
||||
}
|
||||
@@ -120,4 +120,4 @@ namespace scenes {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Menú del títol. Reemplaça `ModuleSequence::doMenu()`.
|
||||
//
|
||||
@@ -20,7 +20,7 @@ namespace scenes {
|
||||
// i el text "polsa tecla" parpallejant cada 2 s (visible 1.4 s,
|
||||
// amagat 0.6 s, igual que el `contador % 100 > 30` original).
|
||||
// 4. Quan l'usuari polsa qualsevol tecla — o 'P' per a activar Pepe —
|
||||
// llegim `info::ctx.pepe_activat`, disparem fade-out i marquem
|
||||
// llegim `Info::ctx.pepe_activat`, disparem fade-out i marquem
|
||||
// num_piramide=1 (vas a doSlides).
|
||||
//
|
||||
// Registrat al SceneRegistry amb state_key = 0.
|
||||
@@ -55,4 +55,4 @@ namespace scenes {
|
||||
int blink_ms_{0};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
#include "game/info.hpp"
|
||||
#include "game/scenes/scene_utils.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
void MortScene::onEnter() {
|
||||
playMusic("music/mort.ogg");
|
||||
Ji::disableKeyboard(60);
|
||||
info::ctx.vida = 5;
|
||||
Info::ctx.vida = 5;
|
||||
|
||||
gfx_ = SurfaceHandle("gfx/gameover.gif");
|
||||
Jd8::clearScreen(0);
|
||||
@@ -47,7 +47,7 @@ namespace scenes {
|
||||
// Arrenca música del següent mòdul abans del fade out,
|
||||
// igual que la versió vella feia al final de doMort().
|
||||
playMusic("music/menu.ogg");
|
||||
info::ctx.num_piramide = 0;
|
||||
Info::ctx.num_piramide = 0;
|
||||
fade_.startFadeOut();
|
||||
phase_ = Phase::FADING_OUT;
|
||||
}
|
||||
@@ -65,4 +65,4 @@ namespace scenes {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Pantalla de "game over". Reemplaça `ModuleSequence::doMort()`.
|
||||
//
|
||||
@@ -34,4 +34,4 @@ namespace scenes {
|
||||
int remaining_ms_{10000}; // 1000 ticks × 10 ms/tick del doMort original
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "game/scenes/palette_fade.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
void PaletteFade::startFadeOut() {
|
||||
Jd8::fadeStartOut();
|
||||
@@ -27,4 +27,4 @@ namespace scenes {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "core/jail/jdraw8.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Embolcall fi damunt de la màquina d'estats de fade de jdraw8
|
||||
// (`JD8_FadeStart*` / `Jd8::fadeTickStep`). Exposa una API time-based
|
||||
@@ -27,4 +27,4 @@ namespace scenes {
|
||||
bool active_{false};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// - `onEnter()` es crida una vegada just abans del primer tick. És el
|
||||
// moment bo per a arrancar música, disparar un fade-in, etc.
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
@@ -28,10 +28,10 @@ namespace scenes {
|
||||
|
||||
// Valor retornat al caller quan l'escena acaba — equivalent al int
|
||||
// que retornaven les velles funcions `Go()` de ModuleSequence:
|
||||
// 1 = continuar amb la següent escena segons info::ctx
|
||||
// 1 = continuar amb la següent escena segons Info::ctx
|
||||
// 0 = entrar al gameplay (ModuleGame)
|
||||
// -1 = eixir del joc
|
||||
[[nodiscard]] virtual auto nextState() const -> int { return 1; }
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "game/scenes/scene_registry.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
auto SceneRegistry::instance() -> SceneRegistry& {
|
||||
static SceneRegistry inst;
|
||||
@@ -12,11 +12,11 @@ namespace scenes {
|
||||
}
|
||||
|
||||
auto SceneRegistry::tryCreate(int state_key) const -> std::unique_ptr<Scene> {
|
||||
const auto it = factories_.find(state_key);
|
||||
if (it == factories_.end()) {
|
||||
const auto IT = factories_.find(state_key);
|
||||
if (IT == factories_.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return it->second();
|
||||
return IT->second();
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
#include "game/scenes/scene.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Mapa de `state_key` (actualment = `info::ctx.num_piramide`) a factory
|
||||
// Mapa de `state_key` (actualment = `Info::ctx.num_piramide`) a factory
|
||||
// d'escena. Permet que el dispatch de `gameFiberEntry` provi primer una
|
||||
// Scene nova i caiga al vell `ModuleSequence::Go()` si encara no està
|
||||
// migrada.
|
||||
@@ -34,4 +34,4 @@ namespace scenes {
|
||||
std::unordered_map<int, Factory> factories_;
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
namespace {
|
||||
auto basename(const char* path) -> std::string {
|
||||
@@ -21,4 +21,4 @@ namespace scenes {
|
||||
Audio::get()->playMusic(basename(filename), loop);
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
// Helpers compartits per les escenes. Aquest header és petit i creix
|
||||
// quan una abstracció comú apareix en dos o més escenes.
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Carrega un OGG de `data/` i arranca'l com a música de fons. Substituïx
|
||||
// el `play_music()` repetit en tots els doX() del vell modulesequence.
|
||||
// `loop`: -1 = infinit (per defecte), 0 = una sola vegada, N = N+1 passades.
|
||||
void playMusic(const char* filename, int loop = -1);
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace {
|
||||
|
||||
constexpr int TICK_MS = 20; // Jg::setUpdateTicks(20) del vell doSecreta
|
||||
|
||||
// Durades per fase, derivades dels contador-thresholds del vell:
|
||||
// tomba1 scroll: 127 passos (contador 1→128) × 20ms
|
||||
// tomba1 hold: 128 passos (contador 128→0) × 20ms
|
||||
// Durades per fase, derivades dels CONTADOR-thresholds del vell:
|
||||
// tomba1 scroll: 127 passos (CONTADOR 1→128) × 20ms
|
||||
// tomba1 hold: 128 passos (CONTADOR 128→0) × 20ms
|
||||
// tomba2 scroll: 94 passos × 20ms
|
||||
// tomba2 hold: 94 passos × 20ms
|
||||
// reveal horit: 80 passos × 20ms
|
||||
@@ -34,7 +34,7 @@ namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
SecretaScene::~SecretaScene() {
|
||||
delete[] pal_aux_;
|
||||
@@ -107,11 +107,11 @@ namespace scenes {
|
||||
|
||||
case Phase::TOMBA1_SCROLL_IN: {
|
||||
phase_acc_ms_ += delta_ms;
|
||||
const int contador = std::min(128, (phase_acc_ms_ / TICK_MS) + 1);
|
||||
const int CONTADOR = std::min(128, (phase_acc_ms_ / TICK_MS) + 1);
|
||||
// Dos blits solapats: el primer avança a velocitat completa,
|
||||
// el segon (contingut de la dreta del src) a meitat (contador>>1).
|
||||
Jd8::blit(70, 60, gfx_, 0, contador, 178, 70);
|
||||
Jd8::blitCK(70, 60, gfx_, 178, contador >> 1, 142, 70, 255);
|
||||
// el segon (contingut de la dreta del src) a meitat (CONTADOR>>1).
|
||||
Jd8::blit(70, 60, gfx_, 0, CONTADOR, 178, 70);
|
||||
Jd8::blitCK(70, 60, gfx_, 178, CONTADOR >> 1, 142, 70, 255);
|
||||
if (phase_acc_ms_ >= TOMBA1_SCROLL_MS) {
|
||||
phase_ = Phase::TOMBA1_HOLD;
|
||||
phase_acc_ms_ = 0;
|
||||
@@ -130,8 +130,8 @@ namespace scenes {
|
||||
|
||||
case Phase::TOMBA2_SCROLL_IN: {
|
||||
phase_acc_ms_ += delta_ms;
|
||||
const int contador = std::min(94, (phase_acc_ms_ / TICK_MS) + 1);
|
||||
Jd8::blit(55, 53, gfx_, 0, 158 - contador, 211, contador);
|
||||
const int CONTADOR = std::min(94, (phase_acc_ms_ / TICK_MS) + 1);
|
||||
Jd8::blit(55, 53, gfx_, 0, 158 - CONTADOR, 211, CONTADOR);
|
||||
if (phase_acc_ms_ >= TOMBA2_SCROLL_MS) {
|
||||
phase_ = Phase::TOMBA2_HOLD;
|
||||
phase_acc_ms_ = 0;
|
||||
@@ -150,10 +150,10 @@ namespace scenes {
|
||||
|
||||
case Phase::TOMBA2_REVEAL: {
|
||||
phase_acc_ms_ += delta_ms;
|
||||
const int contador = std::min(80, (phase_acc_ms_ / TICK_MS) + 1);
|
||||
const int CONTADOR = std::min(80, (phase_acc_ms_ / TICK_MS) + 1);
|
||||
// Revelat horitzontal simètric: l'amplada creix 2px per tick
|
||||
// i el src_x es desplaça a l'esquerra el mateix.
|
||||
Jd8::blit(80, 68, gfx_, 160 - (contador * 2), 0, contador * 2, 64);
|
||||
Jd8::blit(80, 68, gfx_, 160 - (CONTADOR * 2), 0, CONTADOR * 2, 64);
|
||||
if (phase_acc_ms_ >= TOMBA2_REVEAL_MS) {
|
||||
phase_ = Phase::TOMBA2_REVEAL_HOLD;
|
||||
phase_acc_ms_ = 0;
|
||||
@@ -171,11 +171,11 @@ namespace scenes {
|
||||
|
||||
case Phase::RED_PULSE: {
|
||||
phase_acc_ms_ += delta_ms;
|
||||
const int contador = std::min(51, phase_acc_ms_ / TICK_MS);
|
||||
const int CONTADOR = std::min(51, phase_acc_ms_ / TICK_MS);
|
||||
// Anima el canal R dels índexs 254 i 253 (aquest a la meitat
|
||||
// de brillantor). Va de (12,11,11) fins a (63,11,11) / (31,11,11).
|
||||
Jd8::setPaletteColor(254, contador + 12, 11, 11);
|
||||
Jd8::setPaletteColor(253, (contador + 12) >> 1, 11, 11);
|
||||
Jd8::setPaletteColor(254, CONTADOR + 12, 11, 11);
|
||||
Jd8::setPaletteColor(253, (CONTADOR + 12) >> 1, 11, 11);
|
||||
if (phase_acc_ms_ >= RED_PULSE_MS) {
|
||||
phase_ = Phase::RED_PULSE_HOLD;
|
||||
phase_acc_ms_ = 0;
|
||||
@@ -202,4 +202,4 @@ namespace scenes {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Pre-Secreta. Reemplaça `ModuleSequence::doSecreta()`.
|
||||
//
|
||||
@@ -65,4 +65,4 @@ namespace scenes {
|
||||
bool skip_triggered_{false};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -20,15 +20,15 @@ namespace {
|
||||
constexpr int BG_COLOR_INDEX = 255;
|
||||
|
||||
// Desplaçament inicial del slide segons direcció del wipe.
|
||||
// Slide 1 i 3: "scroll in from right" (pos_x va de 320 → 0).
|
||||
// Slide 2: "wipe reverse" (pos_x va de -320 → 0), el mateix efecte
|
||||
// Slide 1 i 3: "scroll in from right" (POS_X va de 320 → 0).
|
||||
// Slide 2: "wipe reverse" (POS_X va de -320 → 0), el mateix efecte
|
||||
// estrany del doSlides vell on la imatge es desplaça des de l'esquerra
|
||||
// però revela primer el lateral dret del src.
|
||||
constexpr int SLIDE_START_X[3] = {320, -320, 320};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
SlidesScene::~SlidesScene() {
|
||||
delete[] pal_aux_;
|
||||
@@ -36,13 +36,13 @@ namespace scenes {
|
||||
}
|
||||
|
||||
void SlidesScene::onEnter() {
|
||||
num_piramide_at_start_ = info::ctx.num_piramide;
|
||||
num_piramide_at_start_ = Info::ctx.num_piramide;
|
||||
|
||||
const char* arxiu = nullptr;
|
||||
if (num_piramide_at_start_ == 7) {
|
||||
// loop=1 per replicar el vell `play_music("final.ogg", 1)`.
|
||||
playMusic("music/final.ogg", 1);
|
||||
arxiu = (info::ctx.diners < 200) ? "gfx/intro2.gif" : "gfx/intro3.gif";
|
||||
arxiu = (Info::ctx.diners < 200) ? "gfx/intro2.gif" : "gfx/intro3.gif";
|
||||
} else {
|
||||
arxiu = "gfx/intro.gif";
|
||||
}
|
||||
@@ -65,12 +65,12 @@ namespace scenes {
|
||||
next_state_ = 0;
|
||||
}
|
||||
|
||||
void SlidesScene::drawSlide(int slide_idx, int pos_x) {
|
||||
const int src_y = slide_idx * SLIDE_H;
|
||||
void SlidesScene::drawSlide(int slide_idx, int POS_X) {
|
||||
const int SRC_Y = slide_idx * SLIDE_H;
|
||||
|
||||
// Clipping manual: translada un rect de 320×65 des de (pos_x, SLIDE_Y)
|
||||
// Clipping manual: translada un rect de 320×65 des de (POS_X, SLIDE_Y)
|
||||
// a l'àrea visible (0..319, SLIDE_Y..SLIDE_Y+64).
|
||||
int dst_x = pos_x;
|
||||
int dst_x = POS_X;
|
||||
int src_x = 0;
|
||||
int w = 320;
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace scenes {
|
||||
}
|
||||
|
||||
if (w > 0) {
|
||||
Jd8::blit(dst_x, SLIDE_Y, gfx_, src_x, src_y, w, SLIDE_H);
|
||||
Jd8::blit(dst_x, SLIDE_Y, gfx_, src_x, SRC_Y, w, SLIDE_H);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,13 +123,13 @@ namespace scenes {
|
||||
} else if (phase_ == Phase::SLIDE2_ENTER) {
|
||||
slide_idx = 1;
|
||||
}
|
||||
const float t = std::min(1.0F, static_cast<float>(phase_acc_ms_) / static_cast<float>(SCROLL_MS));
|
||||
const float eased = Easing::outCubic(t);
|
||||
const int pos_x = Easing::lerpInt(SLIDE_START_X[slide_idx], 0, eased);
|
||||
drawSlide(slide_idx, pos_x);
|
||||
const float T = std::min(1.0F, static_cast<float>(phase_acc_ms_) / static_cast<float>(SCROLL_MS));
|
||||
const float EASED = Easing::outCubic(T);
|
||||
const int POS_X = Easing::lerpInt(SLIDE_START_X[slide_idx], 0, EASED);
|
||||
drawSlide(slide_idx, POS_X);
|
||||
|
||||
if (phase_acc_ms_ >= SCROLL_MS) {
|
||||
// Garanteix posició final exacta (pos_x=0).
|
||||
// Garanteix posició final exacta (POS_X=0).
|
||||
drawSlide(slide_idx, 0);
|
||||
if (phase_ == Phase::SLIDE1_ENTER) {
|
||||
phase_ = Phase::SLIDE1_HOLD;
|
||||
@@ -183,7 +183,7 @@ namespace scenes {
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) {
|
||||
if (num_piramide_at_start_ == 7) {
|
||||
info::ctx.num_piramide = 8;
|
||||
Info::ctx.num_piramide = 8;
|
||||
next_state_ = 1;
|
||||
} else {
|
||||
next_state_ = 0;
|
||||
@@ -197,4 +197,4 @@ namespace scenes {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// 3 slides narratius amb scroll d'entrada + espera + transició amb
|
||||
// fade-out. Reemplaça `ModuleSequence::doSlides()`.
|
||||
@@ -78,4 +78,4 @@ namespace scenes {
|
||||
bool skip_triggered_{false};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
void SpriteMover::moveTo(int x0, int y0, int x1, int y1, int duration_ms, EaseFn ease) {
|
||||
x0_ = x0;
|
||||
@@ -32,10 +32,10 @@ namespace scenes {
|
||||
return;
|
||||
}
|
||||
elapsed_ms_ = std::min(elapsed_ms_ + delta_ms, duration_ms_);
|
||||
const float t = static_cast<float>(elapsed_ms_) / static_cast<float>(duration_ms_);
|
||||
const float eased = ease_(t);
|
||||
cur_x_ = Easing::lerpInt(x0_, x1_, eased);
|
||||
cur_y_ = Easing::lerpInt(y0_, y1_, eased);
|
||||
const float T = static_cast<float>(elapsed_ms_) / static_cast<float>(duration_ms_);
|
||||
const float EASED = ease_(T);
|
||||
cur_x_ = Easing::lerpInt(x0_, x1_, EASED);
|
||||
cur_y_ = Easing::lerpInt(y0_, y1_, EASED);
|
||||
}
|
||||
|
||||
auto SpriteMover::progress() const -> float {
|
||||
@@ -45,4 +45,4 @@ namespace scenes {
|
||||
return static_cast<float>(elapsed_ms_) / static_cast<float>(duration_ms_);
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "utils/easing.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Interpola una posició 2D entre dos punts durant un temps donat amb
|
||||
// una funció d'easing. No toca cap surface — el caller llegix x()/y()
|
||||
@@ -35,4 +35,4 @@ namespace scenes {
|
||||
EaseFn ease_{Easing::linear};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "game/scenes/surface_handle.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
SurfaceHandle::SurfaceHandle(const char* file)
|
||||
: surface_(Jd8::loadSurface(file)) {}
|
||||
@@ -47,4 +47,4 @@ namespace scenes {
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "core/jail/jdraw8.hpp"
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Wrapper RAII damunt de `Jd8::Surface`. Allibera automàticament amb
|
||||
// `Jd8::freeSurface` al destructor. Move-only per evitar dobles alliberaments.
|
||||
@@ -46,4 +46,4 @@ namespace scenes {
|
||||
Jd8::Surface surface_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
auto Timeline::step(int duration_ms, StepFn fn) -> Timeline& {
|
||||
Step s;
|
||||
@@ -98,4 +98,4 @@ namespace scenes {
|
||||
return static_cast<float>(elapsed_in_step_) / static_cast<float>(s.duration_ms);
|
||||
}
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace scenes {
|
||||
namespace Scenes {
|
||||
|
||||
// Timeline declaratiu de passos seqüencials. Cada pas té una duració en
|
||||
// ms i un callback. Exemple d'ús:
|
||||
@@ -54,4 +54,4 @@ namespace scenes {
|
||||
bool skipped_{false};
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
} // namespace Scenes
|
||||
|
||||
+5
-5
@@ -38,8 +38,8 @@ auto SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) -> SDL_App
|
||||
const char* base_path = SDL_GetBasePath();
|
||||
std::string resource_pack_path;
|
||||
if (base_path != nullptr) {
|
||||
const std::string data_path = std::string(base_path) + "data/";
|
||||
Jf::setResourceFolder(data_path.c_str());
|
||||
const std::string DATA_PATH = std::string(base_path) + "data/";
|
||||
Jf::setResourceFolder(DATA_PATH.c_str());
|
||||
resource_pack_path = std::string(base_path) + "resources.pack";
|
||||
} else {
|
||||
resource_pack_path = "resources.pack";
|
||||
@@ -49,11 +49,11 @@ auto SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) -> SDL_App
|
||||
// Release natiu exigix el pack (sense fallback); Debug i WASM mantenen
|
||||
// el fallback actiu per a desenvolupament i per al build amb MEMFS.
|
||||
#if defined(NDEBUG) && !defined(__EMSCRIPTEN__)
|
||||
const bool enable_fallback = false;
|
||||
const bool ENABLE_FALLBACK = false;
|
||||
#else
|
||||
const bool enable_fallback = true;
|
||||
const bool ENABLE_FALLBACK = true;
|
||||
#endif
|
||||
if (!ResourceHelper::initializeResourceSystem(resource_pack_path, enable_fallback)) {
|
||||
if (!ResourceHelper::initializeResourceSystem(resource_pack_path, ENABLE_FALLBACK)) {
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace Easing {
|
||||
}
|
||||
|
||||
auto outCubic(float t) -> float {
|
||||
const float inv = 1.0F - t;
|
||||
return 1.0F - (inv * inv * inv);
|
||||
const float INV = 1.0F - t;
|
||||
return 1.0F - (INV * INV * INV);
|
||||
}
|
||||
auto inCubic(float t) -> float { return t * t * t; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user