-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.lua
37 lines (33 loc) · 940 Bytes
/
dialog.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
dialog = {}
function dialog.load()
dialog.sound = love.audio.newSource("typewriter.wav","static")
dialog.soundTimer = 6
end
function dialog.newDialogText(string,x,y)
local dText = {text = string, length = 0, speed = 20, finished = false, x=x, y=y, timer=0}
--[[
dText.text = string
dText.length = 0
dText.speed = 10
dText.finished = false
]]
return dText
end
function dialog.updateText(dt,dText)
if not dText.finished then
dText.length = dText.length+dt*dText.speed
dText.timer = dText.length+dt*dText.speed
if dText.timer>dialog.soundTimer then
dText.timer = dText.timer - dialog.soundTimer
love.audio.play(dialog.sound)
end
if dText.length>#dText.text then
dText.finished = true
dText.length = #dText.text
end
end
end
function dialog.drawText(dText)
local msg = string.sub(dText.text, 1, math.floor(dText.length))
love.graphics.print(msg,dText.x,dText.y)
end