Atirar
O tiro é outro objeto, criado com spawn. Ele se move sozinho pela velocidade definida no onSpawn.
function onSpawn(self) self.vspeed = -5end
function onUpdate(self) if self.y < -8 then self:destroy() endendclass Bullet : public Entity {public: void onSpawn() override { vspeed = -5; } void onUpdate() override { if (y < -8) destroy(); }};BRASA_ENTITY(Bullet);No objeto que atira:
function onUpdate(self) if pressed("atirar") then spawn("Bullet", self.x, self.y, "Instancias") endendvoid onUpdate() override { if (pressed("atirar")) spawn<Bullet>(x, y, "Instancias");}Intervalo entre os tiros
Seção intitulada “Intervalo entre os tiros”function onSpawn(self) self.podeAtirar = trueend
function onUpdate(self) if held("atirar") and self.podeAtirar then spawn("Bullet", self.x, self.y, "Instancias") self.podeAtirar = false self:after(10, function() self.podeAtirar = true end) endendbool podeAtirar_ = true;
void onUpdate() override { if (held("atirar") && podeAtirar_) { spawn<Bullet>(x, y, "Instancias"); podeAtirar_ = false; after(10, [this] { podeAtirar_ = true; }); }}Na direção do mouse
Seção intitulada “Na direção do mouse”spawn devolve a instância criada. O onSpawn dela já rodou, então o que for definido depois é o que vale.
local bala = spawn("Bullet", self.x, self.y, "Instancias")bala:setSpeed(5)bala:setDirection(self:angleTo(mouseX(), mouseY()))if (Bullet* bala = spawn<Bullet>(x, y, "Instancias")) { bala->setSpeed(5); bala->setDirection(angleTo(mouseX(), mouseY()));}Referência: Instâncias, Temporizadores.
