Compare commits
2 commits
74f515a385
...
e824579d5e
| Author | SHA1 | Date | |
|---|---|---|---|
| e824579d5e | |||
| f86d0dabf0 |
4 changed files with 26 additions and 3 deletions
7
main.lua
7
main.lua
|
|
@ -31,6 +31,8 @@ Area = require 'obj/Area'
|
||||||
GameObject = require 'obj/GameObject'
|
GameObject = require 'obj/GameObject'
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
|
-- slowmo var
|
||||||
|
slow_amnt = 1
|
||||||
-- table of color palette
|
-- table of color palette
|
||||||
COLORS = {
|
COLORS = {
|
||||||
default = {1,1,1,1},
|
default = {1,1,1,1},
|
||||||
|
|
@ -87,7 +89,7 @@ function love.load()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
if current_room then current_room:update(dt) end
|
if current_room then current_room:update(dt*slow_amnt) end
|
||||||
input:update(dt)
|
input:update(dt)
|
||||||
if input:pressed('f1') then gotoRoom('CircleRoom') end
|
if input:pressed('f1') then gotoRoom('CircleRoom') end
|
||||||
if input:pressed('f2') and DEBUG then
|
if input:pressed('f2') and DEBUG then
|
||||||
|
|
@ -114,7 +116,7 @@ function love.update(dt)
|
||||||
for k, v in pairs(counts) do print(k, v) end
|
for k, v in pairs(counts) do print(k, v) end
|
||||||
print("-------------------------------------")
|
print("-------------------------------------")
|
||||||
end
|
end
|
||||||
camera:update(dt)
|
camera:update(dt*slow_amnt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
|
@ -166,6 +168,7 @@ function gotoRoom(room_type, ...)
|
||||||
error("room '"..room_type.."' is not callable (got "..type(Class)..", does room return itself?)")
|
error("room '"..room_type.."' is not callable (got "..type(Class)..", does room return itself?)")
|
||||||
end
|
end
|
||||||
if current_room and current_room.destroy then current_room:destroy() 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](...)
|
current_room = _G[room_type](...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
14
obj/Area.lua
14
obj/Area.lua
|
|
@ -11,6 +11,7 @@ function Area:new(room)
|
||||||
self.room = room
|
self.room = room
|
||||||
self.game_objects = {}
|
self.game_objects = {}
|
||||||
self.world = nil
|
self.world = nil
|
||||||
|
self.timer = Timer()
|
||||||
end
|
end
|
||||||
|
|
||||||
---Updates area
|
---Updates area
|
||||||
|
|
@ -25,6 +26,7 @@ function Area:update(dt)
|
||||||
table.remove(self.game_objects, i)
|
table.remove(self.game_objects, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self.timer:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Draws area
|
---Draws area
|
||||||
|
|
@ -34,6 +36,10 @@ end
|
||||||
|
|
||||||
---Destroys area
|
---Destroys area
|
||||||
function Area:destroy()
|
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
|
for i = #self.game_objects, 1, -1 do
|
||||||
local game_object = self.game_objects[i]
|
local game_object = self.game_objects[i]
|
||||||
game_object:kill()
|
game_object:kill()
|
||||||
|
|
@ -62,4 +68,12 @@ function Area:addCollisionManager(cell_size)
|
||||||
self.world = HC(cell_size or 100)
|
self.world = HC(cell_size or 100)
|
||||||
end
|
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
|
return Area
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,10 @@ end
|
||||||
|
|
||||||
---Destroys room
|
---Destroys room
|
||||||
function Room:destroy()
|
function Room:destroy()
|
||||||
|
if self.timer then
|
||||||
|
self.timer:clear() -- cancel all tweens/after/every
|
||||||
|
self.timer = nil
|
||||||
|
end
|
||||||
self.area:destroy()
|
self.area:destroy()
|
||||||
self.area = nil
|
self.area = nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -83,10 +83,12 @@ function Player:shoot()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:kill()
|
function Player:kill()
|
||||||
|
self:destroy()
|
||||||
for i=1, random(8,12) do
|
for i=1, random(8,12) do
|
||||||
self.area:addGameObject('ExplodeParticle', self.x, self.y)
|
self.area:addGameObject('ExplodeParticle', self.x, self.y)
|
||||||
end
|
end
|
||||||
self:destroy()
|
self.area:slow(.15, 1)
|
||||||
|
camera:shake(6, 60, .4)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Player
|
return Player
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue