-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
86 lines (75 loc) · 1.92 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
--
-- Where is Pixel?
--
-- (C) 2013 Thomas R. Koll
require 'lib/middleclass'
require 'animations'
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'
require 'game_states/finish'
tween = require 'lib/tween'
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 >= 480 or mode.width >= 854) then
preferred_mode = mode
end
end
game:setMode(preferred_mode)
game.current_state = Intro(game.startMenu)
game.playMusic(game.sounds.music[1])
--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)
dt = 0.015
if not game.current_state then return end
if not game.stopped then
game:update(dt)
tween.update(dt)
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
function openURL(url)
if love._os == 'OS X' then
os.execute('open "' .. url .. '"')
elseif love._os == 'Windows' then
os.execute('start "' .. url .. '"')
elseif love._os == 'Linux' then
os.execute('xdg-open "' .. url .. '"')
end
end