-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
147 lines (105 loc) · 4.28 KB
/
main.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
-- All global values used in all scenes (display, textures, options, etc.)
function love.load()
-- Get screenRes
screenRes = {love.graphics.getWidth(),love.graphics.getHeight()}
-- Window and defaulting
globalTimer = 0; love.graphics.setDefaultFilter("nearest","nearest")
fullscreen = false; title = "Ne_mene´s Framework"
WS = {768,576}; wFlags = {resizable=true}
aspectRatio = {WS[1]/WS[2],WS[2]/WS[1]}
love.graphics.setBackgroundColor(0,0,0,1); love.window.setMode(WS[1],WS[2],wFlags); display = love.graphics.newCanvas(WS[1],WS[2]); displayScale = 1
postProCanvas = love.graphics.newCanvas(WS[1],WS[2])
love.window.setTitle(title.." [F1 for fullscreen]")
-- Imports
require "init"
scenes[scene][2]()
-- Mouse
--love.mouse.setVisible(false)
mouseMode = "pointer"
mouse = {["pointer"] = love.graphics.newImage("data/graphics/images/mouse/pointer.png")}
mouseOffset = {0,0}
-- Set joysticks
JOYSTICKS = love.joystick.getJoysticks()
JOYSTICK_LAST_PRESSES = {}
for id,J in pairs(JOYSTICKS) do JOYSTICK_LAST_PRESSES[id] = "none" end
-- Transitions
transition = 1
TIME_SCALE = 1
end
-- Play scenes
function love.draw()
processTextParticles()
-- Time and resetting
rawDt = love.timer.getDelta()
dt = clamp(rawDt, 0, 1 / 30) * TIME_SCALE
globalTimer = globalTimer + dt
-- Mouse pos
xM, yM = love.mouse.getPosition()
w, h = love.graphics.getDimensions()
dw, dh = display:getDimensions()
xM = clamp(xM,w*0.5-dw*0.5*displayScale,w*0.5+dw*0.5*displayScale)
yM = clamp(yM,h*0.5-dh*0.5*displayScale,h*0.5+dh*0.5*displayScale)
xM = xM - (w*0.5-dw*0.5*displayScale)
yM = yM - (h*0.5-dh*0.5*displayScale)
xM = xM/displayScale; yM = yM/displayScale
-- Bg and canvas resetting
love.graphics.setColor(1,1,1,1); love.graphics.setCanvas(display)
love.graphics.clear(0,0,0,1)
--------------------------------------------------------------------------SCENE CALLED
processCamera()
processShockwaves()
love.graphics.setShader()
transition = clamp(transition - dt,0,1)
sceneNew = scenes[scene][1]()
if sceneNew ~= scene then
scenes[scene][3]()
scene = sceneNew; scenes[scene][2]()
transition = 1
end
processAllLights()
-- Mouse
-- love.graphics.setColor(1,1,1,1)
-- love.graphics.draw(mouse[mouseMode],xM,yM,0,SPRSCL,SPRSCL)
-- Post processing
setColor(255, 255, 255)
love.graphics.setShader(SHADERS.POST_PROCESS)
love.graphics.setCanvas(postProCanvas)
love.graphics.draw(display)
love.graphics.setCanvas()
love.graphics.setShader()
-- Draw display
setColor(255 * (1 - transition), 255 * (1 - transition), 255 * (1 - transition))
love.graphics.draw(postProCanvas, w * 0.5 - dw * 0.5 * displayScale - screenshake[1] * displayScale, h * 0.5 - dh * 0.5 * displayScale - screenshake[2] * displayScale, 0, displayScale, displayScale)
-- Check for fullscreen
if justPressed("f1") then changeFullscreen() end
-- Reset input
lastKeyPressed = "none"; lastMouseButtonPressed = -1
for id,J in pairs(JOYSTICKS) do JOYSTICK_LAST_PRESSES[id] = "none" end
end
-- Display resizing
function love.resize(w, h)
displayScale = math.min(w/WS[1], h/WS[2])
love.graphics.setCanvas(display)
love.graphics.scale(zoom)
end
function changeFullscreen()
fullscreen = not fullscreen
love.window.setFullscreen(fullscreen)
if fullscreen == false then
love.window.width = WS[1]; love.window.height = WS[2]; displayScale = 1
end
end
-- Keyboard
function love.keypressed(k) setJustPressed(k) end
-- Mouse
function love.mousepressed(x,y,button) setMouseJustPressed(button) end
-- Joysticks
function love.joystickadded(joystick) table.insert(JOYSTICKS,joystick); table.insert(JOYSTICK_LAST_PRESSES,"none") end
function love.joystickremoved(joystick)
id = elementIndex(JOYSTICKS,joystick)
table.remove(JOYSTICKS,id); table.remove(JOYSTICK_LAST_PRESSES,id)
end
function love.joystickpressed(joystick,button)
id = elementIndex(JOYSTICKS,joystick)
JOYSTICK_LAST_PRESSES[id] = button
end