refactor: extreure helpers per reduir complexitat cognitiva (tidy net)

This commit is contained in:
2026-05-16 16:13:57 +02:00
parent b984e6041e
commit e1bc1b597f
31 changed files with 1145 additions and 1332 deletions
+12 -12
View File
@@ -6,7 +6,7 @@
Bola::Bola(Jd8::Surface gfx, Prota* sam)
: Sprite(gfx) {
this->sam = sam;
this->sam_ = sam;
entitat.frames.reserve(2);
entitat.frames.push_back({30, 155, 15, 15});
@@ -17,28 +17,28 @@ Bola::Bola(Jd8::Surface gfx, Prota* sam)
this->cur_frame = 0;
this->o = 0;
this->cycles_per_frame = 4;
this->cycles_per_frame_ = 4;
this->x = 20;
this->y = 100;
this->contador = 0;
this->contador_ = 0;
}
void Bola::draw() {
if (this->contador == 0) {
if (this->contador_ == 0) {
Sprite::draw();
}
}
void Bola::update() {
if (this->contador == 0) {
if (this->contador_ == 0) {
// Augmentem la x
this->x++;
if (this->x == 280) {
this->contador = 200;
this->contador_ = 200;
}
// Augmentem el frame
if (Jg::getCycleCounter() % this->cycles_per_frame == 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;
@@ -46,16 +46,16 @@ void Bola::update() {
}
// 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;
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;
this->sam_->o = 5;
}
}
} else {
this->contador--;
if (this->contador == 0) {
this->contador_--;
if (this->contador_ == 0) {
this->x = 20;
}
}