dirtier slow() call (works a bit better)
This commit is contained in:
parent
f86d0dabf0
commit
e824579d5e
4 changed files with 23 additions and 11 deletions
12
main.lua
12
main.lua
|
|
@ -31,7 +31,7 @@ Area = require 'obj/Area'
|
|||
GameObject = require 'obj/GameObject'
|
||||
|
||||
function love.load()
|
||||
-- slow_amntmo var
|
||||
-- slowmo var
|
||||
slow_amnt = 1
|
||||
-- table of color palette
|
||||
COLORS = {
|
||||
|
|
@ -168,6 +168,7 @@ function gotoRoom(room_type, ...)
|
|||
error("room '"..room_type.."' is not callable (got "..type(Class)..", does room return itself?)")
|
||||
end
|
||||
if current_room and current_room.destroy then current_room:destroy() end
|
||||
if slow_amnt ~= 1 then slow_amnt = 1 end
|
||||
current_room = _G[room_type](...)
|
||||
end
|
||||
|
||||
|
|
@ -212,15 +213,6 @@ function random(min, max)
|
|||
return (min > max and (love.math.random()*(min - max) + max)) or (love.math.random()*(max - min) + min)
|
||||
end
|
||||
|
||||
---Slows down gameplay
|
||||
---@param amount number percentage to which game will slow down
|
||||
---@param duration number duration in seconds of slow down
|
||||
---@param t Timer|nil optional timer object for optimization
|
||||
function slow(amount, duration, t)
|
||||
local timer = t or Timer()
|
||||
timer:tween(duration, _G, {slow_amnt = amount}, 'im-out-quad')
|
||||
end
|
||||
|
||||
------------------------
|
||||
-- garbage collection --
|
||||
------------------------
|
||||
|
|
|
|||
14
obj/Area.lua
14
obj/Area.lua
|
|
@ -11,6 +11,7 @@ function Area:new(room)
|
|||
self.room = room
|
||||
self.game_objects = {}
|
||||
self.world = nil
|
||||
self.timer = Timer()
|
||||
end
|
||||
|
||||
---Updates area
|
||||
|
|
@ -25,6 +26,7 @@ function Area:update(dt)
|
|||
table.remove(self.game_objects, i)
|
||||
end
|
||||
end
|
||||
self.timer:update(dt)
|
||||
end
|
||||
|
||||
---Draws area
|
||||
|
|
@ -34,6 +36,10 @@ end
|
|||
|
||||
---Destroys area
|
||||
function Area:destroy()
|
||||
if self.timer then
|
||||
self.timer:clear() -- cancel all tweens/after/every
|
||||
self.timer = nil
|
||||
end
|
||||
for i = #self.game_objects, 1, -1 do
|
||||
local game_object = self.game_objects[i]
|
||||
game_object:kill()
|
||||
|
|
@ -62,4 +68,12 @@ function Area:addCollisionManager(cell_size)
|
|||
self.world = HC(cell_size or 100)
|
||||
end
|
||||
|
||||
---Slows down gameplay
|
||||
---@param amount number percentage to which game will slow down
|
||||
---@param duration number duration in seconds of slow down
|
||||
function Area:slow(amount, duration)
|
||||
slow_amnt = amount
|
||||
self.timer:tween(duration, _G, {slow_amnt = 1}, 'in-out-cubic')
|
||||
end
|
||||
|
||||
return Area
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ end
|
|||
|
||||
---Destroys room
|
||||
function Room:destroy()
|
||||
if self.timer then
|
||||
self.timer:clear() -- cancel all tweens/after/every
|
||||
self.timer = nil
|
||||
end
|
||||
self.area:destroy()
|
||||
self.area = nil
|
||||
end
|
||||
|
|
|
|||
|
|
@ -83,10 +83,12 @@ function Player:shoot()
|
|||
end
|
||||
|
||||
function Player:kill()
|
||||
self:destroy()
|
||||
for i=1, random(8,12) do
|
||||
self.area:addGameObject('ExplodeParticle', self.x, self.y)
|
||||
end
|
||||
self:destroy()
|
||||
self.area:slow(.15, 1)
|
||||
camera:shake(6, 60, .4)
|
||||
end
|
||||
|
||||
return Player
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue