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
|
require "src.init"
local lg = love.graphics
function love.load()
main_init()
local scn = new_scene()
event_bind(scn.on_update, "Body", body_sys)
event_bind(scn.on_update, "Player", player_movement_sys)
event_bind(scn.on_update, "Sprite", sprite_anim_sys)
event_bind(scn.on_draw, "Sprite", sprite_draw_sys)
event_bind(scn.on_draw, "Tilemap", tilemap_draw_sys)
set_scene(scn)
new_player(100, 100)
box1 = phys.Box.new(20, 20, 16, 16, {
layers = {},
mask = { "hard" },
})
ground1 = phys.Box.new(5, 50, 64, 16, {})
ground2 = phys.Box.new(64 - 16, 50 + 16, 16, 64, {})
local tilemap = new_tilemap(64, 64)
scn.tilemap = tilemap
set_tile(tilemap, 0, 0, 1)
end
function love.update(dt)
local scn = get_current_scene()
assert(scn, "No scene set.")
fire_event(scn.on_update, dt)
box1:update(0, 5, dt)
flush_scene()
end
function love.draw(dt)
lg.origin()
lg.setCanvas(viewport)
lg.clear()
local scn = get_current_scene()
assert(scn, "No scene set.")
fire_event(scn.on_draw, dt)
-- TODO: Take care of weird displays
lg.setCanvas()
local scr_width, scr_height = lg.getDimensions()
WindowScale = min(scr_width / SCR_WIDTH, scr_height / SCR_HEIGHT)
lg.draw(
viewport,
scr_width / 2, scr_height / 2, 0,
WindowScale, WindowScale,
SCR_WIDTH / 2, SCR_HEIGHT / 2)
lg.print(tostring(love.timer.getFPS()))
input_step()
end
|