-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
132 lines (117 loc) · 4.08 KB
/
Copy pathmain.lua
File metadata and controls
132 lines (117 loc) · 4.08 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
LoadedSection = 1
LoadedSlide = 1
local currentSlide = nil
Collision = require 'core.Collision'
Manager = require 'game.Manager'
Theme = require "theme"
Helpers = require "helpers"
Level = require "level"
Controls = require "game.Controls"
Debug = require "lib.debug"
GameTime = 0
function LoadSlide(section, slide)
Level.loaded = false
GameTime = 0
Helpers.codeLeft = false
print("Loading slide: Section " .. section .. ", Slide " .. slide)
local slidePath = "sections/" .. section .. "/slide_" .. slide
local success, newSlide = pcall(require, slidePath)
if not success then
print("Slide not found: " .. slidePath)
return
end
if newSlide then
if currentSlide then
package.loaded["sections/" .. LoadedSection .. "/slide_" .. LoadedSlide] = nil
end
currentSlide = newSlide
LoadedSection = section
LoadedSlide = slide
if currentSlide.load then
currentSlide:load()
end
end
end
function love.update(dt)
if Level.loaded then
GameTime = GameTime + dt
end
if currentSlide and currentSlide.update then
currentSlide:update(dt)
end
end
local smallFont = love.graphics.newFont(16)
function love.draw()
-- Background that isn't full black
love.graphics.setColor(Theme.Background)
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
love.graphics.setColor(Theme.Text) -- Reset color to text color for drawing the slide
if currentSlide and currentSlide.draw then
currentSlide:draw()
end
-- Draw the section and slide in the bottom left
love.graphics.setColor(Theme.Text[1], Theme.Text[2], Theme.Text[3], 0.5)
love.graphics.setFont(smallFont)
love.graphics.print(LoadedSection .. "." .. LoadedSlide, 20, love.graphics.getHeight() - 40)
end
function love.keypressed(k)
Debug:keypressed(k)
if k == 'escape' then
love.event.quit()
elseif k == Controls.NextSlide then
-- Load the next slide (for simplicity, just incrementing slide number)
LoadSlide(LoadedSection, LoadedSlide + 1)
elseif k == Controls.PrevSlide then
if LoadedSlide == 1 then return end -- Prevent going to slide 0
LoadSlide(LoadedSection, LoadedSlide - 1)
elseif k == Controls.PrevSection then
LoadSlide(LoadedSection - 1, 1) -- Load the first slide of the previous section
elseif k == Controls.NextSection then
LoadSlide(LoadedSection + 1, 1) -- Load the first slide of the next section
elseif k == Controls.ReloadSlide then
Reload()
end
if currentSlide then
if k == Controls.NextStage and currentSlide.stage then
if currentSlide.onStageUp then
currentSlide:onStageUp(currentSlide.stage + 1)
end
currentSlide.stage = currentSlide.stage + 1
elseif k == Controls.PrevStage and currentSlide.stage then
if currentSlide.onStageDown then
currentSlide:onStageDown(currentSlide.stage - 1)
end
currentSlide.stage = math.max(0, currentSlide.stage - 1)
elseif k == Controls.ToggleGrid and currentSlide.showGrid ~= nil then
currentSlide.showGrid = not currentSlide.showGrid
end
end
if currentSlide and currentSlide.keypressed then
currentSlide:keypressed(k)
end
if Level.loaded then
Level:keypressed(k)
end
end
function love.focus(f)
if f then
Reload()
end
end
function Reload()
local oldStage = (currentSlide and currentSlide.stage) or 0
LoadSlide(LoadedSection, LoadedSlide)
if currentSlide then
currentSlide.stage = oldStage
if currentSlide.onStageUp then
for i = 1, oldStage do
currentSlide:onStageUp(i)
end
end
end
end
love.window.setTitle("Slide Presentation")
-- love.window.setFullscreen(true) -- Start in fullscreen mode
-- windows 1920x1080
love.window.setMode(1920, 1080, {resizable=true, vsync=true, fullscreen=false})
LoadSlide(1, 1) -- Load the first slide of section 1