blob: 7663c564eee22709466e28a0108c9ba00a3693f0 (
plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
-- print words on screen to inform user
speaker = {}
local windowH = love.graphics.getHeight()
local windowW = love.graphics.getWidth()
function speaker.init()
speaker.text = nil
speaker.current = nil
speaker.index = 1
speaker.till = nil
speaker.clearOnSwitchingRoom = false
speaker.duration = nil
end
speaker.init()
function speaker.speak(text, duration, clearOnSwitchingRoom)
speaker.till = G.time + (duration or 3)
speaker.duration = duration or 3
speaker.text = text
speaker.clearOnSwitchingRoom = clearOnSwitchingRoom
if type(text) == "table" then
speaker.current = text[1]
elseif type(text) == "string" then
speaker.current = text
end
end
function speaker.clear()
speaker.init()
end
function speaker.print()
if speaker.text then
local font = love.graphics.getFont()
local textWidth = font:getWidth(speaker.current)
love.graphics.print(speaker.current, (windowW - textWidth) / 2, windowH - 200)
end
end
function speaker.update(dt)
if G.time >= (speaker.till or 0) then
if type(speaker.text) == "table" then
speaker.index = speaker.index + 1
speaker.current = speaker.text[speaker.index]
speaker.till = G.time + speaker.duration
if speaker.index > #speaker.text then
speaker.clear()
end
else
speaker.clear()
end
end
end
|