feat: sounds effects on dialog boxes

This commit is contained in:
Kazhnuz 2021-03-22 20:02:54 +01:00
parent 50eb613a53
commit 9e031c0d7d
3 changed files with 9 additions and 4 deletions

Binary file not shown.

View file

@ -95,6 +95,7 @@ local Talkies = {
padding = 4,
talkSound = nil,
optionSwitchSound = nil,
optionOnSelectSound = nil,
inlineOptions = true,
titleColor = {1, 1, 1},
@ -151,6 +152,7 @@ function Talkies.say(title, messages, config)
thickness = config.thickness or Talkies.thickness,
talkSound = config.talkSound or Talkies.talkSound,
optionSwitchSound = config.optionSwitchSound or Talkies.optionSwitchSound,
optionOnSelectSound = config.optionOnSelectSound or Talkies.optionOnSelectSound,
inlineOptions = config.inlineOptions or Talkies.inlineOptions,
font = font,
fontHeight = font:getHeight(" "),
@ -377,7 +379,7 @@ function Talkies.onAction()
else
if currentDialog:showOptions() then
currentDialog.options[currentDialog.optionIndex][2]() -- Execute the selected function
playSound(currentDialog.optionSwitchSound)
playSound(currentDialog.optionOnSelectSound)
end
Talkies.advanceMsg()
end

View file

@ -6,6 +6,9 @@ local Talkies = require('core.libs.talkies')
function DialogBox:new(controller, args)
DialogBox.super.new(self, controller, args)
Talkies.font = love.graphics.newFont("assets/gui/fonts/PixelOperator.ttf", 16)
Talkies.talkSound = love.audio.newSource("assets/sfx/talk.wav", "static")
Talkies.optionOnSelectSound = love.audio.newSource("assets/sfx/menus/select.wav", "static")
Talkies.optionSwitchSound = love.audio.newSource("assets/sfx/menus/beep.wav", "static")
end
function DialogBox:start()
@ -52,9 +55,9 @@ function DialogBox:update(dt)
self:finish()
end
local keys = self.events.scene.sources[1].keys
if (keys["up"].isPressed) then Talkies.prevOption()
elseif (keys["down"].isPressed) then Talkies.nextOption()
elseif (keys["A"].isPressed) then Talkies.onAction()
if (keys["up"].isPressed) then Talkies.prevOption();
elseif (keys["down"].isPressed) then Talkies.nextOption();
elseif (keys["A"].isPressed) then Talkies.onAction();
end
end