diff --git a/sonic-radiance.love/assets/gui/qtebtn.png b/sonic-radiance.love/assets/gui/qtebtn.png index 002e048..5336ab3 100644 Binary files a/sonic-radiance.love/assets/gui/qtebtn.png and b/sonic-radiance.love/assets/gui/qtebtn.png differ diff --git a/sonic-radiance.love/game/modules/tweenmanager/init.lua b/sonic-radiance.love/game/modules/tweenmanager/init.lua index 3be1df4..2255cb5 100644 --- a/sonic-radiance.love/game/modules/tweenmanager/init.lua +++ b/sonic-radiance.love/game/modules/tweenmanager/init.lua @@ -38,7 +38,7 @@ end function TweenManager:getTimerInfo(name) if (self.timers[name] ~= nil) then - self.timers[name]:getInfo() + return self.timers[name]:getInfo() end end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/parent.lua index 4e18dc5..024e03d 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/parent.lua @@ -1,12 +1,14 @@ local QteParent = Object:extend() local TweenManager = require "game.modules.tweenmanager" +local Prompts = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.qte.prompts" function QteParent:new(choregraphySystem, arguments) self.choregraphy = choregraphySystem self.arguments = arguments self.tweens = TweenManager(self) self.isBlocking = nil + self.prompts = Prompts(self) end function QteParent:blockAction(action, isBlocked) @@ -45,6 +47,8 @@ function QteParent:updateQte(dt) else self:update(dt) self.tweens:update(dt) + self.prompts:update(dt) + self:verifyPrompts() end end @@ -62,6 +66,21 @@ function QteParent:finish(success) end end +function QteParent:verifyPrompts() + local promptResult = self.prompts:verifyPrompts() + if (promptResult == 1) then + self:promptSuccess() + elseif (promptResult == -1) then + self:fail() + end +end + +function QteParent:draw() + self:drawOverButtons() + self.prompts:draw(self.x, self.y) + self:drawUnderButtons() +end + -- USABLE FUNCTIONS -- Use these functions to access some of the API @@ -76,10 +95,10 @@ function QteParent:delay(time) end function QteParent:getTimerInfo() - self.tweens:getTimerInfo("qteTimer") + return self.tweens:getTimerInfo("qteTimer") end -function QteParent:succes() +function QteParent:success() self:finish(true) end @@ -98,11 +117,19 @@ function QteParent:update(dt) -- end +function QteParent:promptSuccess() + +end + function QteParent:isSuccessOnEnd() return false end -function QteParent:draw() +function QteParent:drawOverButtons() + +end + +function QteParent:drawUnderButtons() end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/prompts/button.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/prompts/button.lua new file mode 100644 index 0000000..2a74f6d --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/prompts/button.lua @@ -0,0 +1,91 @@ +local Button = Object:extend() +local TweenManager = require "game.modules.tweenmanager" + +local keys = {"A", "B", "C"} +local BTN_SIZE = 21 +local CANVAS_SIZE = 21+2 + +local function myStencilFunction() + love.graphics.circle("fill", CANVAS_SIZE/2, CANVAS_SIZE/2, BTN_SIZE/2 - 1) + end + +function Button:new(prompt, key, number, beginTime) + self.prompt = prompt + self.key = key + self.number = number or 1 + + self.isPressed = false + + self.lum = 1 + self.opacity = 0 + self.frame = self:getFrame() + self.scale = 1.25 + + self.timerTexture = nil + self.tweens = TweenManager(self) + self.tweens:newTween(0, beginTime, {opacity = 1, scale = 1}, "inOutQuart") +end + +function Button:getFrame() + for i, key in ipairs(keys) do + if (key == self.key) then + return i + end + end + error("Non existing key " .. self.keys) +end + +function Button:update(dt, isFirst) + self.tweens:update(dt) + + if (isFirst) then + self.timerTexture = love.graphics.newCanvas(CANVAS_SIZE, CANVAS_SIZE) + love.graphics.setCanvas({self.timerTexture, stencil = true}) + love.graphics.setColor(0.5, 0.5, 0.5, 1) + love.graphics.circle("fill", CANVAS_SIZE/2, CANVAS_SIZE/2, BTN_SIZE/2) + utils.graphics.setColorHSV(self.prompt:getTimer()/3, 1, 1) + love.graphics.stencil(myStencilFunction, "replace", 1) + love.graphics.setStencilTest("greater", 0) + love.graphics.arc("fill", CANVAS_SIZE/2, CANVAS_SIZE/2, BTN_SIZE/2, 0 - (math.pi/2), ((math.pi*2*self.prompt:getTimer()) - (math.pi/2)), 16) + love.graphics.setStencilTest() + love.graphics.setCanvas() + end +end + +function Button:verifyPrompts(sourceKeys, removeWhenPressed) + local mustBeRemoved = false + local keyValue = 0 + self.lum = 1 + for i, key in ipairs(keys) do + if (sourceKeys[key].isPressed) then + if (key == self.key) then + keyValue = 1 + self.lum = 0.8 + else + keyValue = -1 + end + end + end + if (removeWhenPressed and keyValue == 1) then + self.number = self.number - 1 + if (self.number == 0) then + mustBeRemoved = true + end + end + return keyValue, mustBeRemoved +end + +function Button:finish() + self.tweens:newTween(0, 0.2, {opacity = 0, scale = 1.25}, "inOutQuart") +end + +function Button:draw(x, y, isFirst) + love.graphics.setColor(self.lum,self.lum,self.lum,self.opacity) + if (isFirst and self.timerTexture ~= nil) then + love.graphics.draw(self.timerTexture, x, y, 0, -self.scale, self.scale, 12, 11) + end + self.prompt.assets.tileset["qtebtn"]:drawTile(self.frame, x, y, 0, self.scale, self.scale, 8, 8) + love.graphics.setColor(1,1,1,1) +end + +return Button \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/prompts/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/prompts/init.lua new file mode 100644 index 0000000..697d8f6 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/qte/prompts/init.lua @@ -0,0 +1,60 @@ +local QtePrompts = Object:extend() +local Button = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.qte.prompts.button" + +QtePrompts.BEGINTIME = 0.2 + +function QtePrompts:new(qte) + self.qte = qte + self.canPress = true + self.removeWhenPressed = true + self.assets = qte.choregraphy.assets + self.scene = core.scenemanager.currentScene + self.current = 1 + + self.list = {} +end + +function QtePrompts:add(key, number) + table.insert(self.list, Button(self, key, number, QtePrompts.BEGINTIME)) +end + +function QtePrompts:getTimer() + local defaultValue = 0 + local _, _, timerValue = self.qte:getTimerInfo() + return timerValue or defaultValue +end + +function QtePrompts:update(dt) + for i, button in ipairs(self.list) do + button:update(dt, (i == self.current)) + end +end + +function QtePrompts:verifyPrompts() + local buttonValue, mustBeRemoved = 0, false + if (self.list[self.current] ~= nil) then + local keys = self.scene.sources[1].keys + buttonValue, mustBeRemoved = self.list[self.current]:verifyPrompts(keys, self.removeWhenPressed) + if (not self.canPress and buttonValue == 1) then + buttonValue = -1 + end + if (mustBeRemoved) then + self.list[self.current]:finish() + self.current = self.current + 1 + end + end + return buttonValue +end + +function QtePrompts:isOver() + return (self.current > #self.list) +end + +function QtePrompts:draw(x, y) + local SIZE = 20 + for i, button in ipairs(self.list) do + button:draw(x + (SIZE*(i-1)) - ((SIZE/2)*(#self.list-1)), y, (i == self.current)) + end +end + +return QtePrompts \ No newline at end of file