#include "game/bola.hpp" #include #include "core/jail/jgame.hpp" Bola::Bola(Jd8::Surface gfx, Prota* sam) : Sprite(gfx) { this->sam = sam; entitat.frames.reserve(2); entitat.frames.push_back({30, 155, 15, 15}); entitat.frames.push_back({45, 155, 15, 15}); entitat.animacions.resize(1); entitat.animacions[0].frames = {0, 1}; this->cur_frame = 0; this->o = 0; this->cycles_per_frame = 4; this->x = 20; this->y = 100; this->contador = 0; } void Bola::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; } // 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; } } // 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; } } } else { this->contador--; if (this->contador == 0) { this->x = 20; } } }