Fixed a bug regarding transitions
This commit is contained in:
parent
ad05851b01
commit
fed23c4252
16
game.lua
16
game.lua
@ -3,7 +3,8 @@ local Game = {}
|
||||
local insert = table.insert
|
||||
|
||||
function Game:reinit()
|
||||
self.gameloop = {}
|
||||
self:reinitgameloop()
|
||||
self.maxobjects = 0
|
||||
self.objects = {}
|
||||
self.scenes = require "scenes"
|
||||
self.objects.base = require "objects/base"
|
||||
@ -14,7 +15,6 @@ function Game:reinit()
|
||||
self.objects.transition= require "objects/transition"
|
||||
self.objects.tutorial = require "objects/tutorial"
|
||||
self.rect = require "lib/rect"
|
||||
self.maxobjects = 0
|
||||
self.camerax = 0
|
||||
self.debug = false
|
||||
self.cameray = 0
|
||||
@ -25,6 +25,10 @@ function Game:reinit()
|
||||
love.window.setIcon(love.image.newImageData("assets/icon.png"))
|
||||
end
|
||||
|
||||
function Game:reinitgameloop()
|
||||
self.gameloop = {}
|
||||
end
|
||||
|
||||
function Game:changesize(width,height)
|
||||
self.WIDTH = width
|
||||
self.HEIGHT = height
|
||||
@ -129,13 +133,15 @@ function Game:findName(askedname)
|
||||
end
|
||||
|
||||
function Game:delid(objid)
|
||||
self.gameloop[objid] = nil
|
||||
for i,v in ipairs(self.gameloop) do
|
||||
if v~=nil and v.id==objid then self.gameloop[i] = nil end
|
||||
end
|
||||
end
|
||||
|
||||
function Game:delname(objName)
|
||||
for i,v in ipairs(Game:findName(objName)) do
|
||||
for i,v in ipairs(self:findName(objName)) do
|
||||
if v~=nil then
|
||||
self:delid(v.id)
|
||||
Game:delid(objid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,21 +14,24 @@ function gen:new(game,time,func,args)
|
||||
|
||||
function Transition:step(dt)
|
||||
if self.timer:tick(dt) then
|
||||
if self.func then
|
||||
self.game.scenes[func](self.game.scenes,self.game,self.args)
|
||||
local t = self.game.objects.transition:new(self.game,self.timer.maxcount)
|
||||
self.game:summon(t)
|
||||
if self.timer.loops == 1 then
|
||||
if self.func then
|
||||
self.game.scenes[func](self.game.scenes,self.game,self.args)
|
||||
local t = self.game.objects.transition:new(self.game,self.timer.maxcount)
|
||||
self.game:summon(t)
|
||||
end
|
||||
end
|
||||
self.game:delid(self.id)
|
||||
end
|
||||
end
|
||||
|
||||
function Transition:draw()
|
||||
local offset = self.game.HEIGHT
|
||||
if not self.func then offset = 0 end
|
||||
lg.setColor(self.color)
|
||||
lg.rectangle("fill",0,offset-self.game.HEIGHT*(1-self.timer:getratio()), self.game.WIDTH,self.game.HEIGHT)
|
||||
lg.setColor({1,1,1,1})
|
||||
if self.timer.loops<1 then
|
||||
local offset = self.game.HEIGHT
|
||||
if not self.func then offset = 0 end
|
||||
lg.setColor(self.color)
|
||||
lg.rectangle("fill",0,offset-self.game.HEIGHT*(1-self.timer:getratio()), self.game.WIDTH,self.game.HEIGHT)
|
||||
lg.setColor({1,1,1,1})
|
||||
end
|
||||
end
|
||||
|
||||
return Transition
|
||||
|
@ -1,7 +1,7 @@
|
||||
local scenes = {}
|
||||
|
||||
function scenes:main(game)
|
||||
game.gameloop = {}
|
||||
game:reinitgameloop()
|
||||
local cellsize = 44
|
||||
local x = (game.WIDTH-cellsize*5)/2
|
||||
local y = (game.HEIGHT-cellsize*5)/2
|
||||
@ -16,7 +16,7 @@ function scenes:main(game)
|
||||
end
|
||||
|
||||
function scenes:ending(game,args)
|
||||
game.gameloop = {}
|
||||
game:reinitgameloop()
|
||||
local ending = game.objects.ending:new(game,args.winner)
|
||||
game:summon(ending)
|
||||
local background = game.objects.background:new(game,game:newImage("pattern.png"),30,15)
|
||||
|
Loading…
Reference in New Issue
Block a user