-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
129 lines (108 loc) · 3.07 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
-- デバッグモード
local debugMode = true
-- フォーカス
local pauseOnUnfocus = true
local focused = true
local screenshot
-- スクリーンショット保存先
local screenshotDirectory = 'screenshot'
-- アプリケーション
local application = (require 'Game')()
application:setDebugMode(debugMode)
-- 読み込み
function love.load()
-- ランダムシードの設定
love.math.setRandomSeed(love.timer.getTime())
-- スクリーンショット保存先の用意
if #screenshotDirectory > 0 then
local dir = love.filesystem.getInfo(screenshotDirectory, 'directory')
if dir == nil then
love.filesystem.createDirectory(screenshotDirectory)
end
end
end
-- 更新
function love.update(dt)
if focused or not pauseOnUnfocus then
application:update(dt)
end
end
-- 描画
function love.draw()
if (focused or screenshot == nil) or not pauseOnUnfocus then
-- 画面のリセット
love.graphics.reset()
-- ゲーム描画
application:draw()
elseif screenshot then
-- スクリーンショットを描画
love.graphics.draw(screenshot)
end
end
-- キー入力
function love.keypressed(key, scancode, isrepeat)
if key == 'escape' then
-- 終了
love.event.quit()
elseif key == 'printscreen' then
-- スクリーンショット
love.graphics.captureScreenshot((screenshotDirectory .. '/') .. os.time() .. '.png')
elseif key == 'f5' then
-- リスタート
love.event.quit('restart')
elseif key == 'f12' then
-- デバッグモード切り替え
debugMode = not debugMode
-- アプリケーションのデバッグモード切り替え
application:setDebugMode(debugMode)
else
-- アプリケーションへ渡す
application:keypressed(key, scancode, isrepeat)
end
end
-- キー離した
function love.keyreleased(...)
application:keyreleased(...)
end
-- マウス入力
function love.mousepressed(...)
application:mousepressed(...)
end
-- マウス離した
function love.mousereleased(...)
application:mousereleased(...)
end
-- マウス移動
function love.mousemoved(...)
application:mousemoved(...)
end
-- マウスホイール
function love.wheelmoved(...)
application:wheelmoved(...)
end
-- テキスト入力
function love.textinput(...)
application:textinput(...)
end
-- フォーカス
function love.focus(f)
focused = f
if not pauseOnUnfocus then
-- フォーカスがない時にポーズしない
elseif not f then
-- フォーカスを失ったので、スクリーンショット撮影
love.graphics.captureScreenshot(
function (imageData)
screenshot = love.graphics.newImage(imageData)
end
)
elseif screenshot then
-- フォーカスが戻ったので、スクリーンショット開放
screenshot:release()
screenshot = nil
end
end
-- リサイズ
function love.resize(...)
application:resize(...)
end