-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
72 lines (63 loc) · 1.75 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
globals = {}
globals.logLevel = 'debug'
globals.timer = require('timer')
globals.assets = require('assets')
globals.conf = require('conf')
globals.scaleMouse = function (x, y)
return (x - globals.view.x) / globals.view.scale,
(y - globals.view.y) / globals.view.scale
end
local game = require('game'); globals.game = game
-- Function to initialize game state
-- Put config parsing, state initialization etc. here
function love.load()
globals.view = {
scale = 1,
x = 0,
y = 0,
}
globals.assets.load()
game.load()
globals.canvas = love.graphics.newCanvas()
end
-- Function to render the game screen
-- Parse game state and construct the screen here
function love.draw()
love.graphics.setCanvas(globals.canvas)
love.graphics.clear()
game.draw()
love.graphics.setCanvas()
love.graphics.draw(globals.canvas, globals.view.x, globals.view.y, 0,
globals.view.scale)
end
-- Function to manipulate game state at each frame
-- Put game strategy here
function love.update(timeSinceUpdate)
globals.timer.update(timeSinceUpdate)
game.update()
end
function love.keypressed(key, unicode)
game.event.push('keyinput', { key, unicode })
end
function love.textinput(text)
game.event.push('textinput', { text })
end
function love.mousepressed(x, y, button)
x, y = globals.scaleMouse(x, y)
game.event.push('mousepress', { x, y, button })
end
function love.resize(width, height)
local function min(a, b)
if a > b then
return b
else
return a
end
end
local scale = min(width / 800, height / 600)
globals.view = {
scale = scale,
x = (width - (800 * scale)) / 2,
y = (height - (600 * scale)) / 2,
}
end