step 1: mort_scene substituix doMort() amb la capa scenes::
This commit is contained in:
@@ -48,6 +48,7 @@ set(APP_SOURCES
|
|||||||
source/scenes/palette_fade.cpp
|
source/scenes/palette_fade.cpp
|
||||||
source/scenes/surface_handle.cpp
|
source/scenes/surface_handle.cpp
|
||||||
source/scenes/scene_registry.cpp
|
source/scenes/scene_registry.cpp
|
||||||
|
source/scenes/mort_scene.cpp
|
||||||
|
|
||||||
# Game
|
# Game
|
||||||
source/game/options.cpp
|
source/game/options.cpp
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "game/modulegame.hpp"
|
#include "game/modulegame.hpp"
|
||||||
#include "game/modulesequence.hpp"
|
#include "game/modulesequence.hpp"
|
||||||
#include "game/options.hpp"
|
#include "game/options.hpp"
|
||||||
|
#include "scenes/mort_scene.hpp"
|
||||||
#include "scenes/scene.hpp"
|
#include "scenes/scene.hpp"
|
||||||
#include "scenes/scene_registry.hpp"
|
#include "scenes/scene_registry.hpp"
|
||||||
|
|
||||||
@@ -94,6 +95,14 @@ void gameFiberEntry() {
|
|||||||
void Director::init() {
|
void Director::init() {
|
||||||
instance_ = new Director();
|
instance_ = new Director();
|
||||||
Gamepad::init();
|
Gamepad::init();
|
||||||
|
|
||||||
|
// Registre d'escenes migrades. Cada entrada = una funció del vell
|
||||||
|
// ModuleSequence reescrita com a `scenes::*Scene`. Mentre vagen
|
||||||
|
// caient, el fallback al switch legacy de gameFiberEntry deixa de
|
||||||
|
// rebre aquests states.
|
||||||
|
auto& registry = scenes::SceneRegistry::instance();
|
||||||
|
registry.registerScene(100, [] { return std::make_unique<scenes::MortScene>(); });
|
||||||
|
|
||||||
GameFiber::init(gameFiberEntry);
|
GameFiber::init(gameFiberEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,9 +57,7 @@ int ModuleSequence::Go() {
|
|||||||
case 8: // Credits
|
case 8: // Credits
|
||||||
doCredits();
|
doCredits();
|
||||||
break;
|
break;
|
||||||
case 100: // Mort
|
// case 100 (Mort) → migrat a scenes::MortScene, dispatch via SceneRegistry.
|
||||||
doMort();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JD8_FadeOut();
|
JD8_FadeOut();
|
||||||
@@ -1292,35 +1290,4 @@ void ModuleSequence::doCredits() {
|
|||||||
JD8_FreeSurface(vaddr2);
|
JD8_FreeSurface(vaddr2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModuleSequence::doMort() {
|
// doMort() — migrat a scenes::MortScene (source/scenes/mort_scene.cpp)
|
||||||
play_music("00000001.ogg");
|
|
||||||
|
|
||||||
JI_DisableKeyboard(60);
|
|
||||||
|
|
||||||
info::ctx.vida = 5;
|
|
||||||
this->contador = 1000;
|
|
||||||
|
|
||||||
JD8_Surface gfx = JD8_LoadSurface("gameover.gif");
|
|
||||||
JD8_Palette pal = JD8_LoadPalette("gameover.gif");
|
|
||||||
|
|
||||||
JD8_ClearScreen(0);
|
|
||||||
|
|
||||||
JD8_Blit(gfx);
|
|
||||||
|
|
||||||
JD8_FadeToPal(pal);
|
|
||||||
|
|
||||||
bool exit = false;
|
|
||||||
while (!exit && !JG_Quitting()) {
|
|
||||||
if (JG_ShouldUpdate()) {
|
|
||||||
JI_Update();
|
|
||||||
|
|
||||||
if (JI_AnyKey()) {
|
|
||||||
exit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
contador--;
|
|
||||||
if (contador == 0) exit = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
play_music("00000003.ogg");
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class ModuleSequence {
|
|||||||
void doBanner();
|
void doBanner();
|
||||||
void doSecreta();
|
void doSecreta();
|
||||||
void doCredits();
|
void doCredits();
|
||||||
void doMort();
|
// doMort() → migrat a scenes::MortScene
|
||||||
|
|
||||||
int contador;
|
int contador;
|
||||||
};
|
};
|
||||||
|
|||||||
80
source/scenes/mort_scene.cpp
Normal file
80
source/scenes/mort_scene.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#include "scenes/mort_scene.hpp"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include "core/jail/jail_audio.hpp"
|
||||||
|
#include "core/jail/jdraw8.hpp"
|
||||||
|
#include "core/jail/jfile.hpp"
|
||||||
|
#include "core/jail/jinput.hpp"
|
||||||
|
#include "game/info.hpp"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Helper local: carrega un OGG del disc i l'envia a JA_PlayMusic. Equivalent
|
||||||
|
// al `play_music()` del modulesequence vell. El buffer es queda huérfano
|
||||||
|
// després de passar-lo a JA_LoadMusic (que n'ha fet una còpia SDL_malloc'd).
|
||||||
|
// Leak conegut del codi original, no el fixem en aquesta escena.
|
||||||
|
void play_music(const char* music) {
|
||||||
|
int size = 0;
|
||||||
|
char* buffer = file_getfilebuffer(music, size);
|
||||||
|
if (!buffer) return;
|
||||||
|
JA_PlayMusic(JA_LoadMusic(reinterpret_cast<Uint8*>(buffer), size, music));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace scenes {
|
||||||
|
|
||||||
|
void MortScene::onEnter() {
|
||||||
|
play_music("00000001.ogg");
|
||||||
|
JI_DisableKeyboard(60);
|
||||||
|
info::ctx.vida = 5;
|
||||||
|
|
||||||
|
gfx_ = SurfaceHandle("gameover.gif");
|
||||||
|
JD8_ClearScreen(0);
|
||||||
|
JD8_Blit(gfx_);
|
||||||
|
|
||||||
|
// PaletteFade en fa una còpia interna via memcpy, així que alliberem
|
||||||
|
// la paleta temporal immediatament.
|
||||||
|
JD8_Palette pal = JD8_LoadPalette("gameover.gif");
|
||||||
|
fade_.startFadeTo(pal);
|
||||||
|
std::free(pal);
|
||||||
|
|
||||||
|
phase_ = Phase::FadingIn;
|
||||||
|
remaining_ms_ = 10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MortScene::tick(int delta_ms) {
|
||||||
|
switch (phase_) {
|
||||||
|
case Phase::FadingIn:
|
||||||
|
fade_.tick(delta_ms);
|
||||||
|
if (fade_.done()) phase_ = Phase::Showing;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Phase::Showing:
|
||||||
|
if (JI_AnyKey()) {
|
||||||
|
remaining_ms_ = 0;
|
||||||
|
} else {
|
||||||
|
remaining_ms_ -= delta_ms;
|
||||||
|
}
|
||||||
|
if (remaining_ms_ <= 0) {
|
||||||
|
// Arrenca música del següent mòdul abans del fade out,
|
||||||
|
// igual que la versió vella feia al final de doMort().
|
||||||
|
play_music("00000003.ogg");
|
||||||
|
info::ctx.num_piramide = 0;
|
||||||
|
fade_.startFadeOut();
|
||||||
|
phase_ = Phase::FadingOut;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Phase::FadingOut:
|
||||||
|
fade_.tick(delta_ms);
|
||||||
|
if (fade_.done()) phase_ = Phase::Done;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Phase::Done:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace scenes
|
||||||
36
source/scenes/mort_scene.hpp
Normal file
36
source/scenes/mort_scene.hpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "scenes/palette_fade.hpp"
|
||||||
|
#include "scenes/scene.hpp"
|
||||||
|
#include "scenes/surface_handle.hpp"
|
||||||
|
|
||||||
|
namespace scenes {
|
||||||
|
|
||||||
|
// Pantalla de "game over". Reemplaça `ModuleSequence::doMort()`.
|
||||||
|
//
|
||||||
|
// Flux:
|
||||||
|
// 1. Carrega gameover.gif, arranca música "00000001.ogg", fade-in de paleta.
|
||||||
|
// 2. Mostra la pantalla ~10 segons o fins que l'usuari polse una tecla.
|
||||||
|
// 3. Arranca música del menú ("00000003.ogg") i fade-out de paleta.
|
||||||
|
// 4. Marca num_piramide=0 i retorna nextState=1 perquè el Director
|
||||||
|
// passe a l'escena del menú.
|
||||||
|
class MortScene : public Scene {
|
||||||
|
public:
|
||||||
|
void onEnter() override;
|
||||||
|
void tick(int delta_ms) override;
|
||||||
|
bool done() const override { return phase_ == Phase::Done; }
|
||||||
|
int nextState() const override { return 1; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class Phase { FadingIn,
|
||||||
|
Showing,
|
||||||
|
FadingOut,
|
||||||
|
Done };
|
||||||
|
|
||||||
|
SurfaceHandle gfx_;
|
||||||
|
PaletteFade fade_;
|
||||||
|
Phase phase_{Phase::FadingIn};
|
||||||
|
int remaining_ms_{10000}; // 1000 ticks × 10 ms/tick del doMort original
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace scenes
|
||||||
Reference in New Issue
Block a user