fase 1: jail i game a c++ idiomàtic (raii, info::ctx, cheats arreglats)

This commit is contained in:
2026-04-15 18:03:46 +02:00
parent 2c833d086e
commit 7f85b50c63
18 changed files with 834 additions and 804 deletions

View File

@@ -1,61 +1,48 @@
#include "game/engendro.hpp"
#include <stdlib.h>
#include "core/jail/jgame.hpp"
Engendro::Engendro(JD8_Surface gfx, Uint16 x, Uint16 y)
: Sprite(gfx) {
this->entitat = (Entitat*)malloc(sizeof(Entitat));
// Frames
this->entitat->num_frames = 4;
this->entitat->frames = (Frame*)malloc(this->entitat->num_frames * sizeof(Frame));
Uint8 frame = 0;
for (int y = 50; y <= 65; y += 15) {
for (int x = 225; x <= 240; x += 15) {
this->entitat->frames[frame].w = 15;
this->entitat->frames[frame].h = 15;
this->entitat->frames[frame].x = x;
this->entitat->frames[frame].y = y;
frame++;
}
}
// Animacions
this->entitat->num_animacions = 1;
this->entitat->animacions = (Animacio*)malloc(this->entitat->num_animacions * sizeof(Animacio));
this->entitat->animacions[0].num_frames = 6;
this->entitat->animacions[0].frames = (Uint8*)malloc(6);
this->entitat->animacions[0].frames[0] = 0;
this->entitat->animacions[0].frames[1] = 1;
this->entitat->animacions[0].frames[2] = 2;
this->entitat->animacions[0].frames[3] = 3;
this->entitat->animacions[0].frames[4] = 2;
this->entitat->animacions[0].frames[5] = 1;
this->cur_frame = 0;
this->vida = 18;
this->x = x;
this->y = y;
this->o = 0;
this->cycles_per_frame = 30;
}
void Engendro::draw() {
Sprite::draw();
}
bool Engendro::update() {
bool mort = false;
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
this->cur_frame++;
if (this->cur_frame == this->entitat->animacions[this->o].num_frames) this->cur_frame = 0;
this->vida--;
}
if (vida == 0) mort = true;
return mort;
}
#include "game/engendro.hpp"
#include <stdlib.h>
#include "core/jail/jgame.hpp"
Engendro::Engendro(JD8_Surface gfx, Uint16 x, Uint16 y)
: Sprite(gfx) {
entitat.frames.reserve(4);
for (int py = 50; py <= 65; py += 15) {
for (int px = 225; px <= 240; px += 15) {
Frame f;
f.w = 15;
f.h = 15;
f.x = px;
f.y = py;
entitat.frames.push_back(f);
}
}
entitat.animacions.resize(1);
entitat.animacions[0].frames = {0, 1, 2, 3, 2, 1};
this->cur_frame = 0;
this->vida = 18;
this->x = x;
this->y = y;
this->o = 0;
this->cycles_per_frame = 30;
}
void Engendro::draw() {
Sprite::draw();
}
bool Engendro::update() {
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;
this->vida--;
}
if (vida == 0) mort = true;
return mort;
}