feat: add a way to load / unload the battlesystem

This commit is contained in:
Kazhnuz 2021-04-02 22:23:39 +02:00
parent ab3e4eadd8
commit f0b696117b
9 changed files with 102 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -0,0 +1,38 @@
local CoreCBS = Object:extend()
local battleutils = require "game.utils.battle"
local defTransitions = require "core.modules.transitions"
local radTransitions = require "game.modules.transitions"
local DEFAULTX = 424/2
local DEFAULTY = 240/2
function CoreCBS:new()
self.lastx, self.lasty = DEFAULTX, DEFAULTY
end
function CoreCBS:startBattle(category, name, x, y)
local data = battleutils.getBattleData(category, name)
self.lastx, self.lasty = x or DEFAULTX, y or DEFAULTY
core.screen:startTransition(radTransitions.eggman, radTransitions.borders, function() scenes.cbs(data) end, x, y)
end
function CoreCBS:endBattle(isFleeing)
local transitionEnd = radTransitions.sonic
if (isFleeing) then
transitionEnd = defTransitions.circle;
end
core.screen:startTransition(radTransitions.borders, transitionEnd,
function()
if (core.scenemanager:haveStoredScene("afterBattle")) then
core.scenemanager:setStoredScene("afterBattle")
else
scenes.debug.menu()
end
end, self.lastx, self.lasty)
self.lastx, self.lasty = DEFAULTX, DEFAULTY
end
return CoreCBS

View file

@ -28,6 +28,7 @@ local Characters = require "game.characters"
local Ennemies = require "game.ennemies" local Ennemies = require "game.ennemies"
local Skills = require "game.skills" local Skills = require "game.skills"
local Loot = require "game.loot" local Loot = require "game.loot"
local CBSCore = require "game.battle"
local binser = require "core.modules.gamesystem.libs.binser" local binser = require "core.modules.gamesystem.libs.binser"
@ -43,6 +44,7 @@ function Game:new()
self.ennemies = Ennemies(self) self.ennemies = Ennemies(self)
self.skills = Skills(self) self.skills = Skills(self)
self.loot = Loot(self) self.loot = Loot(self)
self.cbs = CBSCore(self)
self.flags = {} self.flags = {}
self.destroyedGizmo = {} self.destroyedGizmo = {}

View file

@ -0,0 +1,8 @@
local DecalTransition = require "core.modules.transitions.decal"
local EggmanTransition = DecalTransition:extend()
function EggmanTransition:new(func, ox, oy, fadeOut)
EggmanTransition.super.new(self, func, ox, oy, fadeOut, "eggdecal")
end
return EggmanTransition

View file

@ -0,0 +1,5 @@
return {
sonic = require "game.modules.transitions.sonic",
eggman = require "game.modules.transitions.eggman",
borders = require "game.modules.transitions.zigzag",
}

View file

@ -0,0 +1,8 @@
local DecalTransition = require "core.modules.transitions.decal"
local SonicTransition = DecalTransition:extend()
function SonicTransition:new(func, ox, oy, fadeOut)
SonicTransition.super.new(self, func, ox, oy, fadeOut, "sonicdecal")
end
return SonicTransition

View file

@ -0,0 +1,41 @@
local CanvasTransition = require "core.modules.transitions.canvas"
local ZigZagTransition = CanvasTransition:extend()
function ZigZagTransition:new(func, ox, oy, fadeOut)
self.offset = 0
ZigZagTransition.super.new(self, func, ox, oy, fadeOut, "inQuad", "outQuad", 1, 0.1)
end
function ZigZagTransition:loadResources()
self.border = love.graphics.newImage("assets/transitions/border.png")
end
function ZigZagTransition:drawCanvas(dt)
local w, _ = self.border:getDimensions()
self.offset = (self.offset + (dt * 256)) % w
utils.graphics.resetColor()
love.graphics.rectangle("fill", 0, 0, 424, 240)
love.graphics.setColor(0,0,0,1)
local max = 120 + 16
self:drawBorder(0 + max * (self.value), false)
utils.graphics.resetColor()
self:drawBorder(240 - max * (self.value), true)
end
function ZigZagTransition:drawBorder(y, reversed)
local offset = self.offset
local sy = 1
if (reversed) then
offset = self.offset * -1
sy = -1
end
local w, h = self.border:getDimensions()
local ox, oy = 0, h
for i = -1, math.ceil(424 / w), 1 do
love.graphics.draw(self.border,(i * w) + offset,y,0,1,sy,ox,oy)
end
end
return ZigZagTransition