feat: add simple prompts
This commit is contained in:
parent
ba7b4ce977
commit
dd9f3cb6e3
7 changed files with 108 additions and 12 deletions
|
@ -4,7 +4,8 @@ return {
|
|||
{"normaltiles", "assets/backgrounds/normaltile"},
|
||||
{"sptiles", "assets/backgrounds/specialtile"},
|
||||
{"borders", "assets/backgrounds/borders"},
|
||||
{"ranks", "assets/gui/ranks"}
|
||||
{"ranks", "assets/gui/ranks"},
|
||||
{"qtebtn", "assets/gui/qtebtn"}
|
||||
},
|
||||
["sprites"] = {
|
||||
{"cursorground", "assets/gui/cursor/ground"},
|
||||
|
|
|
@ -2,4 +2,6 @@ local qtes = {}
|
|||
|
||||
local baseURI = "scenes.battlesystem.controllers.fighters.systems.choregraphy.qte."
|
||||
|
||||
qtes["simplePrompt"] = require (baseURI .. "simpleprompt")
|
||||
|
||||
return qtes
|
||||
|
|
|
@ -9,6 +9,9 @@ function QteParent:new(choregraphySystem, arguments)
|
|||
self.tweens = TweenManager(self)
|
||||
self.isBlocking = nil
|
||||
self.prompts = Prompts(self)
|
||||
self.timer = 0
|
||||
self.timerActive = false
|
||||
self.isSuccess = false
|
||||
end
|
||||
|
||||
function QteParent:blockAction(action, isBlocked)
|
||||
|
@ -17,6 +20,13 @@ function QteParent:blockAction(action, isBlocked)
|
|||
end
|
||||
end
|
||||
|
||||
function QteParent:endQte()
|
||||
self.choregraphy:endQte(self.isSuccess)
|
||||
if (self.isBlocking ~= nil) then
|
||||
self.isBlocking:getSignal("qteEnded")
|
||||
end
|
||||
end
|
||||
|
||||
function QteParent:setOrigin(origin)
|
||||
local x, y = 424/2, 240/2
|
||||
local argy = 24
|
||||
|
@ -55,15 +65,23 @@ end
|
|||
function QteParent:timerResponse(timer)
|
||||
if (timer == "qteTimer") then
|
||||
core.debug:print("qte", "Timer finished")
|
||||
self:finish(self:isSuccessOnEnd())
|
||||
if (self.timerActive) then
|
||||
self:finish(self:isSuccessOnEnd())
|
||||
end
|
||||
elseif (timer == "startTimer") then
|
||||
core.debug:print("qte", "Timer started with " .. self.timer .. " seconds")
|
||||
self.tweens:newTimer(self.timer, "qteTimer")
|
||||
self.timerActive = true
|
||||
self.prompts.defaultTimerValue = 0
|
||||
elseif (timer == "endQte") then
|
||||
self:endQte()
|
||||
end
|
||||
end
|
||||
|
||||
function QteParent:finish(success)
|
||||
self.choregraphy:endQte(success)
|
||||
if (self.isBlocking ~= nil) then
|
||||
self.isBlocking:getSignal("qteEnded")
|
||||
end
|
||||
self.isSuccess = success
|
||||
self.timerActive = false
|
||||
self.tweens:newTimer(self.prompts.BEGINTIME, "endQte")
|
||||
end
|
||||
|
||||
function QteParent:verifyPrompts()
|
||||
|
@ -85,8 +103,9 @@ end
|
|||
-- Use these functions to access some of the API
|
||||
|
||||
function QteParent:setTimer(time)
|
||||
core.debug:print("qte", "Timer started with " .. time .. " seconds")
|
||||
self.tweens:newTimer(time, "qteTimer")
|
||||
core.debug:print("qte", "Timer started with " .. time .. " prepared")
|
||||
self.timer = time
|
||||
self.tweens:newTimer(self.prompts.BEGINTIME, "startTimer")
|
||||
end
|
||||
|
||||
function QteParent:delay(time)
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
local Button = Object:extend()
|
||||
local ButtonCircle = Object:extend()
|
||||
local TweenManager = require "game.modules.tweenmanager"
|
||||
|
||||
local keys = {"A", "B", "C"}
|
||||
local BTN_SIZE = 21
|
||||
local CANVAS_SIZE = 21+2
|
||||
local SHAKETIME = 0.02
|
||||
local SHAKEPOWER = 4
|
||||
|
||||
local function myStencilFunction()
|
||||
love.graphics.circle("fill", CANVAS_SIZE/2, CANVAS_SIZE/2, BTN_SIZE/2 - 1)
|
||||
|
@ -13,6 +16,7 @@ function Button:new(prompt, key, number, beginTime)
|
|||
self.prompt = prompt
|
||||
self.key = key
|
||||
self.number = number or 1
|
||||
self.showNumber = (self.number > 1)
|
||||
|
||||
self.isPressed = false
|
||||
|
||||
|
@ -20,6 +24,10 @@ function Button:new(prompt, key, number, beginTime)
|
|||
self.opacity = 0
|
||||
self.frame = self:getFrame()
|
||||
self.scale = 1.25
|
||||
self.isFailed = false
|
||||
self.shakeTimer = SHAKETIME
|
||||
self.shakex, self.shakey = 0, 0
|
||||
self.circles = {}
|
||||
|
||||
self.timerTexture = nil
|
||||
self.tweens = TweenManager(self)
|
||||
|
@ -37,6 +45,18 @@ end
|
|||
|
||||
function Button:update(dt, isFirst)
|
||||
self.tweens:update(dt)
|
||||
for i, circle in ipairs(self.circles) do
|
||||
circle:update(dt)
|
||||
end
|
||||
|
||||
if (self.isFailed) then
|
||||
self.shakeTimer = self.shakeTimer - dt
|
||||
if (self.shakeTimer < 0) then
|
||||
self.shakeTimer = SHAKETIME
|
||||
self.shakex = math.random(SHAKEPOWER*2) - (SHAKEPOWER)
|
||||
self.shakey = math.random(SHAKEPOWER*2) - (SHAKEPOWER)
|
||||
end
|
||||
end
|
||||
|
||||
if (isFirst) then
|
||||
self.timerTexture = love.graphics.newCanvas(CANVAS_SIZE, CANVAS_SIZE)
|
||||
|
@ -61,8 +81,10 @@ function Button:verifyPrompts(sourceKeys, removeWhenPressed)
|
|||
if (key == self.key) then
|
||||
keyValue = 1
|
||||
self.lum = 0.8
|
||||
table.insert(self.circles, ButtonCircle())
|
||||
else
|
||||
keyValue = -1
|
||||
self.isFailed = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -75,17 +97,46 @@ function Button:verifyPrompts(sourceKeys, removeWhenPressed)
|
|||
return keyValue, mustBeRemoved
|
||||
end
|
||||
|
||||
function Button:finish()
|
||||
self.tweens:newTween(0, 0.2, {opacity = 0, scale = 1.25}, "inOutQuart")
|
||||
function Button:finish(success)
|
||||
local scale = 0.75
|
||||
if (success == true) then
|
||||
scale = 1.25
|
||||
end
|
||||
self.tweens:newTween(0, 0.15, {opacity = 0, scale = scale}, "inOutQuart")
|
||||
end
|
||||
|
||||
function Button:draw(x, y, isFirst)
|
||||
local x, y = x + self.shakex, y + self.shakey
|
||||
love.graphics.setColor(1,1,1,self.circleOpacity)
|
||||
for i, circle in ipairs(self.circles) do
|
||||
circle:draw(x, y)
|
||||
end
|
||||
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)
|
||||
if (self.number > 0 and self.showNumber) then
|
||||
self.prompt.assets.fonts["hudnbrs_small"]:draw(utils.math.numberToString(self.number, 2), x, y + 2, -1, "left")
|
||||
end
|
||||
end
|
||||
|
||||
function ButtonCircle:new()
|
||||
self.radius = 6
|
||||
self.opacity = 1
|
||||
self.tweens = TweenManager(self)
|
||||
self.tweens:newTween(0, 0.2, {radius = 12}, "inOutQuart")
|
||||
self.tweens:newTween(0.1, 0.1, {opacity = 0}, "inOutQuart")
|
||||
end
|
||||
|
||||
function ButtonCircle:update(dt)
|
||||
self.tweens:update(dt)
|
||||
end
|
||||
|
||||
function ButtonCircle:draw(x, y)
|
||||
love.graphics.setColor(1,1,1,self.opacity)
|
||||
love.graphics.circle("line",x,y,self.radius, 16)
|
||||
end
|
||||
|
||||
return Button
|
|
@ -10,6 +10,7 @@ function QtePrompts:new(qte)
|
|||
self.assets = qte.choregraphy.assets
|
||||
self.scene = core.scenemanager.currentScene
|
||||
self.current = 1
|
||||
self.defaultTimerValue = 1
|
||||
|
||||
self.list = {}
|
||||
end
|
||||
|
@ -19,7 +20,7 @@ function QtePrompts:add(key, number)
|
|||
end
|
||||
|
||||
function QtePrompts:getTimer()
|
||||
local defaultValue = 0
|
||||
local defaultValue = self.defaultTimerValue
|
||||
local _, _, timerValue = self.qte:getTimerInfo()
|
||||
return timerValue or defaultValue
|
||||
end
|
||||
|
@ -39,10 +40,15 @@ function QtePrompts:verifyPrompts()
|
|||
buttonValue = -1
|
||||
end
|
||||
if (mustBeRemoved) then
|
||||
self.list[self.current]:finish()
|
||||
self.list[self.current]:finish(true)
|
||||
self.current = self.current + 1
|
||||
end
|
||||
end
|
||||
for i, button in ipairs(self.list) do
|
||||
if (buttonValue == -1 and (i ~= self.current)) then
|
||||
button:finish(false)
|
||||
end
|
||||
end
|
||||
return buttonValue
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
local Parent = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.qte.parent"
|
||||
local SimplePrompt = Parent:extend()
|
||||
|
||||
function SimplePrompt:start()
|
||||
self:setTimer(self.arguments.duration)
|
||||
for i, keyData in ipairs(self.arguments.key) do
|
||||
self.prompts:add(keyData[1], keyData[2])
|
||||
end
|
||||
end
|
||||
|
||||
function SimplePrompt:promptSuccess()
|
||||
if (self.prompts:isOver()) then
|
||||
self:success()
|
||||
end
|
||||
end
|
||||
|
||||
return SimplePrompt
|
Loading…
Reference in a new issue