tidy-fix automàtic (sense naming)
This commit is contained in:
+16
-6
@@ -1,6 +1,6 @@
|
||||
#include "game/bola.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "core/jail/jgame.hpp"
|
||||
|
||||
@@ -24,29 +24,39 @@ Bola::Bola(JD8_Surface gfx, Prota* sam)
|
||||
}
|
||||
|
||||
void Bola::draw() {
|
||||
if (this->contador == 0) Sprite::draw();
|
||||
if (this->contador == 0) {
|
||||
Sprite::draw();
|
||||
}
|
||||
}
|
||||
|
||||
void Bola::update() {
|
||||
if (this->contador == 0) {
|
||||
// Augmentem la x
|
||||
this->x++;
|
||||
if (this->x == 280) this->contador = 200;
|
||||
if (this->x == 280) {
|
||||
this->contador = 200;
|
||||
}
|
||||
|
||||
// Augmentem el frame
|
||||
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
|
||||
this->cur_frame++;
|
||||
if (this->cur_frame == entitat.animacions[this->o].frames.size()) this->cur_frame = 0;
|
||||
if (this->cur_frame == entitat.animacions[this->o].frames.size()) {
|
||||
this->cur_frame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 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) this->sam->o = 5;
|
||||
if (info::ctx.vida == 0) {
|
||||
this->sam->o = 5;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this->contador--;
|
||||
if (this->contador == 0) this->x = 20;
|
||||
if (this->contador == 0) {
|
||||
this->x = 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "game/engendro.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "core/jail/jgame.hpp"
|
||||
|
||||
@@ -29,16 +29,20 @@ Engendro::Engendro(JD8_Surface gfx, Uint16 x, Uint16 y)
|
||||
this->cycles_per_frame = 30;
|
||||
}
|
||||
|
||||
bool Engendro::update() {
|
||||
auto Engendro::update() -> bool {
|
||||
bool mort = false;
|
||||
|
||||
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
|
||||
this->cur_frame++;
|
||||
if (this->cur_frame == entitat.animacions[this->o].frames.size()) this->cur_frame = 0;
|
||||
if (this->cur_frame == entitat.animacions[this->o].frames.size()) {
|
||||
this->cur_frame = 0;
|
||||
}
|
||||
this->vida--;
|
||||
}
|
||||
|
||||
if (vida == 0) mort = true;
|
||||
if (vida == 0) {
|
||||
mort = true;
|
||||
}
|
||||
|
||||
return mort;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ class Engendro : public Sprite {
|
||||
public:
|
||||
explicit Engendro(JD8_Surface gfx, Uint16 x, Uint16 y);
|
||||
|
||||
bool update();
|
||||
auto update() -> bool;
|
||||
|
||||
protected:
|
||||
Uint8 vida;
|
||||
|
||||
+44
-25
@@ -1,6 +1,6 @@
|
||||
#include "game/mapa.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "core/jail/jgame.hpp"
|
||||
#include "core/jail/jinput.hpp"
|
||||
@@ -21,7 +21,7 @@ Mapa::Mapa(JD8_Surface gfx, Prota* sam) {
|
||||
this->nova_momia = false;
|
||||
}
|
||||
|
||||
Mapa::~Mapa(void) {
|
||||
Mapa::~Mapa() {
|
||||
JD8_FreeSurface(this->fondo);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ void Mapa::draw() {
|
||||
// Pinta tombes
|
||||
for (int y = 0; y < 4; y++) {
|
||||
for (int x = 0; x < 4; x++) {
|
||||
JD8_BlitCK(35 + (x * 65), 45 + (y * 35), this->gfx, this->tombes[x + y * 4].x, this->tombes[x + y * 4].y, 50, 20, 255);
|
||||
JD8_BlitCK(35 + (x * 65), 45 + (y * 35), this->gfx, this->tombes[x + (y * 4)].x, this->tombes[x + (y * 4)].y, 50, 20, 255);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,9 @@ void Mapa::update() {
|
||||
if (((sam->x - 20) % 65 == 0) && ((sam->y - 30) % 35 == 0) && ((this->ultim_vertex.columna != (sam->x - 20) / 65) || (this->ultim_vertex.fila != (sam->y - 30) / 35))) {
|
||||
this->vertex.columna = (sam->x - 20) / 65;
|
||||
this->vertex.fila = (sam->y - 30) / 35;
|
||||
if (this->ultim_vertex.columna != 255) this->comprovaUltimCami();
|
||||
if (this->ultim_vertex.columna != 255) {
|
||||
this->comprovaUltimCami();
|
||||
}
|
||||
this->ultim_vertex = this->vertex;
|
||||
}
|
||||
|
||||
@@ -79,7 +81,7 @@ void Mapa::update() {
|
||||
}
|
||||
}
|
||||
|
||||
bool Mapa::novaMomia() {
|
||||
auto Mapa::novaMomia() -> bool {
|
||||
bool resultat = nova_momia;
|
||||
nova_momia = false;
|
||||
return resultat;
|
||||
@@ -96,7 +98,9 @@ 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) JD8_BlitToSurface(175, 3, this->gfx, 60, 193, 7, 6, this->fondo);
|
||||
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++) {
|
||||
@@ -150,7 +154,7 @@ void Mapa::preparaFondoEstatic() {
|
||||
}
|
||||
}
|
||||
|
||||
void swap(Uint8& a, Uint8& b) {
|
||||
void swap(Uint8& a, Uint8& b) noexcept {
|
||||
Uint8 temp = a;
|
||||
a = b;
|
||||
b = temp;
|
||||
@@ -161,28 +165,36 @@ void Mapa::preparaTombes() {
|
||||
int cx = info::ctx.num_piramide == 6 ? 270 : 0;
|
||||
int cy = info::ctx.num_piramide == 6 ? 50 : 0;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
this->tombes[i].contingut = contingut;
|
||||
this->tombes[i].oberta = false;
|
||||
this->tombes[i].costat[0] = false;
|
||||
this->tombes[i].costat[1] = false;
|
||||
this->tombes[i].costat[2] = false;
|
||||
this->tombes[i].costat[3] = false;
|
||||
this->tombes[i].x = cx;
|
||||
this->tombes[i].y = cy;
|
||||
for (auto& tombe : this->tombes) {
|
||||
tombe.contingut = contingut;
|
||||
tombe.oberta = false;
|
||||
tombe.costat[0] = false;
|
||||
tombe.costat[1] = false;
|
||||
tombe.costat[2] = false;
|
||||
tombe.costat[3] = false;
|
||||
tombe.x = cx;
|
||||
tombe.y = cy;
|
||||
}
|
||||
if (info::ctx.num_piramide == 6) {
|
||||
return;
|
||||
}
|
||||
if (info::ctx.num_piramide == 6) return;
|
||||
this->tombes[0].contingut = CONTE_FARAO;
|
||||
this->tombes[1].contingut = CONTE_CLAU;
|
||||
this->tombes[2].contingut = CONTE_PERGAMI;
|
||||
this->tombes[3].contingut = CONTE_MOMIA;
|
||||
for (int i = 4; i < 8; i++) this->tombes[i].contingut = CONTE_RES;
|
||||
for (int i = 8; i < 16; i++) this->tombes[i].contingut = CONTE_TRESOR;
|
||||
for (int i = 4; i < 8; i++) {
|
||||
this->tombes[i].contingut = CONTE_RES;
|
||||
}
|
||||
for (int i = 8; i < 16; i++) {
|
||||
this->tombes[i].contingut = CONTE_TRESOR;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 50; i++) swap(this->tombes[rand() % 16].contingut, this->tombes[rand() % 16].contingut);
|
||||
for (int i = 0; i < 50; i++) {
|
||||
swap(this->tombes[rand() % 16].contingut, this->tombes[rand() % 16].contingut);
|
||||
}
|
||||
}
|
||||
|
||||
Uint8 minim(Uint8 a, Uint8 b) {
|
||||
auto minim(Uint8 a, Uint8 b) -> Uint8 {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
@@ -225,11 +237,16 @@ void Mapa::comprovaUltimCami() {
|
||||
|
||||
void Mapa::comprovaCaixa(Uint8 num) {
|
||||
// Si la tomba ja està oberta, no hi ha res que mirar
|
||||
if (this->tombes[num].oberta) return;
|
||||
if (this->tombes[num].oberta) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Si algun costat encara no està passat, no hi ha res que fer
|
||||
for (int i = 0; i < 4; i++)
|
||||
if (!this->tombes[num].costat[i]) return;
|
||||
for (bool i : this->tombes[num].costat) {
|
||||
if (!i) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Sinó, pos la acabem d'obrir
|
||||
this->tombes[num].oberta = true;
|
||||
@@ -263,7 +280,9 @@ void Mapa::comprovaCaixa(Uint8 num) {
|
||||
this->tombes[num].y = 70;
|
||||
info::ctx.diamants++;
|
||||
info::ctx.diners += VALOR_DIAMANT;
|
||||
if (info::ctx.diamants == 16) this->farao = this->clau = true;
|
||||
if (info::ctx.diamants == 16) {
|
||||
this->farao = this->clau = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+14
-12
@@ -4,14 +4,16 @@
|
||||
#include "game/info.hpp"
|
||||
#include "game/prota.hpp"
|
||||
|
||||
#define CONTE_RES 0
|
||||
#define CONTE_TRESOR 1
|
||||
#define CONTE_FARAO 2
|
||||
#define CONTE_CLAU 3
|
||||
#define CONTE_MOMIA 4
|
||||
#define CONTE_PERGAMI 5
|
||||
#define CONTE_DIAMANT 6
|
||||
#define VALOR_DIAMANT 5
|
||||
enum {
|
||||
CONTE_RES = 0,
|
||||
CONTE_TRESOR = 1,
|
||||
CONTE_FARAO = 2,
|
||||
CONTE_CLAU = 3,
|
||||
CONTE_MOMIA = 4,
|
||||
CONTE_PERGAMI = 5,
|
||||
CONTE_DIAMANT = 6,
|
||||
VALOR_DIAMANT = 5
|
||||
};
|
||||
|
||||
struct Tomba {
|
||||
bool costat[4];
|
||||
@@ -28,16 +30,16 @@ struct Vertex {
|
||||
class Mapa {
|
||||
public:
|
||||
explicit Mapa(JD8_Surface gfx, Prota* sam);
|
||||
~Mapa(void);
|
||||
~Mapa();
|
||||
|
||||
Mapa(const Mapa&) = delete;
|
||||
Mapa& operator=(const Mapa&) = delete;
|
||||
auto operator=(const Mapa&) -> Mapa& = delete;
|
||||
Mapa(Mapa&&) = delete;
|
||||
Mapa& operator=(Mapa&&) = delete;
|
||||
auto operator=(Mapa&&) -> Mapa& = delete;
|
||||
|
||||
void draw();
|
||||
void update();
|
||||
bool novaMomia();
|
||||
auto novaMomia() -> bool;
|
||||
void comprovaCaixa(Uint8 num);
|
||||
|
||||
Tomba tombes[16];
|
||||
|
||||
@@ -5,8 +5,7 @@ Marcador::Marcador(JD8_Surface gfx, Prota* sam) {
|
||||
this->sam = sam;
|
||||
}
|
||||
|
||||
Marcador::~Marcador(void) {
|
||||
}
|
||||
Marcador::~Marcador() = default;
|
||||
|
||||
void Marcador::draw() {
|
||||
if (info::ctx.num_piramide < 6) {
|
||||
@@ -18,10 +17,14 @@ void Marcador::draw() {
|
||||
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);
|
||||
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);
|
||||
if (info::ctx.vida < 5) {
|
||||
JD8_BlitCK(271, 1 + (info::ctx.vida * 3), this->gfx, 75, 20, 15, 15 - (info::ctx.vida * 3), 255);
|
||||
}
|
||||
}
|
||||
|
||||
void Marcador::pintaNumero(Uint16 x, Uint16 y, Uint8 num) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
class Marcador {
|
||||
public:
|
||||
explicit Marcador(JD8_Surface gfx, Prota* sam);
|
||||
~Marcador(void);
|
||||
~Marcador();
|
||||
|
||||
void draw();
|
||||
|
||||
|
||||
+29
-11
@@ -54,7 +54,9 @@ void ModuleGame::tick(int delta_ms) {
|
||||
// per la Draw() d'onEnter. Només el JD8_Flip del caller muta
|
||||
// pixel_data segons la paleta que avança pas a pas.
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) phase_ = Phase::Playing;
|
||||
if (fade_.done()) {
|
||||
phase_ = Phase::Playing;
|
||||
}
|
||||
break;
|
||||
|
||||
case Phase::Playing:
|
||||
@@ -75,7 +77,9 @@ void ModuleGame::tick(int delta_ms) {
|
||||
// mostraria l'estat post-Update del sprite (p.ex. el prota
|
||||
// "tornant" davant la porta després d'haver eixit).
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) phase_ = Phase::Done;
|
||||
if (fade_.done()) {
|
||||
phase_ = Phase::Done;
|
||||
}
|
||||
break;
|
||||
|
||||
case Phase::Done:
|
||||
@@ -83,8 +87,10 @@ void ModuleGame::tick(int delta_ms) {
|
||||
}
|
||||
}
|
||||
|
||||
int ModuleGame::nextState() const {
|
||||
if (JG_Quitting()) return -1;
|
||||
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) {
|
||||
@@ -93,14 +99,16 @@ int ModuleGame::nextState() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModuleGame::applyFinalTransitions() {
|
||||
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++;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -112,8 +120,12 @@ void ModuleGame::Draw() {
|
||||
this->mapa->draw();
|
||||
this->marcador->draw();
|
||||
this->sam->draw();
|
||||
for (auto& m : this->momies) m->draw();
|
||||
if (this->bola) this->bola->draw();
|
||||
for (auto& m : this->momies) {
|
||||
m->draw();
|
||||
}
|
||||
if (this->bola) {
|
||||
this->bola->draw();
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleGame::Update() {
|
||||
@@ -123,14 +135,18 @@ void ModuleGame::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);
|
||||
if (this->bola) this->bola->update();
|
||||
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++;
|
||||
}
|
||||
|
||||
if (JI_CheatActivated("reviu")) info::ctx.vida = 5;
|
||||
if (JI_CheatActivated("reviu")) {
|
||||
info::ctx.vida = 5;
|
||||
}
|
||||
if (JI_CheatActivated("alone")) {
|
||||
this->momies.clear();
|
||||
info::ctx.momies = 0;
|
||||
@@ -157,7 +173,9 @@ void ModuleGame::iniciarMomies() {
|
||||
} else {
|
||||
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;
|
||||
|
||||
@@ -32,14 +32,14 @@ class ModuleGame : public scenes::Scene {
|
||||
~ModuleGame() override;
|
||||
|
||||
ModuleGame(const ModuleGame&) = delete;
|
||||
ModuleGame& operator=(const ModuleGame&) = delete;
|
||||
auto operator=(const ModuleGame&) -> ModuleGame& = delete;
|
||||
ModuleGame(ModuleGame&&) = delete;
|
||||
ModuleGame& operator=(ModuleGame&&) = delete;
|
||||
auto operator=(ModuleGame&&) -> ModuleGame& = delete;
|
||||
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return phase_ == Phase::Done; }
|
||||
int nextState() const override;
|
||||
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
|
||||
[[nodiscard]] auto nextState() const -> int override;
|
||||
|
||||
private:
|
||||
enum class Phase {
|
||||
@@ -53,7 +53,7 @@ class ModuleGame : public scenes::Scene {
|
||||
void Update(); // gated per JG_ShouldUpdate
|
||||
|
||||
void iniciarMomies();
|
||||
void applyFinalTransitions(); // muta info::ctx quan final_ passa a !=0
|
||||
void applyFinalTransitions() const; // muta info::ctx quan final_ passa a !=0
|
||||
|
||||
Phase phase_{Phase::FadingIn};
|
||||
scenes::PaletteFade fade_;
|
||||
|
||||
+34
-18
@@ -1,6 +1,6 @@
|
||||
#include "game/momia.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "core/jail/jgame.hpp"
|
||||
|
||||
@@ -15,9 +15,13 @@ 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) f.h -= 5;
|
||||
if (info::ctx.num_piramide == 4) {
|
||||
f.h -= 5;
|
||||
}
|
||||
f.x = (col * 15) + 75;
|
||||
if (this->dimoni) f.x += 75;
|
||||
if (this->dimoni) {
|
||||
f.x += 75;
|
||||
}
|
||||
f.y = 20 + (row * 15);
|
||||
entitat.frames.push_back(f);
|
||||
}
|
||||
@@ -26,14 +30,14 @@ Momia::Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam)
|
||||
entitat.animacions.resize(4);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
entitat.animacions[i].frames = {
|
||||
static_cast<Uint8>(0 + i * 5),
|
||||
static_cast<Uint8>(1 + i * 5),
|
||||
static_cast<Uint8>(2 + i * 5),
|
||||
static_cast<Uint8>(1 + i * 5),
|
||||
static_cast<Uint8>(0 + i * 5),
|
||||
static_cast<Uint8>(3 + i * 5),
|
||||
static_cast<Uint8>(4 + i * 5),
|
||||
static_cast<Uint8>(3 + i * 5),
|
||||
static_cast<Uint8>(0 + (i * 5)),
|
||||
static_cast<Uint8>(1 + (i * 5)),
|
||||
static_cast<Uint8>(2 + (i * 5)),
|
||||
static_cast<Uint8>(1 + (i * 5)),
|
||||
static_cast<Uint8>(0 + (i * 5)),
|
||||
static_cast<Uint8>(3 + (i * 5)),
|
||||
static_cast<Uint8>(4 + (i * 5)),
|
||||
static_cast<Uint8>(3 + (i * 5)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,7 +83,7 @@ void Momia::draw() {
|
||||
}
|
||||
}
|
||||
|
||||
bool Momia::update() {
|
||||
auto Momia::update() -> bool {
|
||||
bool morta = false;
|
||||
|
||||
if (this->engendro) {
|
||||
@@ -120,22 +124,32 @@ bool Momia::update() {
|
||||
|
||||
switch (this->o) {
|
||||
case 0:
|
||||
if (y < 170) this->y++;
|
||||
if (y < 170) {
|
||||
this->y++;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (y > 30) this->y--;
|
||||
if (y > 30) {
|
||||
this->y--;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (x < 280) this->x++;
|
||||
if (x < 280) {
|
||||
this->x++;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (x > 20) this->x--;
|
||||
if (x > 20) {
|
||||
this->x--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
|
||||
this->cur_frame++;
|
||||
if (this->cur_frame == entitat.animacions[this->o].frames.size()) this->cur_frame = 0;
|
||||
if (this->cur_frame == entitat.animacions[this->o].frames.size()) {
|
||||
this->cur_frame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
@@ -144,7 +158,9 @@ bool Momia::update() {
|
||||
this->sam->pergami = false;
|
||||
} else {
|
||||
info::ctx.vida--;
|
||||
if (info::ctx.vida == 0) this->sam->o = 5;
|
||||
if (info::ctx.vida == 0) {
|
||||
this->sam->o = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class Momia : public Sprite {
|
||||
explicit Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam);
|
||||
|
||||
void draw() override;
|
||||
bool update();
|
||||
auto update() -> bool;
|
||||
|
||||
bool dimoni;
|
||||
|
||||
|
||||
+119
-55
@@ -1,5 +1,6 @@
|
||||
#include "game/options.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@@ -58,16 +59,21 @@ namespace Options {
|
||||
auto yaml = fkyaml::node::deserialize(content);
|
||||
if (yaml.contains("game")) {
|
||||
const auto& node = yaml["game"];
|
||||
if (node.contains("habitacio_inicial"))
|
||||
if (node.contains("habitacio_inicial")) {
|
||||
game.habitacio_inicial = node["habitacio_inicial"].get_value<int>();
|
||||
if (node.contains("piramide_inicial"))
|
||||
}
|
||||
if (node.contains("piramide_inicial")) {
|
||||
game.piramide_inicial = node["piramide_inicial"].get_value<int>();
|
||||
if (node.contains("vides"))
|
||||
}
|
||||
if (node.contains("vides")) {
|
||||
game.vides = node["vides"].get_value<int>();
|
||||
if (node.contains("diamants_inicial"))
|
||||
}
|
||||
if (node.contains("diamants_inicial")) {
|
||||
game.diamants_inicial = node["diamants_inicial"].get_value<int>();
|
||||
if (node.contains("diners_inicial"))
|
||||
}
|
||||
if (node.contains("diners_inicial")) {
|
||||
game.diners_inicial = node["diners_inicial"].get_value<int>();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (const fkyaml::exception& e) {
|
||||
@@ -80,7 +86,9 @@ namespace Options {
|
||||
// com a punt d'entrada únic per als callsites legacy del menú; el cos
|
||||
// ja no toca jail_audio directament.
|
||||
void applyAudio() {
|
||||
if (::Audio::get() == nullptr) return;
|
||||
if (::Audio::get() == nullptr) {
|
||||
return;
|
||||
}
|
||||
::Audio::get()->enable(audio.enabled);
|
||||
::Audio::get()->enableMusic(audio.music.enabled);
|
||||
::Audio::get()->enableSound(audio.sound.enabled);
|
||||
@@ -91,114 +99,148 @@ namespace Options {
|
||||
// --- Funcions helper de càrrega ---
|
||||
|
||||
static void loadAudioConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("audio")) return;
|
||||
if (!yaml.contains("audio")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["audio"];
|
||||
|
||||
if (node.contains("enabled"))
|
||||
if (node.contains("enabled")) {
|
||||
audio.enabled = node["enabled"].get_value<bool>();
|
||||
}
|
||||
|
||||
if (node.contains("volume"))
|
||||
if (node.contains("volume")) {
|
||||
audio.volume = node["volume"].get_value<float>();
|
||||
}
|
||||
|
||||
if (node.contains("music")) {
|
||||
const auto& music = node["music"];
|
||||
if (music.contains("enabled"))
|
||||
if (music.contains("enabled")) {
|
||||
audio.music.enabled = music["enabled"].get_value<bool>();
|
||||
if (music.contains("volume"))
|
||||
}
|
||||
if (music.contains("volume")) {
|
||||
audio.music.volume = music["volume"].get_value<float>();
|
||||
}
|
||||
}
|
||||
|
||||
if (node.contains("sound")) {
|
||||
const auto& sound = node["sound"];
|
||||
if (sound.contains("enabled"))
|
||||
if (sound.contains("enabled")) {
|
||||
audio.sound.enabled = sound["enabled"].get_value<bool>();
|
||||
if (sound.contains("volume"))
|
||||
}
|
||||
if (sound.contains("volume")) {
|
||||
audio.sound.volume = sound["volume"].get_value<float>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loadVideoConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("video")) return;
|
||||
if (!yaml.contains("video")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["video"];
|
||||
|
||||
if (node.contains("gpu_acceleration"))
|
||||
if (node.contains("gpu_acceleration")) {
|
||||
video.gpu_acceleration = node["gpu_acceleration"].get_value<bool>();
|
||||
if (node.contains("shader_enabled"))
|
||||
}
|
||||
if (node.contains("shader_enabled")) {
|
||||
video.shader_enabled = node["shader_enabled"].get_value<bool>();
|
||||
if (node.contains("supersampling"))
|
||||
}
|
||||
if (node.contains("supersampling")) {
|
||||
video.supersampling = node["supersampling"].get_value<bool>();
|
||||
}
|
||||
if (node.contains("scaling_mode")) {
|
||||
auto s = node["scaling_mode"].get_value<std::string>();
|
||||
if (s == "disabled")
|
||||
if (s == "disabled") {
|
||||
video.scaling_mode = ScalingMode::DISABLED;
|
||||
else if (s == "stretch")
|
||||
} else if (s == "stretch") {
|
||||
video.scaling_mode = ScalingMode::STRETCH;
|
||||
else if (s == "letterbox")
|
||||
} else if (s == "letterbox") {
|
||||
video.scaling_mode = ScalingMode::LETTERBOX;
|
||||
else if (s == "overscan")
|
||||
} else if (s == "overscan") {
|
||||
video.scaling_mode = ScalingMode::OVERSCAN;
|
||||
else
|
||||
} else {
|
||||
video.scaling_mode = ScalingMode::INTEGER;
|
||||
}
|
||||
}
|
||||
if (node.contains("vsync"))
|
||||
if (node.contains("vsync")) {
|
||||
video.vsync = node["vsync"].get_value<bool>();
|
||||
if (node.contains("aspect_ratio_4_3"))
|
||||
}
|
||||
if (node.contains("aspect_ratio_4_3")) {
|
||||
video.aspect_ratio_4_3 = node["aspect_ratio_4_3"].get_value<bool>();
|
||||
}
|
||||
if (node.contains("texture_filter")) {
|
||||
auto s = node["texture_filter"].get_value<std::string>();
|
||||
video.texture_filter = (s == "linear") ? TextureFilter::LINEAR : TextureFilter::NEAREST;
|
||||
}
|
||||
if (node.contains("downscale_algo"))
|
||||
if (node.contains("downscale_algo")) {
|
||||
video.downscale_algo = node["downscale_algo"].get_value<int>();
|
||||
}
|
||||
if (node.contains("internal_resolution")) {
|
||||
video.internal_resolution = node["internal_resolution"].get_value<int>();
|
||||
if (video.internal_resolution < 1) video.internal_resolution = 1;
|
||||
video.internal_resolution = std::max(video.internal_resolution, 1);
|
||||
}
|
||||
if (node.contains("current_shader"))
|
||||
if (node.contains("current_shader")) {
|
||||
video.current_shader = node["current_shader"].get_value<std::string>();
|
||||
if (node.contains("current_postfx_preset"))
|
||||
}
|
||||
if (node.contains("current_postfx_preset")) {
|
||||
video.current_postfx_preset = node["current_postfx_preset"].get_value<std::string>();
|
||||
if (node.contains("current_crtpi_preset"))
|
||||
}
|
||||
if (node.contains("current_crtpi_preset")) {
|
||||
video.current_crtpi_preset = node["current_crtpi_preset"].get_value<std::string>();
|
||||
}
|
||||
}
|
||||
|
||||
static void loadRenderInfoFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("render_info")) return;
|
||||
if (!yaml.contains("render_info")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["render_info"];
|
||||
|
||||
if (node.contains("position")) {
|
||||
auto pos = node["position"].get_value<std::string>();
|
||||
if (pos == "top")
|
||||
if (pos == "top") {
|
||||
render_info.position = RenderInfoPosition::TOP;
|
||||
else if (pos == "bottom")
|
||||
} else if (pos == "bottom") {
|
||||
render_info.position = RenderInfoPosition::BOTTOM;
|
||||
else
|
||||
} else {
|
||||
render_info.position = RenderInfoPosition::OFF;
|
||||
}
|
||||
}
|
||||
if (node.contains("show_time"))
|
||||
if (node.contains("show_time")) {
|
||||
render_info.show_time = node["show_time"].get_value<bool>();
|
||||
if (node.contains("text_color"))
|
||||
}
|
||||
if (node.contains("text_color")) {
|
||||
render_info.text_color = static_cast<Uint32>(node["text_color"].get_value<uint64_t>());
|
||||
if (node.contains("shadow_color"))
|
||||
}
|
||||
if (node.contains("shadow_color")) {
|
||||
render_info.shadow_color = static_cast<Uint32>(node["shadow_color"].get_value<uint64_t>());
|
||||
}
|
||||
}
|
||||
|
||||
static void loadWindowConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("window")) return;
|
||||
if (!yaml.contains("window")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["window"];
|
||||
|
||||
if (node.contains("zoom"))
|
||||
if (node.contains("zoom")) {
|
||||
window.zoom = node["zoom"].get_value<int>();
|
||||
if (node.contains("fullscreen"))
|
||||
}
|
||||
if (node.contains("fullscreen")) {
|
||||
window.fullscreen = node["fullscreen"].get_value<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: carrega una SDL_Scancode des d'un string (nom SDL de la tecla).
|
||||
static void loadScancodeField(const fkyaml::node& node, const std::string& key, SDL_Scancode& target) {
|
||||
if (!node.contains(key)) return;
|
||||
if (!node.contains(key)) {
|
||||
return;
|
||||
}
|
||||
auto name = node[key].get_value<std::string>();
|
||||
SDL_Scancode sc = SDL_GetScancodeFromName(name.c_str());
|
||||
if (sc != SDL_SCANCODE_UNKNOWN) target = sc;
|
||||
if (sc != SDL_SCANCODE_UNKNOWN) {
|
||||
target = sc;
|
||||
}
|
||||
}
|
||||
|
||||
static void loadControlsFromYaml(const fkyaml::node& yaml) {
|
||||
@@ -212,15 +254,20 @@ namespace Options {
|
||||
}
|
||||
|
||||
static void loadGameConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("game")) return;
|
||||
if (!yaml.contains("game")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["game"];
|
||||
|
||||
if (node.contains("use_new_logo"))
|
||||
if (node.contains("use_new_logo")) {
|
||||
game.use_new_logo = node["use_new_logo"].get_value<bool>();
|
||||
if (node.contains("show_title_credits"))
|
||||
}
|
||||
if (node.contains("show_title_credits")) {
|
||||
game.show_title_credits = node["show_title_credits"].get_value<bool>();
|
||||
if (node.contains("show_preload"))
|
||||
}
|
||||
if (node.contains("show_preload")) {
|
||||
game.show_preload = node["show_preload"].get_value<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
// Carrega les opcions des del fitxer configurat
|
||||
@@ -334,10 +381,11 @@ namespace Options {
|
||||
file << "render_info:\n";
|
||||
{
|
||||
const char* pos = "off";
|
||||
if (render_info.position == RenderInfoPosition::TOP)
|
||||
if (render_info.position == RenderInfoPosition::TOP) {
|
||||
pos = "top";
|
||||
else if (render_info.position == RenderInfoPosition::BOTTOM)
|
||||
} else if (render_info.position == RenderInfoPosition::BOTTOM) {
|
||||
pos = "bottom";
|
||||
}
|
||||
file << " position: " << pos << " # off/top/bottom\n";
|
||||
}
|
||||
file << " show_time: " << (render_info.show_time ? "true" : "false") << "\n";
|
||||
@@ -438,7 +486,9 @@ namespace Options {
|
||||
if (yaml.contains("presets")) {
|
||||
for (const auto& p : yaml["presets"]) {
|
||||
PostFXPreset preset;
|
||||
if (p.contains("name")) preset.name = p["name"].get_value<std::string>();
|
||||
if (p.contains("name")) {
|
||||
preset.name = p["name"].get_value<std::string>();
|
||||
}
|
||||
parseFloatField(p, "vignette", preset.vignette);
|
||||
parseFloatField(p, "scanlines", preset.scanlines);
|
||||
parseFloatField(p, "chroma", preset.chroma);
|
||||
@@ -497,7 +547,9 @@ namespace Options {
|
||||
if (yaml.contains("presets")) {
|
||||
for (const auto& p : yaml["presets"]) {
|
||||
CrtPiPreset preset;
|
||||
if (p.contains("name")) preset.name = p["name"].get_value<std::string>();
|
||||
if (p.contains("name")) {
|
||||
preset.name = p["name"].get_value<std::string>();
|
||||
}
|
||||
parseFloatField(p, "scanline_weight", preset.scanline_weight);
|
||||
parseFloatField(p, "scanline_gap_brightness", preset.scanline_gap_brightness);
|
||||
parseFloatField(p, "bloom_factor", preset.bloom_factor);
|
||||
@@ -506,24 +558,36 @@ namespace Options {
|
||||
parseFloatField(p, "mask_brightness", preset.mask_brightness);
|
||||
parseFloatField(p, "curvature_x", preset.curvature_x);
|
||||
parseFloatField(p, "curvature_y", preset.curvature_y);
|
||||
if (p.contains("mask_type")) try {
|
||||
if (p.contains("mask_type")) {
|
||||
try {
|
||||
preset.mask_type = p["mask_type"].get_value<int>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_scanlines")) try {
|
||||
}
|
||||
if (p.contains("enable_scanlines")) {
|
||||
try {
|
||||
preset.enable_scanlines = p["enable_scanlines"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_multisample")) try {
|
||||
}
|
||||
if (p.contains("enable_multisample")) {
|
||||
try {
|
||||
preset.enable_multisample = p["enable_multisample"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_gamma")) try {
|
||||
}
|
||||
if (p.contains("enable_gamma")) {
|
||||
try {
|
||||
preset.enable_gamma = p["enable_gamma"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_curvature")) try {
|
||||
}
|
||||
if (p.contains("enable_curvature")) {
|
||||
try {
|
||||
preset.enable_curvature = p["enable_curvature"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_sharper")) try {
|
||||
}
|
||||
if (p.contains("enable_sharper")) {
|
||||
try {
|
||||
preset.enable_sharper = p["enable_sharper"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
crtpi_presets.push_back(preset);
|
||||
}
|
||||
}
|
||||
|
||||
+59
-27
@@ -1,6 +1,6 @@
|
||||
#include "game/prota.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "core/jail/jgame.hpp"
|
||||
#include "core/jail/jinput.hpp"
|
||||
@@ -14,7 +14,9 @@ Prota::Prota(JD8_Surface gfx)
|
||||
Frame f;
|
||||
f.w = 15;
|
||||
f.h = 15;
|
||||
if (info::ctx.num_piramide == 4) f.h -= 5;
|
||||
if (info::ctx.num_piramide == 4) {
|
||||
f.h -= 5;
|
||||
}
|
||||
f.x = x * 15;
|
||||
f.y = 20 + (y * 15);
|
||||
entitat.frames.push_back(f);
|
||||
@@ -26,7 +28,9 @@ Prota::Prota(JD8_Surface gfx)
|
||||
Frame f;
|
||||
f.w = 15;
|
||||
f.h = 30;
|
||||
if (info::ctx.num_piramide == 4) f.h -= 5;
|
||||
if (info::ctx.num_piramide == 4) {
|
||||
f.h -= 5;
|
||||
}
|
||||
f.x = x;
|
||||
f.y = y;
|
||||
entitat.frames.push_back(f);
|
||||
@@ -38,7 +42,9 @@ Prota::Prota(JD8_Surface gfx)
|
||||
Frame f;
|
||||
f.w = 15;
|
||||
f.h = 15;
|
||||
if (info::ctx.num_piramide == 4) f.h -= 5;
|
||||
if (info::ctx.num_piramide == 4) {
|
||||
f.h -= 5;
|
||||
}
|
||||
f.x = x;
|
||||
f.y = y;
|
||||
entitat.frames.push_back(f);
|
||||
@@ -48,23 +54,29 @@ Prota::Prota(JD8_Surface gfx)
|
||||
entitat.animacions.resize(6);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
entitat.animacions[i].frames = {
|
||||
static_cast<Uint8>(0 + i * 5),
|
||||
static_cast<Uint8>(1 + i * 5),
|
||||
static_cast<Uint8>(2 + i * 5),
|
||||
static_cast<Uint8>(1 + i * 5),
|
||||
static_cast<Uint8>(0 + i * 5),
|
||||
static_cast<Uint8>(3 + i * 5),
|
||||
static_cast<Uint8>(4 + i * 5),
|
||||
static_cast<Uint8>(3 + i * 5),
|
||||
static_cast<Uint8>(0 + (i * 5)),
|
||||
static_cast<Uint8>(1 + (i * 5)),
|
||||
static_cast<Uint8>(2 + (i * 5)),
|
||||
static_cast<Uint8>(1 + (i * 5)),
|
||||
static_cast<Uint8>(0 + (i * 5)),
|
||||
static_cast<Uint8>(3 + (i * 5)),
|
||||
static_cast<Uint8>(4 + (i * 5)),
|
||||
static_cast<Uint8>(3 + (i * 5)),
|
||||
};
|
||||
}
|
||||
|
||||
entitat.animacions[4].frames.resize(50);
|
||||
for (int i = 0; i < 50; i++) entitat.animacions[4].frames[i] = i + 20;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
entitat.animacions[4].frames[i] = i + 20;
|
||||
}
|
||||
|
||||
entitat.animacions[5].frames.resize(48);
|
||||
for (int i = 0; i < 12; i++) entitat.animacions[5].frames[i] = i + 70;
|
||||
for (int i = 12; i < 48; i++) entitat.animacions[5].frames[i] = 81;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
entitat.animacions[5].frames[i] = i + 70;
|
||||
}
|
||||
for (int i = 12; i < 48; i++) {
|
||||
entitat.animacions[5].frames[i] = 81;
|
||||
}
|
||||
|
||||
cur_frame = 0;
|
||||
x = 150;
|
||||
@@ -87,40 +99,56 @@ void Prota::draw() {
|
||||
}
|
||||
}
|
||||
|
||||
Uint8 Prota::update() {
|
||||
auto Prota::update() -> Uint8 {
|
||||
Uint8 eixir = 0;
|
||||
|
||||
if (this->o < 4) {
|
||||
Uint8 dir = 4;
|
||||
if (JI_KeyPressed(SDL_SCANCODE_DOWN)) {
|
||||
if ((this->x - 20) % 65 == 0) this->o = 0;
|
||||
if ((this->x - 20) % 65 == 0) {
|
||||
this->o = 0;
|
||||
}
|
||||
dir = this->o;
|
||||
}
|
||||
if (JI_KeyPressed(SDL_SCANCODE_UP)) {
|
||||
if ((this->x - 20) % 65 == 0) this->o = 1;
|
||||
if ((this->x - 20) % 65 == 0) {
|
||||
this->o = 1;
|
||||
}
|
||||
dir = this->o;
|
||||
}
|
||||
if (JI_KeyPressed(SDL_SCANCODE_RIGHT)) {
|
||||
if ((this->y - 30) % 35 == 0) this->o = 2;
|
||||
if ((this->y - 30) % 35 == 0) {
|
||||
this->o = 2;
|
||||
}
|
||||
dir = this->o;
|
||||
}
|
||||
if (JI_KeyPressed(SDL_SCANCODE_LEFT)) {
|
||||
if ((this->y - 30) % 35 == 0) this->o = 3;
|
||||
if ((this->y - 30) % 35 == 0) {
|
||||
this->o = 3;
|
||||
}
|
||||
dir = this->o;
|
||||
}
|
||||
|
||||
switch (dir) {
|
||||
case 0:
|
||||
if (this->y < 170) this->y++;
|
||||
if (this->y < 170) {
|
||||
this->y++;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (this->y > 30) this->y--;
|
||||
if (this->y > 30) {
|
||||
this->y--;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (this->x < 280) this->x++;
|
||||
if (this->x < 280) {
|
||||
this->x++;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (this->x > 20) this->x--;
|
||||
if (this->x > 20) {
|
||||
this->x--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -128,13 +156,17 @@ Uint8 Prota::update() {
|
||||
this->cur_frame = 0;
|
||||
} else {
|
||||
this->frame_pejades++;
|
||||
if (this->frame_pejades == 15) this->frame_pejades = 0;
|
||||
if (this->frame_pejades == 15) {
|
||||
this->frame_pejades = 0;
|
||||
}
|
||||
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
|
||||
this->cur_frame++;
|
||||
if (this->cur_frame == entitat.animacions[this->o].frames.size()) this->cur_frame = 0;
|
||||
if (this->cur_frame == entitat.animacions[this->o].frames.size()) {
|
||||
this->cur_frame = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
eixir = false;
|
||||
eixir = 0u;
|
||||
} else {
|
||||
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
|
||||
this->cur_frame++;
|
||||
|
||||
@@ -8,7 +8,7 @@ class Prota : public Sprite {
|
||||
explicit Prota(JD8_Surface gfx);
|
||||
|
||||
void draw() override;
|
||||
Uint8 update();
|
||||
auto update() -> Uint8;
|
||||
|
||||
Uint8 frame_pejades;
|
||||
bool pergami;
|
||||
|
||||
@@ -42,7 +42,9 @@ namespace scenes {
|
||||
switch (phase_) {
|
||||
case Phase::FadingIn:
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) phase_ = Phase::Showing;
|
||||
if (fade_.done()) {
|
||||
phase_ = Phase::Showing;
|
||||
}
|
||||
break;
|
||||
|
||||
case Phase::Showing:
|
||||
@@ -60,7 +62,9 @@ namespace scenes {
|
||||
|
||||
case Phase::FadingOut:
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) phase_ = Phase::Done;
|
||||
if (fade_.done()) {
|
||||
phase_ = Phase::Done;
|
||||
}
|
||||
break;
|
||||
|
||||
case Phase::Done:
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace scenes {
|
||||
public:
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return phase_ == Phase::Done; }
|
||||
int nextState() const override { return 0; }
|
||||
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
|
||||
[[nodiscard]] auto nextState() const -> int override { return 0; }
|
||||
|
||||
private:
|
||||
enum class Phase { FadingIn,
|
||||
|
||||
@@ -35,10 +35,12 @@ namespace scenes {
|
||||
render();
|
||||
}
|
||||
|
||||
void BootLoaderScene::render() const {
|
||||
void BootLoaderScene::render() {
|
||||
JD8_ClearScreen(BG_COLOR);
|
||||
|
||||
if (!Options::game.show_preload) return;
|
||||
if (!Options::game.show_preload) {
|
||||
return;
|
||||
}
|
||||
|
||||
const float pct = Resource::Cache::get()->getProgress();
|
||||
const int filled = static_cast<int>(static_cast<float>(BAR_W) * pct);
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace scenes {
|
||||
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return done_; }
|
||||
[[nodiscard]] auto done() const -> bool override { return done_; }
|
||||
|
||||
private:
|
||||
void render() const;
|
||||
static void render();
|
||||
|
||||
bool done_{false};
|
||||
};
|
||||
|
||||
@@ -18,14 +18,14 @@ namespace {
|
||||
};
|
||||
|
||||
constexpr CocheFrame COCHE_FRAMES[8] = {
|
||||
{214, 152},
|
||||
{214, 104},
|
||||
{214, 56},
|
||||
{214, 104},
|
||||
{214, 152},
|
||||
{214, 8},
|
||||
{108, 152},
|
||||
{214, 8},
|
||||
{.x = 214, .y = 152},
|
||||
{.x = 214, .y = 104},
|
||||
{.x = 214, .y = 56},
|
||||
{.x = 214, .y = 104},
|
||||
{.x = 214, .y = 152},
|
||||
{.x = 214, .y = 8},
|
||||
{.x = 108, .y = 152},
|
||||
{.x = 214, .y = 8},
|
||||
};
|
||||
|
||||
constexpr int CONTADOR_MAX = 3100; // ~62 s de crèdits a 20 ms/tick
|
||||
@@ -101,7 +101,7 @@ namespace scenes {
|
||||
|
||||
void CreditsScene::writeTrickIni() {
|
||||
FILE* ini = std::fopen("trick.ini", "wb");
|
||||
if (ini) {
|
||||
if (ini != nullptr) {
|
||||
std::fwrite("1", 1, 1, ini);
|
||||
std::fclose(ini);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace scenes {
|
||||
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return phase_ == Phase::Done; }
|
||||
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
|
||||
|
||||
private:
|
||||
enum class Phase { Rolling,
|
||||
@@ -36,7 +36,7 @@ namespace scenes {
|
||||
Done };
|
||||
|
||||
void render();
|
||||
void writeTrickIni();
|
||||
static void writeTrickIni();
|
||||
|
||||
SurfaceHandle vaddr2_; // gfx/final.gif (sprites i coches)
|
||||
SurfaceHandle vaddr3_; // gfx/finals.gif (fons / parallax)
|
||||
|
||||
@@ -10,7 +10,9 @@ namespace scenes {
|
||||
loop_(loop) {}
|
||||
|
||||
void FrameAnimator::tick(int delta_ms) {
|
||||
if (finished_) return;
|
||||
if (finished_) {
|
||||
return;
|
||||
}
|
||||
elapsed_ms_ += delta_ms;
|
||||
while (elapsed_ms_ >= frame_ms_) {
|
||||
elapsed_ms_ -= frame_ms_;
|
||||
|
||||
@@ -15,9 +15,9 @@ namespace scenes {
|
||||
|
||||
void tick(int delta_ms);
|
||||
|
||||
int frame() const { return current_frame_; }
|
||||
bool done() const { return !loop_ && finished_; }
|
||||
int numFrames() const { return num_frames_; }
|
||||
[[nodiscard]] auto frame() const -> int { return current_frame_; }
|
||||
[[nodiscard]] auto done() const -> bool { return !loop_ && finished_; }
|
||||
[[nodiscard]] auto numFrames() const -> int { return num_frames_; }
|
||||
|
||||
void reset();
|
||||
void setFrameMs(int frame_ms) { frame_ms_ = frame_ms; }
|
||||
|
||||
@@ -108,14 +108,28 @@ namespace scenes {
|
||||
// els índexs 16..31 (grup del verd brillant del logo).
|
||||
for (int i = 16; i < 32; i++) {
|
||||
if (i == 17) {
|
||||
if (pal_[i].r < 255) pal_[i].r++;
|
||||
if (pal_[i].g < 255) pal_[i].g++;
|
||||
if (pal_[i].b < 255) pal_[i].b++;
|
||||
if (pal_[i].r < 255) {
|
||||
pal_[i].r++;
|
||||
}
|
||||
if (pal_[i].g < 255) {
|
||||
pal_[i].g++;
|
||||
}
|
||||
if (pal_[i].b < 255) {
|
||||
pal_[i].b++;
|
||||
}
|
||||
}
|
||||
if (pal_[i].b < pal_[i].g) {
|
||||
pal_[i].b++;
|
||||
}
|
||||
if (pal_[i].b > pal_[i].g) {
|
||||
pal_[i].b--;
|
||||
}
|
||||
if (pal_[i].r < pal_[i].g) {
|
||||
pal_[i].r++;
|
||||
}
|
||||
if (pal_[i].r > pal_[i].g) {
|
||||
pal_[i].r--;
|
||||
}
|
||||
if (pal_[i].b < pal_[i].g) pal_[i].b++;
|
||||
if (pal_[i].b > pal_[i].g) pal_[i].b--;
|
||||
if (pal_[i].r < pal_[i].g) pal_[i].r++;
|
||||
if (pal_[i].r > pal_[i].g) pal_[i].r--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace scenes {
|
||||
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return phase_ == Phase::Done; }
|
||||
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
|
||||
|
||||
private:
|
||||
enum class Phase {
|
||||
|
||||
@@ -27,21 +27,21 @@ namespace {
|
||||
};
|
||||
|
||||
constexpr RevealStep REVEAL_STEPS[] = {
|
||||
{100, 27, 68, false, false}, // J
|
||||
{100, 53, 96, false, false}, // JA
|
||||
{100, 66, 109, false, false}, // JAI
|
||||
{200, 92, 136, false, false}, // JAIL
|
||||
{200, 92, -1, true, false}, // JAIL (clear, sense avió — parpelleig)
|
||||
{100, 118, 160, false, false}, // JAILG
|
||||
{100, 145, 188, false, false}, // JAILGA
|
||||
{100, 178, 221, false, false}, // JAILGAM
|
||||
{100, 205, 248, false, false}, // JAILGAME
|
||||
{200, 0, 274, false, true}, // JAILGAMES (wordmark complet) + avió
|
||||
{200, 0, -1, true, true}, // JAILGAMES (clear, sense avió)
|
||||
{200, 0, 274, false, true}, // JAILGAMES + avió (sense clear)
|
||||
{200, 0, -1, true, true}, // JAILGAMES (clear, sense avió)
|
||||
{200, 0, 274, false, true}, // JAILGAMES + avió (sense clear)
|
||||
{200, 0, -1, true, true}, // JAILGAMES (clear, sense avió)
|
||||
{.duration_ms = 100, .body_w = 27, .plane_x = 68, .clear = false, .wordmark = false}, // J
|
||||
{.duration_ms = 100, .body_w = 53, .plane_x = 96, .clear = false, .wordmark = false}, // JA
|
||||
{.duration_ms = 100, .body_w = 66, .plane_x = 109, .clear = false, .wordmark = false}, // JAI
|
||||
{.duration_ms = 200, .body_w = 92, .plane_x = 136, .clear = false, .wordmark = false}, // JAIL
|
||||
{.duration_ms = 200, .body_w = 92, .plane_x = -1, .clear = true, .wordmark = false}, // JAIL (clear, sense avió — parpelleig)
|
||||
{.duration_ms = 100, .body_w = 118, .plane_x = 160, .clear = false, .wordmark = false}, // JAILG
|
||||
{.duration_ms = 100, .body_w = 145, .plane_x = 188, .clear = false, .wordmark = false}, // JAILGA
|
||||
{.duration_ms = 100, .body_w = 178, .plane_x = 221, .clear = false, .wordmark = false}, // JAILGAM
|
||||
{.duration_ms = 100, .body_w = 205, .plane_x = 248, .clear = false, .wordmark = false}, // JAILGAME
|
||||
{.duration_ms = 200, .body_w = 0, .plane_x = 274, .clear = false, .wordmark = true}, // JAILGAMES (wordmark complet) + avió
|
||||
{.duration_ms = 200, .body_w = 0, .plane_x = -1, .clear = true, .wordmark = true}, // JAILGAMES (clear, sense avió)
|
||||
{.duration_ms = 200, .body_w = 0, .plane_x = 274, .clear = false, .wordmark = true}, // JAILGAMES + avió (sense clear)
|
||||
{.duration_ms = 200, .body_w = 0, .plane_x = -1, .clear = true, .wordmark = true}, // JAILGAMES (clear, sense avió)
|
||||
{.duration_ms = 200, .body_w = 0, .plane_x = 274, .clear = false, .wordmark = true}, // JAILGAMES + avió (sense clear)
|
||||
{.duration_ms = 200, .body_w = 0, .plane_x = -1, .clear = true, .wordmark = true}, // JAILGAMES (clear, sense avió)
|
||||
};
|
||||
constexpr int REVEAL_COUNT = sizeof(REVEAL_STEPS) / sizeof(REVEAL_STEPS[0]);
|
||||
|
||||
@@ -88,7 +88,9 @@ namespace scenes {
|
||||
|
||||
case Phase::Reveal: {
|
||||
const RevealStep& s = REVEAL_STEPS[reveal_index_];
|
||||
if (s.clear) JD8_ClearScreen(0);
|
||||
if (s.clear) {
|
||||
JD8_ClearScreen(0);
|
||||
}
|
||||
if (s.wordmark) {
|
||||
drawWordmark(gfx_);
|
||||
} else if (s.body_w > 0) {
|
||||
@@ -121,14 +123,28 @@ namespace scenes {
|
||||
// els altres convergeixen cap al mateix gris mitjà.
|
||||
for (int i = 16; i < 32; i++) {
|
||||
if (i == 17) {
|
||||
if (pal_[i].r < 255) pal_[i].r++;
|
||||
if (pal_[i].g < 255) pal_[i].g++;
|
||||
if (pal_[i].b < 255) pal_[i].b++;
|
||||
if (pal_[i].r < 255) {
|
||||
pal_[i].r++;
|
||||
}
|
||||
if (pal_[i].g < 255) {
|
||||
pal_[i].g++;
|
||||
}
|
||||
if (pal_[i].b < 255) {
|
||||
pal_[i].b++;
|
||||
}
|
||||
}
|
||||
if (pal_[i].b < pal_[i].g) {
|
||||
pal_[i].b++;
|
||||
}
|
||||
if (pal_[i].b > pal_[i].g) {
|
||||
pal_[i].b--;
|
||||
}
|
||||
if (pal_[i].r < pal_[i].g) {
|
||||
pal_[i].r++;
|
||||
}
|
||||
if (pal_[i].r > pal_[i].g) {
|
||||
pal_[i].r--;
|
||||
}
|
||||
if (pal_[i].b < pal_[i].g) pal_[i].b++;
|
||||
if (pal_[i].b > pal_[i].g) pal_[i].b--;
|
||||
if (pal_[i].r < pal_[i].g) pal_[i].r++;
|
||||
if (pal_[i].r > pal_[i].g) pal_[i].r--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace scenes {
|
||||
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return phase_ == Phase::Done; }
|
||||
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
|
||||
|
||||
private:
|
||||
enum class Phase {
|
||||
|
||||
@@ -146,17 +146,17 @@ namespace {
|
||||
}
|
||||
|
||||
constexpr SpritePhase variant_0[] = {
|
||||
{0, 200, v0_walk_right, true},
|
||||
{0, 200, v0_pull_map_right, true},
|
||||
{200, 0, v0_pull_map_right, true}, // guarda el mapa (reprodueix inversament)
|
||||
{200, 80, v0_walk_left_to_80, true},
|
||||
{0, 200, v0_pull_map_left, true},
|
||||
{300, 95, v0_momia_left, true},
|
||||
{0, 50, v0_turn, true},
|
||||
{0, 49, v0_jump1, true},
|
||||
{50, 99, v0_jump2, true},
|
||||
{80, 0, v0_walk_final, true},
|
||||
{0, 150, v0_final, true},
|
||||
{.start_i = 0, .end_i = 200, .render = v0_walk_right, .skippable = true},
|
||||
{.start_i = 0, .end_i = 200, .render = v0_pull_map_right, .skippable = true},
|
||||
{.start_i = 200, .end_i = 0, .render = v0_pull_map_right, .skippable = true}, // guarda el mapa (reprodueix inversament)
|
||||
{.start_i = 200, .end_i = 80, .render = v0_walk_left_to_80, .skippable = true},
|
||||
{.start_i = 0, .end_i = 200, .render = v0_pull_map_left, .skippable = true},
|
||||
{.start_i = 300, .end_i = 95, .render = v0_momia_left, .skippable = true},
|
||||
{.start_i = 0, .end_i = 50, .render = v0_turn, .skippable = true},
|
||||
{.start_i = 0, .end_i = 49, .render = v0_jump1, .skippable = true},
|
||||
{.start_i = 50, .end_i = 99, .render = v0_jump2, .skippable = true},
|
||||
{.start_i = 80, .end_i = 0, .render = v0_walk_final, .skippable = true},
|
||||
{.start_i = 0, .end_i = 150, .render = v0_final, .skippable = true},
|
||||
};
|
||||
|
||||
// =========================================================================
|
||||
@@ -224,13 +224,13 @@ namespace {
|
||||
}
|
||||
|
||||
constexpr SpritePhase variant_1[] = {
|
||||
{0, 200, v1_walk_right, true},
|
||||
{0, 300, v1_pull_map, true},
|
||||
{0, 100, v1_interrogant, true},
|
||||
{0, 200, v1_drop_map, true},
|
||||
{0, 75, v1_stone_fall, true},
|
||||
{0, 19, v1_stone_break, true},
|
||||
{0, 200, v1_final, true},
|
||||
{.start_i = 0, .end_i = 200, .render = v1_walk_right, .skippable = true},
|
||||
{.start_i = 0, .end_i = 300, .render = v1_pull_map, .skippable = true},
|
||||
{.start_i = 0, .end_i = 100, .render = v1_interrogant, .skippable = true},
|
||||
{.start_i = 0, .end_i = 200, .render = v1_drop_map, .skippable = true},
|
||||
{.start_i = 0, .end_i = 75, .render = v1_stone_fall, .skippable = true},
|
||||
{.start_i = 0, .end_i = 19, .render = v1_stone_break, .skippable = true},
|
||||
{.start_i = 0, .end_i = 200, .render = v1_final, .skippable = true},
|
||||
};
|
||||
|
||||
// =========================================================================
|
||||
@@ -268,17 +268,17 @@ namespace {
|
||||
}
|
||||
|
||||
constexpr SpritePhase variant_2[] = {
|
||||
{0, 145, v2_approach, true},
|
||||
{0, 100, v2_still, true},
|
||||
{0, 50, v2_horn, true},
|
||||
{0, 800, v2_ball, true},
|
||||
{.start_i = 0, .end_i = 145, .render = v2_approach, .skippable = true},
|
||||
{.start_i = 0, .end_i = 100, .render = v2_still, .skippable = true},
|
||||
{.start_i = 0, .end_i = 50, .render = v2_horn, .skippable = true},
|
||||
{.start_i = 0, .end_i = 800, .render = v2_ball, .skippable = true},
|
||||
};
|
||||
|
||||
// =========================================================================
|
||||
// Dispatch per variant
|
||||
// =========================================================================
|
||||
|
||||
const SpritePhase* variant_table(int variant) {
|
||||
auto variant_table(int variant) -> const SpritePhase* {
|
||||
switch (variant) {
|
||||
case 0:
|
||||
return variant_0;
|
||||
@@ -290,7 +290,7 @@ namespace {
|
||||
return variant_0;
|
||||
}
|
||||
|
||||
int variant_length(int variant) {
|
||||
auto variant_length(int variant) -> int {
|
||||
switch (variant) {
|
||||
case 0:
|
||||
return sizeof(variant_0) / sizeof(variant_0[0]);
|
||||
@@ -302,11 +302,11 @@ namespace {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int phase_step_count(const SpritePhase& p) {
|
||||
auto phase_step_count(const SpritePhase& p) -> int {
|
||||
return std::abs(p.end_i - p.start_i) + 1;
|
||||
}
|
||||
|
||||
int phase_current_i(const SpritePhase& p, int step) {
|
||||
auto phase_current_i(const SpritePhase& p, int step) -> int {
|
||||
return p.end_i >= p.start_i ? p.start_i + step : p.start_i - step;
|
||||
}
|
||||
|
||||
@@ -334,7 +334,9 @@ namespace scenes {
|
||||
}
|
||||
|
||||
void IntroSpritesScene::tick(int delta_ms) {
|
||||
if (done_) return;
|
||||
if (done_) {
|
||||
return;
|
||||
}
|
||||
|
||||
const SpritePhase* phases = variant_table(variant_);
|
||||
const int num_phases = variant_length(variant_);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace scenes {
|
||||
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return done_; }
|
||||
[[nodiscard]] auto done() const -> bool override { return done_; }
|
||||
|
||||
private:
|
||||
SurfaceHandle gfx_;
|
||||
|
||||
@@ -62,7 +62,9 @@ namespace scenes {
|
||||
switch (phase_) {
|
||||
case Phase::FadingIn:
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) phase_ = Phase::Showing;
|
||||
if (fade_.done()) {
|
||||
phase_ = Phase::Showing;
|
||||
}
|
||||
break;
|
||||
|
||||
case Phase::Showing: {
|
||||
@@ -70,20 +72,26 @@ namespace scenes {
|
||||
palmeres_acc_ms_ += delta_ms;
|
||||
while (palmeres_acc_ms_ >= 80) {
|
||||
palmeres_acc_ms_ -= 80;
|
||||
if (--palmeres_ < 0) palmeres_ = 319;
|
||||
if (--palmeres_ < 0) {
|
||||
palmeres_ = 319;
|
||||
}
|
||||
}
|
||||
|
||||
// Horitzó: 1 pixel cada 320 ms (= cada 16 ticks × 20 ms)
|
||||
horitzo_acc_ms_ += delta_ms;
|
||||
while (horitzo_acc_ms_ >= 320) {
|
||||
horitzo_acc_ms_ -= 320;
|
||||
if (--horitzo_ < 0) horitzo_ = 319;
|
||||
if (--horitzo_ < 0) {
|
||||
horitzo_ = 319;
|
||||
}
|
||||
}
|
||||
|
||||
camello_.tick(delta_ms);
|
||||
|
||||
blink_ms_ += delta_ms;
|
||||
if (blink_ms_ >= 2000) blink_ms_ %= 2000;
|
||||
if (blink_ms_ >= 2000) {
|
||||
blink_ms_ %= 2000;
|
||||
}
|
||||
|
||||
render();
|
||||
|
||||
@@ -102,7 +110,9 @@ namespace scenes {
|
||||
|
||||
case Phase::FadingOut:
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) phase_ = Phase::Done;
|
||||
if (fade_.done()) {
|
||||
phase_ = Phase::Done;
|
||||
}
|
||||
break;
|
||||
|
||||
case Phase::Done:
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace scenes {
|
||||
public:
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return phase_ == Phase::Done; }
|
||||
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
|
||||
|
||||
private:
|
||||
enum class Phase { FadingIn,
|
||||
|
||||
@@ -32,7 +32,9 @@ namespace scenes {
|
||||
switch (phase_) {
|
||||
case Phase::FadingIn:
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) phase_ = Phase::Showing;
|
||||
if (fade_.done()) {
|
||||
phase_ = Phase::Showing;
|
||||
}
|
||||
break;
|
||||
|
||||
case Phase::Showing:
|
||||
@@ -53,7 +55,9 @@ namespace scenes {
|
||||
|
||||
case Phase::FadingOut:
|
||||
fade_.tick(delta_ms);
|
||||
if (fade_.done()) phase_ = Phase::Done;
|
||||
if (fade_.done()) {
|
||||
phase_ = Phase::Done;
|
||||
}
|
||||
break;
|
||||
|
||||
case Phase::Done:
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace scenes {
|
||||
public:
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return phase_ == Phase::Done; }
|
||||
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
|
||||
|
||||
private:
|
||||
enum class Phase { FadingIn,
|
||||
|
||||
@@ -13,7 +13,9 @@ namespace scenes {
|
||||
}
|
||||
|
||||
void PaletteFade::tick(int /*delta_ms*/) {
|
||||
if (!active_) return;
|
||||
if (!active_) {
|
||||
return;
|
||||
}
|
||||
// El fade té 32 passos interns. Amb un tick per frame (~16ms)
|
||||
// dura ~512ms — el mateix temps que la versió bloquejant original.
|
||||
// Si en el futur volem fer-lo genuinament time-based (p.ex. "fade
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace scenes {
|
||||
|
||||
void tick(int delta_ms);
|
||||
|
||||
bool active() const { return active_; }
|
||||
bool done() const { return !active_; }
|
||||
[[nodiscard]] auto active() const -> bool { return active_; }
|
||||
[[nodiscard]] auto done() const -> bool { return !active_; }
|
||||
|
||||
private:
|
||||
bool active_{false};
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace scenes {
|
||||
|
||||
virtual void tick(int delta_ms) = 0;
|
||||
|
||||
virtual bool done() const = 0;
|
||||
[[nodiscard]] virtual auto done() const -> bool = 0;
|
||||
|
||||
// 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
|
||||
// 0 = entrar al gameplay (ModuleGame)
|
||||
// -1 = eixir del joc
|
||||
virtual int nextState() const { return 1; }
|
||||
[[nodiscard]] virtual auto nextState() const -> int { return 1; }
|
||||
};
|
||||
|
||||
} // namespace scenes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace scenes {
|
||||
|
||||
SceneRegistry& SceneRegistry::instance() {
|
||||
auto SceneRegistry::instance() -> SceneRegistry& {
|
||||
static SceneRegistry inst;
|
||||
return inst;
|
||||
}
|
||||
@@ -11,9 +11,11 @@ namespace scenes {
|
||||
factories_[state_key] = std::move(factory);
|
||||
}
|
||||
|
||||
std::unique_ptr<Scene> SceneRegistry::tryCreate(int state_key) const {
|
||||
auto SceneRegistry::tryCreate(int state_key) const -> std::unique_ptr<Scene> {
|
||||
const auto it = factories_.find(state_key);
|
||||
if (it == factories_.end()) return nullptr;
|
||||
if (it == factories_.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return it->second();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ namespace scenes {
|
||||
public:
|
||||
using Factory = std::function<std::unique_ptr<Scene>()>;
|
||||
|
||||
static SceneRegistry& instance();
|
||||
static auto instance() -> SceneRegistry&;
|
||||
|
||||
void registerScene(int state_key, Factory factory);
|
||||
|
||||
// Retorna `nullptr` si no hi ha cap escena registrada per a aquest
|
||||
// state. El caller hauria de caure al path legacy en aquest cas.
|
||||
std::unique_ptr<Scene> tryCreate(int state_key) const;
|
||||
auto tryCreate(int state_key) const -> std::unique_ptr<Scene>;
|
||||
|
||||
private:
|
||||
SceneRegistry() = default;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace scenes {
|
||||
|
||||
namespace {
|
||||
std::string basename(const char* path) {
|
||||
auto basename(const char* path) -> std::string {
|
||||
std::string s = path;
|
||||
auto pos = s.find_last_of("/\\");
|
||||
return pos == std::string::npos ? s : s.substr(pos + 1);
|
||||
@@ -15,7 +15,9 @@ namespace scenes {
|
||||
} // namespace
|
||||
|
||||
void playMusic(const char* filename, int loop) {
|
||||
if (!filename) return;
|
||||
if (filename == nullptr) {
|
||||
return;
|
||||
}
|
||||
Audio::get()->playMusic(basename(filename), loop);
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace scenes {
|
||||
|
||||
case Phase::Tomba1ScrollIn: {
|
||||
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);
|
||||
@@ -130,7 +130,7 @@ namespace scenes {
|
||||
|
||||
case Phase::Tomba2ScrollIn: {
|
||||
phase_acc_ms_ += delta_ms;
|
||||
const int contador = std::min(94, phase_acc_ms_ / TICK_MS + 1);
|
||||
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::Tomba2Hold;
|
||||
@@ -150,7 +150,7 @@ namespace scenes {
|
||||
|
||||
case Phase::Tomba2Reveal: {
|
||||
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);
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace scenes {
|
||||
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return phase_ == Phase::Done; }
|
||||
int nextState() const override { return 0; }
|
||||
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
|
||||
[[nodiscard]] auto nextState() const -> int override { return 0; }
|
||||
|
||||
private:
|
||||
enum class Phase {
|
||||
@@ -50,7 +50,7 @@ namespace scenes {
|
||||
};
|
||||
|
||||
void swapToTomba2();
|
||||
void beginRedPulseSetup();
|
||||
static void beginRedPulseSetup();
|
||||
void beginFinalFade();
|
||||
|
||||
SurfaceHandle gfx_;
|
||||
|
||||
@@ -105,7 +105,9 @@ namespace scenes {
|
||||
// el final natural crida JA_FadeOutMusic (beginFinalFade() distingeix).
|
||||
if (!skip_triggered_ && JI_AnyKey()) {
|
||||
skip_triggered_ = true;
|
||||
if (num_piramide_at_start_ != 7) Audio::get()->fadeOutMusic(250);
|
||||
if (num_piramide_at_start_ != 7) {
|
||||
Audio::get()->fadeOutMusic(250);
|
||||
}
|
||||
fade_.startFadeOut();
|
||||
phase_ = Phase::FadeFinal;
|
||||
}
|
||||
@@ -118,7 +120,7 @@ namespace scenes {
|
||||
const int slide_idx = (phase_ == Phase::Slide1Enter ? 0
|
||||
: phase_ == Phase::Slide2Enter ? 1
|
||||
: 2);
|
||||
const float t = std::min(1.0f, static_cast<float>(phase_acc_ms_) / static_cast<float>(SCROLL_MS));
|
||||
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);
|
||||
@@ -126,12 +128,13 @@ namespace scenes {
|
||||
if (phase_acc_ms_ >= SCROLL_MS) {
|
||||
// Garanteix posició final exacta (pos_x=0).
|
||||
drawSlide(slide_idx, 0);
|
||||
if (phase_ == Phase::Slide1Enter)
|
||||
if (phase_ == Phase::Slide1Enter) {
|
||||
phase_ = Phase::Slide1Hold;
|
||||
else if (phase_ == Phase::Slide2Enter)
|
||||
} else if (phase_ == Phase::Slide2Enter) {
|
||||
phase_ = Phase::Slide2Hold;
|
||||
else
|
||||
} else {
|
||||
phase_ = Phase::Slide3Hold;
|
||||
}
|
||||
phase_acc_ms_ = 0;
|
||||
}
|
||||
break;
|
||||
@@ -142,10 +145,11 @@ namespace scenes {
|
||||
phase_acc_ms_ += delta_ms;
|
||||
if (phase_acc_ms_ >= HOLD_MS) {
|
||||
fade_.startFadeOut();
|
||||
if (phase_ == Phase::Slide1Hold)
|
||||
if (phase_ == Phase::Slide1Hold) {
|
||||
phase_ = Phase::FadeOut1;
|
||||
else
|
||||
} else {
|
||||
phase_ = Phase::FadeOut2;
|
||||
}
|
||||
phase_acc_ms_ = 0;
|
||||
}
|
||||
break;
|
||||
@@ -163,10 +167,11 @@ namespace scenes {
|
||||
if (fade_.done()) {
|
||||
restorePalette();
|
||||
JD8_ClearScreen(BG_COLOR_INDEX);
|
||||
if (phase_ == Phase::FadeOut1)
|
||||
if (phase_ == Phase::FadeOut1) {
|
||||
phase_ = Phase::Slide2Enter;
|
||||
else
|
||||
} else {
|
||||
phase_ = Phase::Slide3Enter;
|
||||
}
|
||||
phase_acc_ms_ = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace scenes {
|
||||
|
||||
void onEnter() override;
|
||||
void tick(int delta_ms) override;
|
||||
bool done() const override { return phase_ == Phase::Done; }
|
||||
int nextState() const override { return next_state_; }
|
||||
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
|
||||
[[nodiscard]] auto nextState() const -> int override { return next_state_; }
|
||||
|
||||
private:
|
||||
enum class Phase {
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace scenes {
|
||||
y1_ = y1;
|
||||
duration_ms_ = std::max(0, duration_ms);
|
||||
elapsed_ms_ = 0;
|
||||
ease_ = ease ? ease : Easing::linear;
|
||||
ease_ = (ease != nullptr) ? ease : Easing::linear;
|
||||
cur_x_ = x0;
|
||||
cur_y_ = y0;
|
||||
}
|
||||
@@ -38,8 +38,10 @@ namespace scenes {
|
||||
cur_y_ = Easing::lerpInt(y0_, y1_, eased);
|
||||
}
|
||||
|
||||
float SpriteMover::progress() const {
|
||||
if (duration_ms_ <= 0) return 1.0f;
|
||||
auto SpriteMover::progress() const -> float {
|
||||
if (duration_ms_ <= 0) {
|
||||
return 1.0F;
|
||||
}
|
||||
return static_cast<float>(elapsed_ms_) / static_cast<float>(duration_ms_);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ namespace scenes {
|
||||
|
||||
void tick(int delta_ms);
|
||||
|
||||
int x() const { return cur_x_; }
|
||||
int y() const { return cur_y_; }
|
||||
bool done() const { return elapsed_ms_ >= duration_ms_; }
|
||||
float progress() const; // 0..1 sense easing aplicat
|
||||
[[nodiscard]] auto x() const -> int { return cur_x_; }
|
||||
[[nodiscard]] auto y() const -> int { return cur_y_; }
|
||||
[[nodiscard]] auto done() const -> bool { return elapsed_ms_ >= duration_ms_; }
|
||||
[[nodiscard]] auto progress() const -> float; // 0..1 sense easing aplicat
|
||||
|
||||
private:
|
||||
int x0_{0}, y0_{0}, x1_{0}, y1_{0};
|
||||
|
||||
@@ -6,7 +6,9 @@ namespace scenes {
|
||||
: surface_(JD8_LoadSurface(file)) {}
|
||||
|
||||
SurfaceHandle::~SurfaceHandle() {
|
||||
if (surface_) JD8_FreeSurface(surface_);
|
||||
if (surface_ != nullptr) {
|
||||
JD8_FreeSurface(surface_);
|
||||
}
|
||||
}
|
||||
|
||||
SurfaceHandle::SurfaceHandle(SurfaceHandle&& other) noexcept
|
||||
@@ -14,9 +16,11 @@ namespace scenes {
|
||||
other.surface_ = nullptr;
|
||||
}
|
||||
|
||||
SurfaceHandle& SurfaceHandle::operator=(SurfaceHandle&& other) noexcept {
|
||||
auto SurfaceHandle::operator=(SurfaceHandle&& other) noexcept -> SurfaceHandle& {
|
||||
if (this != &other) {
|
||||
if (surface_) JD8_FreeSurface(surface_);
|
||||
if (surface_ != nullptr) {
|
||||
JD8_FreeSurface(surface_);
|
||||
}
|
||||
surface_ = other.surface_;
|
||||
other.surface_ = nullptr;
|
||||
}
|
||||
@@ -24,16 +28,20 @@ namespace scenes {
|
||||
}
|
||||
|
||||
void SurfaceHandle::reset(const char* file) {
|
||||
if (surface_) JD8_FreeSurface(surface_);
|
||||
surface_ = file ? JD8_LoadSurface(file) : nullptr;
|
||||
if (surface_ != nullptr) {
|
||||
JD8_FreeSurface(surface_);
|
||||
}
|
||||
surface_ = (file != nullptr) ? JD8_LoadSurface(file) : nullptr;
|
||||
}
|
||||
|
||||
void SurfaceHandle::adopt(JD8_Surface raw) {
|
||||
if (surface_) JD8_FreeSurface(surface_);
|
||||
if (surface_ != nullptr) {
|
||||
JD8_FreeSurface(surface_);
|
||||
}
|
||||
surface_ = raw;
|
||||
}
|
||||
|
||||
JD8_Surface SurfaceHandle::release() {
|
||||
auto SurfaceHandle::release() -> JD8_Surface {
|
||||
JD8_Surface r = surface_;
|
||||
surface_ = nullptr;
|
||||
return r;
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace scenes {
|
||||
~SurfaceHandle();
|
||||
|
||||
SurfaceHandle(const SurfaceHandle&) = delete;
|
||||
SurfaceHandle& operator=(const SurfaceHandle&) = delete;
|
||||
auto operator=(const SurfaceHandle&) -> SurfaceHandle& = delete;
|
||||
|
||||
SurfaceHandle(SurfaceHandle&& other) noexcept;
|
||||
SurfaceHandle& operator=(SurfaceHandle&& other) noexcept;
|
||||
auto operator=(SurfaceHandle&& other) noexcept -> SurfaceHandle&;
|
||||
|
||||
// Allibera la surface actual (si n'hi ha) i carrega una nova.
|
||||
// Usat per escenes que recarreguen assets a mitja cinemàtica
|
||||
@@ -34,13 +34,13 @@ namespace scenes {
|
||||
// altre propietari). Usat quan una escena delega a codi legacy que
|
||||
// també allibera la mateixa surface — cal "soltar" el ownership per
|
||||
// evitar double free.
|
||||
[[nodiscard]] JD8_Surface release();
|
||||
[[nodiscard]] auto release() -> JD8_Surface;
|
||||
|
||||
// Conversió implícita per al confort d'ús: JD8_Blit(handle)
|
||||
// en lloc de JD8_Blit(handle.get()).
|
||||
operator JD8_Surface() const { return surface_; }
|
||||
JD8_Surface get() const { return surface_; }
|
||||
bool valid() const { return surface_ != nullptr; }
|
||||
[[nodiscard]] auto get() const -> JD8_Surface { return surface_; }
|
||||
[[nodiscard]] auto valid() const -> bool { return surface_ != nullptr; }
|
||||
|
||||
private:
|
||||
JD8_Surface surface_{nullptr};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace scenes {
|
||||
|
||||
Timeline& Timeline::step(int duration_ms, StepFn fn) {
|
||||
auto Timeline::step(int duration_ms, StepFn fn) -> Timeline& {
|
||||
Step s;
|
||||
s.duration_ms = duration_ms;
|
||||
s.continuous = std::move(fn);
|
||||
@@ -12,7 +12,7 @@ namespace scenes {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timeline& Timeline::once(OnceFn fn) {
|
||||
auto Timeline::once(OnceFn fn) -> Timeline& {
|
||||
Step s;
|
||||
s.duration_ms = 0;
|
||||
s.oneshot = std::move(fn);
|
||||
@@ -25,7 +25,9 @@ namespace scenes {
|
||||
auto& s = steps_[current_];
|
||||
if (!s.entered) {
|
||||
s.entered = true;
|
||||
if (s.oneshot) s.oneshot();
|
||||
if (s.oneshot) {
|
||||
s.oneshot();
|
||||
}
|
||||
}
|
||||
++current_;
|
||||
elapsed_in_step_ = 0;
|
||||
@@ -33,21 +35,29 @@ namespace scenes {
|
||||
}
|
||||
|
||||
void Timeline::tick(int delta_ms) {
|
||||
if (skipped_) return;
|
||||
if (skipped_) {
|
||||
return;
|
||||
}
|
||||
flushOneShots();
|
||||
if (current_ >= steps_.size()) return;
|
||||
if (current_ >= steps_.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& s = steps_[current_];
|
||||
if (!s.entered) {
|
||||
s.entered = true;
|
||||
// Primer tick dins del pas: cridem amb progress=0 si hi ha callback.
|
||||
if (s.continuous) s.continuous(0.0f);
|
||||
if (s.continuous) {
|
||||
s.continuous(0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
elapsed_in_step_ += delta_ms;
|
||||
if (elapsed_in_step_ >= s.duration_ms) {
|
||||
// Tancament del pas: una crida final amb progress=1.
|
||||
if (s.continuous) s.continuous(1.0f);
|
||||
if (s.continuous) {
|
||||
s.continuous(1.0F);
|
||||
}
|
||||
++current_;
|
||||
elapsed_in_step_ = 0;
|
||||
// Pot ser que el següent pas siga una cadena de one-shots.
|
||||
@@ -65,20 +75,26 @@ namespace scenes {
|
||||
}
|
||||
|
||||
void Timeline::reset() {
|
||||
for (auto& s : steps_) s.entered = false;
|
||||
for (auto& s : steps_) {
|
||||
s.entered = false;
|
||||
}
|
||||
current_ = 0;
|
||||
elapsed_in_step_ = 0;
|
||||
skipped_ = false;
|
||||
}
|
||||
|
||||
bool Timeline::done() const {
|
||||
auto Timeline::done() const -> bool {
|
||||
return skipped_ || current_ >= steps_.size();
|
||||
}
|
||||
|
||||
float Timeline::currentProgress() const {
|
||||
if (current_ >= steps_.size()) return 1.0f;
|
||||
auto Timeline::currentProgress() const -> float {
|
||||
if (current_ >= steps_.size()) {
|
||||
return 1.0F;
|
||||
}
|
||||
const auto& s = steps_[current_];
|
||||
if (s.duration_ms <= 0) return 0.0f;
|
||||
if (s.duration_ms <= 0) {
|
||||
return 0.0F;
|
||||
}
|
||||
return static_cast<float>(elapsed_in_step_) / static_cast<float>(s.duration_ms);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,16 +25,16 @@ namespace scenes {
|
||||
using StepFn = std::function<void(float progress_0_1)>;
|
||||
using OnceFn = std::function<void()>;
|
||||
|
||||
Timeline& step(int duration_ms, StepFn fn = nullptr);
|
||||
Timeline& once(OnceFn fn);
|
||||
auto step(int duration_ms, StepFn fn = nullptr) -> Timeline&;
|
||||
auto once(OnceFn fn) -> Timeline&;
|
||||
|
||||
void tick(int delta_ms);
|
||||
void skip();
|
||||
void reset();
|
||||
|
||||
bool done() const;
|
||||
int currentStepIndex() const { return static_cast<int>(current_); }
|
||||
float currentProgress() const;
|
||||
[[nodiscard]] auto done() const -> bool;
|
||||
[[nodiscard]] auto currentStepIndex() const -> int { return static_cast<int>(current_); }
|
||||
[[nodiscard]] auto currentProgress() const -> float;
|
||||
|
||||
private:
|
||||
struct Step {
|
||||
|
||||
Reference in New Issue
Block a user