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