This commit is contained in:
2026-04-18 13:22:13 +02:00
parent 2e1a82ff40
commit 27f8b0ae36
21 changed files with 54 additions and 66 deletions

View File

@@ -0,0 +1 @@
{"sessionId":"7b0c9c32-3dd4-48a3-ba06-c2303dc08243","pid":123890,"acquiredAt":1776510185734}

View File

@@ -265,13 +265,13 @@ inline JA_Music_t* JA_LoadMusic(const Uint8* buffer, Uint32 length) {
auto* music = new JA_Music_t();
music->ogg_data.assign(buffer, buffer + length);
int error = 0;
int vorbis_error = 0;
music->vorbis = stb_vorbis_open_memory(music->ogg_data.data(),
static_cast<int>(length),
&error,
&vorbis_error,
nullptr);
if (!music->vorbis) {
std::cout << "JA_LoadMusic: stb_vorbis_open_memory failed (error " << error << ")" << '\n';
std::cout << "JA_LoadMusic: stb_vorbis_open_memory failed (error " << vorbis_error << ")" << '\n';
delete music;
return nullptr;
}

View File

@@ -40,8 +40,11 @@ void JD8_ClearScreen(Uint8 color) {
}
JD8_Surface JD8_NewSurface() {
JD8_Surface surface = (JD8_Surface)malloc(64000);
memset(surface, 0, 64000);
JD8_Surface surface = (JD8_Surface)calloc(1, 64000);
if (surface == NULL) {
printf("JD8_NewSurface: out of memory\n");
exit(1);
}
return surface;
}
@@ -89,6 +92,10 @@ JD8_Palette JD8_LoadPalette(const char* file) {
// d'alliberar amb free() — mateixa convenció que el LoadPalette
// original (retornava un malloc).
JD8_Palette palette = (JD8_Palette)malloc(768);
if (palette == NULL) {
printf("JD8_LoadPalette: out of memory\n");
exit(1);
}
memcpy(palette, cached.data(), 768);
return palette;
} catch (const std::exception&) {

View File

@@ -82,9 +82,7 @@ void file_setconfigfolder(const char* foldername) {
config_folder = std::string(homedir) + "/.config/" + foldername;
#endif
if (!config_folder.empty()) {
std::filesystem::create_directories(config_folder);
}
std::filesystem::create_directories(config_folder);
}
const char* file_getconfigfolder() {

View File

@@ -80,27 +80,27 @@ void Text::loadFont(const char* fnt_file) {
// Elimina comentaris inline
auto comment_pos = line.find('#');
if (comment_pos != std::string::npos) {
line = line.substr(0, comment_pos);
line.resize(comment_pos);
}
// Parseja directives
if (line.find("box_width") == 0) {
if (line.starts_with("box_width")) {
sscanf(line.c_str(), "box_width %d", &box_width_);
continue;
}
if (line.find("box_height") == 0) {
if (line.starts_with("box_height")) {
sscanf(line.c_str(), "box_height %d", &box_height_);
continue;
}
if (line.find("columns") == 0) {
if (line.starts_with("columns")) {
sscanf(line.c_str(), "columns %d", &columns_);
continue;
}
if (line.find("cell_spacing") == 0) {
if (line.starts_with("cell_spacing")) {
sscanf(line.c_str(), "cell_spacing %d", &cell_spacing_);
continue;
}
if (line.find("row_spacing") == 0) {
if (line.starts_with("row_spacing")) {
sscanf(line.c_str(), "row_spacing %d", &row_spacing_);
continue;
}

View File

@@ -8,7 +8,7 @@ class Bola : public Sprite {
public:
Bola(JD8_Surface gfx, Prota* sam);
void draw();
void draw() override;
void update();
protected:

View File

@@ -29,10 +29,6 @@ Engendro::Engendro(JD8_Surface gfx, Uint16 x, Uint16 y)
this->cycles_per_frame = 30;
}
void Engendro::draw() {
Sprite::draw();
}
bool Engendro::update() {
bool mort = false;

View File

@@ -6,7 +6,6 @@ class Engendro : public Sprite {
public:
Engendro(JD8_Surface gfx, Uint16 x, Uint16 y);
void draw();
bool update();
protected:

View File

@@ -9,28 +9,21 @@ ModuleGame::ModuleGame() {
this->gfx = JD8_LoadSurface(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif");
JG_SetUpdateTicks(10);
this->sam = new Prota(this->gfx);
this->mapa = new Mapa(this->gfx, this->sam);
this->marcador = new Marcador(this->gfx, this->sam);
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) {
this->bola = new Bola(this->gfx, this->sam);
} else {
this->bola = nullptr;
this->bola = std::make_unique<Bola>(this->gfx, this->sam.get());
}
this->momies = nullptr;
this->iniciarMomies();
}
ModuleGame::~ModuleGame() {
if (this->bola != nullptr) delete this->bola;
if (this->momies != nullptr) {
this->momies->clear();
delete this->momies;
}
delete this->marcador;
delete this->mapa;
delete this->sam;
JD8_FreeSurface(this->gfx);
}
@@ -123,7 +116,7 @@ void ModuleGame::Draw() {
this->marcador->draw();
this->sam->draw();
if (this->momies != nullptr) this->momies->draw();
if (this->bola != nullptr) this->bola->draw();
if (this->bola) this->bola->draw();
}
void ModuleGame::Update() {
@@ -137,14 +130,14 @@ void ModuleGame::Update() {
this->momies = seguent;
info::ctx.momies--;
}
if (this->bola != nullptr) this->bola->update();
if (this->bola) this->bola->update();
this->mapa->update();
if (this->mapa->novaMomia()) {
if (this->momies != nullptr) {
this->momies->insertar(new Momia(this->gfx, true, 0, 0, this->sam));
this->momies->insertar(new Momia(this->gfx, true, 0, 0, this->sam.get()));
info::ctx.momies++;
} else {
this->momies = new Momia(this->gfx, true, 0, 0, this->sam);
this->momies = new Momia(this->gfx, true, 0, 0, this->sam.get());
info::ctx.momies++;
}
}
@@ -187,9 +180,9 @@ void ModuleGame::iniciarMomies() {
bool dimonis = info::ctx.num_piramide == 6;
for (int i = 0; i < info::ctx.momies; i++) {
if (this->momies == nullptr) {
this->momies = new Momia(this->gfx, dimonis, x, y, this->sam);
this->momies = new Momia(this->gfx, dimonis, x, y, this->sam.get());
} else {
this->momies->insertar(new Momia(this->gfx, dimonis, x, y, this->sam));
this->momies->insertar(new Momia(this->gfx, dimonis, x, y, this->sam.get()));
}
x += 65;
if (x == 345) {

View File

@@ -1,5 +1,7 @@
#pragma once
#include <memory>
#include "game/bola.hpp"
#include "game/info.hpp"
#include "game/mapa.hpp"
@@ -52,9 +54,9 @@ class ModuleGame : public scenes::Scene {
Uint8 final_{0};
JD8_Surface gfx{nullptr};
Mapa* mapa{nullptr};
Prota* sam{nullptr};
Marcador* marcador{nullptr};
Momia* momies{nullptr};
Bola* bola{nullptr};
std::unique_ptr<Mapa> mapa;
std::unique_ptr<Prota> sam;
std::unique_ptr<Marcador> marcador;
Momia* momies{nullptr}; // llista enllaçada, ownership enredat amb `next`
std::unique_ptr<Bola> bola;
};

View File

@@ -10,15 +10,15 @@ Momia::Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam)
this->sam = sam;
entitat.frames.reserve(20);
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 5; x++) {
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 5; col++) {
Frame f;
f.w = 15;
f.h = 15;
if (info::ctx.num_piramide == 4) f.h -= 5;
f.x = (x * 15) + 75;
f.x = (col * 15) + 75;
if (this->dimoni) f.x += 75;
f.y = 20 + (y * 15);
f.y = 20 + (row * 15);
entitat.frames.push_back(f);
}
}
@@ -57,9 +57,8 @@ Momia::Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam)
} else {
this->y = y;
}
this->engendro = new Engendro(gfx, this->x, this->y);
this->engendro = std::make_unique<Engendro>(gfx, this->x, this->y);
} else {
this->engendro = NULL;
this->x = x;
this->y = y;
}
@@ -67,12 +66,11 @@ Momia::Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam)
void Momia::clear() {
if (this->next != NULL) this->next->clear();
if (this->engendro != NULL) delete this->engendro;
delete this->next;
}
void Momia::draw() {
if (this->engendro != NULL) {
if (this->engendro) {
this->engendro->draw();
} else {
Sprite::draw();
@@ -91,10 +89,9 @@ void Momia::draw() {
bool Momia::update() {
bool morta = false;
if (this->engendro != NULL) {
if (this->engendro) {
if (this->engendro->update()) {
delete this->engendro;
this->engendro = NULL;
this->engendro.reset();
}
} else {
if (this->sam->o < 4 && (this->dimoni || info::ctx.num_piramide == 5 || JG_GetCycleCounter() % 2 == 0)) {

View File

@@ -1,5 +1,7 @@
#pragma once
#include <memory>
#include "game/engendro.hpp"
#include "game/info.hpp"
#include "game/prota.hpp"
@@ -10,7 +12,7 @@ class Momia : public Sprite {
Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam);
void clear();
void draw();
void draw() override;
bool update();
void insertar(Momia* momia);
@@ -19,5 +21,5 @@ class Momia : public Sprite {
protected:
Prota* sam;
Engendro* engendro;
std::unique_ptr<Engendro> engendro;
};

View File

@@ -5,9 +5,9 @@
class Prota : public Sprite {
public:
Prota(JD8_Surface gfx);
explicit Prota(JD8_Surface gfx);
void draw();
void draw() override;
Uint8 update();
Uint8 frame_pejades;

View File

@@ -22,10 +22,10 @@ struct Entitat {
class Sprite {
public:
Sprite(JD8_Surface gfx);
explicit Sprite(JD8_Surface gfx);
virtual ~Sprite() = default;
void draw();
virtual void draw();
Entitat entitat;
Uint8 cur_frame = 0;

View File

@@ -16,7 +16,6 @@ namespace scenes {
void onEnter() override;
void tick(int delta_ms) override;
bool done() const override { return done_; }
int nextState() const override { return 1; } // 1 → SceneRegistry::tryCreate(num_piramide=255 → intro)
private:
void render() const;

View File

@@ -29,7 +29,6 @@ namespace scenes {
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 { Rolling,

View File

@@ -37,7 +37,6 @@ namespace scenes {
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 {

View File

@@ -38,7 +38,6 @@ namespace scenes {
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 {

View File

@@ -29,7 +29,6 @@ namespace scenes {
void onEnter() override;
void tick(int delta_ms) override;
bool done() const override { return done_; }
int nextState() const override { return 1; }
private:
SurfaceHandle gfx_;

View File

@@ -27,7 +27,6 @@ namespace scenes {
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,

View File

@@ -19,7 +19,6 @@ namespace scenes {
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,