forked from TomK32/Where-is-Pixel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
68 lines (58 loc) · 1.52 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
--
-- Where is Pixel?
--
-- (C) 2013 Thomas R. Koll
require 'lib/middleclass'
require 'game'
require 'views/view'
require 'views/credits_view'
require 'game_states/state'
require 'game_states/intro'
require 'game_states/start_menu'
require 'game_states/level_state'
function love.load()
local modes = love.graphics.getModes()
table.sort(modes, function(a, b) return a.width*a.height > b.width*b.height end)
local preferred_mode = modes[1]
for i, mode in ipairs(modes) do
if math.abs(9/16 - mode.height / mode.width) < 0.1 and (mode.height >= 768 or mode.width >= 1366) then
preferred_mode = mode
end
end
game:setMode(preferred_mode)
game.current_state = Intro(game.startMenu)
--love.audio.play(game.sounds.music.track01)
--game:start()
end
function love.draw()
if not game.current_state then return end
game.current_state:draw()
if not madeScreenshot and game.debug then
madeScreenshot = true
makeScreenshot()
end
end
function love.keypressed(key)
if key == 'f2' then
makeScreenshot()
end
if not game.current_state then return end
game.current_state:keypressed(key)
end
function love.mousepressed(x,y,button)
if game.current_state.mousepressed then
game.current_state:mousepressed(x,y,button)
end
end
function love.update(dt)
if not game.current_state then return end
game.current_state:update(dt)
end
function love.quit()
if game.debug then
makeScreenshot()
end
end
function makeScreenshot()
love.graphics.newScreenshot():encode(os.time() .. '.png', 'png')
end