-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemoMode.lua
More file actions
89 lines (70 loc) · 1.98 KB
/
demoMode.lua
File metadata and controls
89 lines (70 loc) · 1.98 KB
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
--Runs a 'demo' mode, used largely by the screensaver, but available to the main program
--Default behavior is to switch between a number of different 'profiles'
--Examples of profiles can be found in the profiles folder
local life = require("life");
local profiles = require("profiles");
local demoMode = {}
local currentInstance;
--Not the best implementation but don't worry about it
local fadeAmount = 1;
local fadeOut = false;
local fadeIn = false;
local currProfile;
local function loadRandomProfile()
currentInstance, currProfile = profiles.loadRandom();
currProfile.timeoutFramesEdit = currProfile.timeoutFrames;
if not currProfile.timeout then
currProfile.timeout = math.random(10,30) + love.timer.getTime();
end
collectgarbage();
end
local function load()
profiles.loadProfileList();
loadRandomProfile();
end
local function update(dt)
currentInstance:update();
local switchInstances = false;
if not fadeOut then
--Check if we need to switch instances
if currProfile.timeoutFrames then
currProfile.timeoutFramesEdit = currProfile.timeoutFramesEdit - 1;
switchInstances = currProfile.timeoutFramesEdit <= 0;
end
if currProfile.timeout then
switchInstances = love.timer.getTime() >= currProfile.timeout;
end
if switchInstances then
fadeAmount = 1;
fadeOut = true;
end
else
if not fadeIn then
fadeAmount = fadeAmount - (dt / 1);
if fadeAmount <= -1 then
fadeIn = true;
fadeAmount = 0;
loadRandomProfile();
end
else
fadeAmount = fadeAmount + (dt / 1.5);
if fadeAmount >= 1 then
fadeAmount = 1;
fadeIn = false;
fadeOut = false;
end
end
end
end
local function draw()
currentInstance:refreshImage();
local x,y = love.graphics.getPixelDimensions();
love.graphics.setColor(1,1,1,fadeAmount);
love.graphics.draw(currentInstance.image,0,0,0,x / currentInstance:getWidth(), y / currentInstance:getHeight());
end
function demoMode.init(arg)
love.update = update;
love.draw = draw;
load(arg);
end
return demoMode;