From 7bf5b9a9273c907ffa386b89a610a071f782b5f8 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Mon, 19 Jul 2021 18:23:47 -0700 Subject: [PATCH] Move some code into "expand" & "explode" local functions --- entity.lua | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/entity.lua b/entity.lua index 8bbc91e..30ef7e7 100644 --- a/entity.lua +++ b/entity.lua @@ -110,6 +110,31 @@ local function isnan(n) return tostring(n) == tostring((-1)^.5) end +local function expand(self) + if self.chase and self.visualx < 2 then + if self.hiss == false then + core.sound_play("sneeker_hiss", {object=self.object, gain=1.5, max_hear_distance=2*64}) + end + self.visualx = self.visualx+0.05 + self.object:set_properties({ + visual_size = {x=self.visualx, y=1} + }) + self.hiss = true + elseif self.visualx > 1 then + self.visualx = self.visualx-0.05 + self.object:set_properties({ + visual_size = {x=self.visualx, y=1} + }) + self.hiss = false + end +end + +local function explode(self, pos) + self.object:remove() + sneeker.boom(pos, self.powered) + core.sound_play("sneeker_explode", {object=self.object, gain=sneeker.boom_gain, max_hear_distance=2*64}) +end + def.on_step = function(self, dtime) -- update lifetime timer -- FIXME: this is longer than realtime @@ -184,22 +209,7 @@ def.on_step = function(self, dtime) self.object:set_yaw(self.yaw) end - if self.chase and self.visualx < 2 then - if self.hiss == false then - core.sound_play("sneeker_hiss", {pos=pos, gain=1.5, max_hear_distance=2*64}) - end - self.visualx = self.visualx+0.05 - self.object:set_properties({ - visual_size = {x=self.visualx, y=1} - }) - self.hiss = true - elseif self.visualx > 1 then - self.visualx = self.visualx-0.05 - self.object:set_properties({ - visual_size = {x=self.visualx, y=1} - }) - self.hiss = false - end + expand(self) self.chase = false @@ -276,9 +286,7 @@ def.on_step = function(self, dtime) if object:is_player() and object:get_hp() ~= 0 then self.chase = true if self.visualx >= 2 then - self.object:remove() - sneeker.boom(pos, self.powered) - core.sound_play("sneeker_explode", {pos=pos, gain=sneeker.boom_gain, max_hear_distance=2*64}) + explode(self, pos) return true end end