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

@@ -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;