Fixed a bug regarding transitions

This commit is contained in:
theo@manjaro 2022-03-10 10:47:12 +01:00
parent ad05851b01
commit fed23c4252
3 changed files with 26 additions and 17 deletions

View File

@ -3,7 +3,8 @@ local Game = {}
local insert = table.insert local insert = table.insert
function Game:reinit() function Game:reinit()
self.gameloop = {} self:reinitgameloop()
self.maxobjects = 0
self.objects = {} self.objects = {}
self.scenes = require "scenes" self.scenes = require "scenes"
self.objects.base = require "objects/base" self.objects.base = require "objects/base"
@ -14,7 +15,6 @@ function Game:reinit()
self.objects.transition= require "objects/transition" self.objects.transition= require "objects/transition"
self.objects.tutorial = require "objects/tutorial" self.objects.tutorial = require "objects/tutorial"
self.rect = require "lib/rect" self.rect = require "lib/rect"
self.maxobjects = 0
self.camerax = 0 self.camerax = 0
self.debug = false self.debug = false
self.cameray = 0 self.cameray = 0
@ -25,6 +25,10 @@ function Game:reinit()
love.window.setIcon(love.image.newImageData("assets/icon.png")) love.window.setIcon(love.image.newImageData("assets/icon.png"))
end end
function Game:reinitgameloop()
self.gameloop = {}
end
function Game:changesize(width,height) function Game:changesize(width,height)
self.WIDTH = width self.WIDTH = width
self.HEIGHT = height self.HEIGHT = height
@ -129,13 +133,15 @@ function Game:findName(askedname)
end end
function Game:delid(objid) 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 end
function Game:delname(objName) 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 if v~=nil then
self:delid(v.id) Game:delid(objid)
end end
end end
end end

View File

@ -14,21 +14,24 @@ function gen:new(game,time,func,args)
function Transition:step(dt) function Transition:step(dt)
if self.timer:tick(dt) then if self.timer:tick(dt) then
if self.func then if self.timer.loops == 1 then
self.game.scenes[func](self.game.scenes,self.game,self.args) if self.func then
local t = self.game.objects.transition:new(self.game,self.timer.maxcount) self.game.scenes[func](self.game.scenes,self.game,self.args)
self.game:summon(t) local t = self.game.objects.transition:new(self.game,self.timer.maxcount)
self.game:summon(t)
end
end end
self.game:delid(self.id)
end end
end end
function Transition:draw() function Transition:draw()
local offset = self.game.HEIGHT if self.timer.loops<1 then
if not self.func then offset = 0 end local offset = self.game.HEIGHT
lg.setColor(self.color) if not self.func then offset = 0 end
lg.rectangle("fill",0,offset-self.game.HEIGHT*(1-self.timer:getratio()), self.game.WIDTH,self.game.HEIGHT) lg.setColor(self.color)
lg.setColor({1,1,1,1}) 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 end
return Transition return Transition

View File

@ -1,7 +1,7 @@
local scenes = {} local scenes = {}
function scenes:main(game) function scenes:main(game)
game.gameloop = {} game:reinitgameloop()
local cellsize = 44 local cellsize = 44
local x = (game.WIDTH-cellsize*5)/2 local x = (game.WIDTH-cellsize*5)/2
local y = (game.HEIGHT-cellsize*5)/2 local y = (game.HEIGHT-cellsize*5)/2
@ -16,7 +16,7 @@ function scenes:main(game)
end end
function scenes:ending(game,args) function scenes:ending(game,args)
game.gameloop = {} game:reinitgameloop()
local ending = game.objects.ending:new(game,args.winner) local ending = game.objects.ending:new(game,args.winner)
game:summon(ending) game:summon(ending)
local background = game.objects.background:new(game,game:newImage("pattern.png"),30,15) local background = game.objects.background:new(game,game:newImage("pattern.png"),30,15)