-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
94 lines (77 loc) · 2.18 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
local activeGameState = require "startGamestate"
function love.run()
if love.math then
love.math.setRandomSeed(os.time())
end
if love.load then love.load(arg) end
-- We don't want the first frame's dt to include time taken by love.load.
if love.timer then love.timer.step() end
local dt
local lastFrame = 0
-- Main loop time.
while true do
--If it is time for another tick calculate the tick
if(love.timer.getTime()-lastFrame >= 1/60) then
lastFrame = love.timer.getTime()
if love.timer then
love.timer.step()
dt = love.timer.getDelta()
end
if love.event then
love.event.pump()
for name, a,b,c,d,e,f in love.event.poll() do
if name == "quit" then
if not love.quit or not love.quit() then
return a
end
end
love.handlers[name](a,b,c,d,e,f)
end
end
-- Call update and draw
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics and love.graphics.isActive() then
love.graphics.clear(love.graphics.getBackgroundColor())
love.graphics.origin()
if love.draw then love.draw() end
love.graphics.present()
end
end
end
end
function love.load()
love.graphics.setDefaultFilter("nearest","nearest",1)
love.graphics.setBackgroundColor(0,0,255)
love.window.setMode(640,360,{["fullscreen"] = true,["fullscreentype"]= "desktop", ["vsync"] = true})
activeGameState.load()
end
function love.update()
activeGameState.update()
end
function love.draw()
activeGameState.draw()
end
function switchGamestate(gamestate)
love.graphics.origin()
activeGameState = gamestate
activeGameState.load()
end
--forward event handlers
function love.keypressed(key)
activeGameState.keypressed(key)
end
function love.keyreleased(key)
activeGameState.keyreleased(key)
end
function love.gampadpressed(joystick,button)
activeGameState.gamepadpressed(joystick,button)
end
function love.gamepadreleased(joystick,button)
activeGameState.gamepadpressed(joystick,button)
end
function love.joystickhat(joystick,hat,direction)
activeGameState.joystickhat(joystick,hat,direction)
end
function love.gamepadaxis(joystick,axis,value)
activeGameState.gamepadaxis(joystick,axis,value)
end