-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.lua
107 lines (80 loc) · 1.87 KB
/
scene.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
scenes = {}
scene = {}
local curScene = "intro"
local sceneInitData = {}
local trans = false
local trans_step = 0
local trans_to = ""
local trans_alpha = 0
function scene.switch(sceneName, data, instant)
if trans then return end
sceneInitData = data or {}
if instant then
curScene = sceneName
scene.runInit()
return
end
trans = true
trans_step = 0
trans_to = sceneName
end
function scene.restart(instant)
scene.switch(curScene, sceneInitData, instant or false)
end
function scene.runInit()
if scenes[curScene].init ~= nil then
scenes[curScene].init(sceneInitData)
end
end
function scene.runUpdate(dt)
if scenes[curScene].update ~= nil then
scenes[curScene].update(dt)
end
if scenes[curScene].gui ~= nil then
scenes[curScene].gui:update()
end
end
function scene.runDraw()
local bg
if scenes[curScene].draw ~= nil then
if scenes[curScene].background then
bg = scenes[curScene].background
draw.background(love.math.colorFromBytes(bg[1], bg[2], bg[3]))
end
scenes[curScene].draw()
end
if scenes[curScene].gui ~= nil then
scenes[curScene].gui:draw()
end
if scenes[curScene].background then
draw.backgroundLetterbox(love.math.colorFromBytes(bg[1], bg[2], bg[3]))
end
end
function scene.runBack()
if scenes[curScene].back ~= nil then
scenes[curScene].back()
end
end
function scene.isTransitioning()
return trans
end
function scene.performTransition()
if not trans then return end
if trans_step < 25 then
trans_alpha = trans_alpha + 10
else
trans_alpha = trans_alpha - 10
end
love.graphics.setColor(0,0,0,trans_alpha/255)
love.graphics.push()
love.graphics.origin()
love.graphics.rectangle('fill', 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
love.graphics.pop()
trans_step = trans_step + 1
if trans_step == 25 then
curScene = trans_to
scene.runInit()
elseif trans_step == 50 then
trans = false
end
end