-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
59 lines (50 loc) · 1.49 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
require ("tiolved")
function love.load()
local t=love.timer.getTime()
-- parsering tmx file to a lua table
map=love.filesystem.load("source/orthogonal.lua")()
tloadmap=" time to load map="..love.timer.getTime()-t
-- creation of the gid, a local object full of data
local gid=tiolved.gid(map,"source/")
-- creation of tileset, an object that animate tile (tileset:update(dt))
-- and draw tile stored in spritebatch (tileset:draw())
-- use tileset:add(...) to add tile in spritebatch
tileset=tiolved.tileset(gid,map)
-- interpretation of interpreted layers
local toremove={} -- you must not remove in an array while looping in it
for i,v in ipairs (map.layers) do
if v.name=="collision" then
-- create.collision(v)
table.insert(toremove,i)
end
end
for _,v in ipairs(toremove) do
table.remove(map.layers,v)
end
-- rendering of drawned layers
-- this object draws tile of layers in tileset spritebatch
-- ( use layers:draw() )
layers=tiolved.layers(map,tileset)
-- useful function
toMap,toRender=tiolved.usefulfunc(map)
end
function love.update(dt)
tileset:update(dt)
x=love.mouse:getX()
y=love.mouse:getY()
xmap,ymap=toMap(x,y)
xrender,yrender=toRender(xmap,ymap)
if love.keyboard.isDown("escape") then
love.event.quit()
end
end
function love.draw()
layers:draw() -- must be call before tileset:draw()
tileset:draw()
love.graphics.print(
"x="..x..", y="..y..
"\nxmap="..xmap..", ymap="..ymap..
"\nxrender="..xrender..", yrender="..yrender..
"\n"..tloadmap
)
end