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
|
require "src.init"
local lg = love.graphics
lg.setLineStyle("rough")
function love.load()
main_init()
local scn = new_scene()
event_bind(scn.on_update, "Body", body_sys)
event_bind(scn.on_update, "Player", player_update_sys)
event_bind(scn.on_update, "State_Machine", state_update_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)
event_bind(scn.on_update, "Room_Editor", room_editor_ui_sys)
event_bind(scn.on_ui, "Room_Editor", tile_place_sys)
event_bind(scn.on_draw, "Editor_Entity", draw_editor_entity_sys)
event_bind(scn.on_ui, "Editor_Entity", editor_entity_ui_sys)
set_scene(scn)
local tilemap = new_tilemap(64, 64)
scn.tilemap = tilemap
for x=2, 12 do
set_tile(tilemap, x, 10, 1)
end
player = new_player(100, 100)
local room_editor = new_entity()
add_comp(room_editor, "Room_Editor")
end
function love.update(dt)
local scn = get_current_scene()
assert(scn, "No scene set.")
fire_event(scn.on_update, dt)
flush_scene()
end
function love.draw(dt)
lg.origin()
lg.setCanvas({viewport, stencil=true})
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.setColor(1, 1, 1)
lg.draw(
viewport,
scr_width / 2, scr_height / 2, 0,
WindowScale, WindowScale,
SCR_WIDTH / 2, SCR_HEIGHT / 2)
im.begin_step()
fire_event(scn.on_ui)
im.draw()
im.end_step()
lg.print(tostring(love.timer.getFPS()))
-- lg.print("left "..tostring(player.box:touching_left()), 0, 20)
-- lg.print("right "..tostring(player.box:touching_right()), 0, 40)
-- lg.print("horizontal "..tostring(player.box:touching_horizontal()), 0, 60)
-- lg.print("up "..tostring(player.box:touching_up()), 0, 80)
-- lg.print("down "..tostring(player.box:touching_down()), 0, 100)
-- lg.print("vertical "..tostring(player.box:touching_vertical()), 0, 120)
-- lg.print("any "..tostring(player.box:touching()), 0, 140)
input_step()
end
|