forked from Kadoba/Advanced-Tiled-Loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
147 lines (129 loc) · 2.74 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
function love.load()
tidal = require 'src'
function loadmap(filename,chunksize)
if chunksize then
loading = true
-- proxy methods return self
proxy = tidal.load(filename,chunksize)
:onLoad(function(newmap)
map = newmap
loading = false
-- Reset scale/position/speed
x,y = 0,0
scale= 1
speed= defaultspeed
end)
:onError(function(err)
error(err)
end)
else
proxy = nil
loading= false
map = assert(tidal.load(filename))
-- Reset scale/position/speed
x,y = 0,0
scale= 1
speed= defaultspeed
end
end
-- Cycle through these maps
list = {
'assets/desert.tmx',
'assets/stagmap.tmx',
'assets/isomap.tmx',
}
list_i = 1
show_help = true
loading = false
-- Affects map presentation
x,y = 0,0
scale = 1
defaultspeed= 350
speed = defaultspeed
-- affects draw range
draw_all = true
padding = -70
wx,wy,ww,wh = 0,0,800,600
loadmap( list[list_i] )
end
function love.keypressed(k)
if k == ' ' or k == 'f2' then
list_i = list_i + 1
list_i = list_i > #list and 1 or list_i
end
if k == ' ' then
loadmap( list[list_i], 10 )
end
if k == 'f2' then
loadmap( list[list_i])
end
if k == 'tab' then
draw_all = not draw_all
if draw_all then
map:setDrawRange()
end
end
if k == 'f1' then
show_help = not show_help
end
end
function love.mousepressed(x,y,b)
if b == 'wu' then
scale = scale * 1.2
speed = speed / 1.2
end
if b == 'wd' then
scale = scale / 1.2
speed = speed * 1.2
end
end
function love.update(dt)
if love.keyboard.isDown 'left' then
x = x + dt * -speed
end
if love.keyboard.isDown 'right' then
x = x + dt * speed
end
if love.keyboard.isDown 'up' then
y = y + dt * -speed
end
if love.keyboard.isDown 'down' then
y = y + dt * speed
end
if proxy then proxy:update() end
if map then
if not draw_all then
map:autoDrawRange(x,y, scale, padding)
end
map:update(dt)
end
end
function love.draw()
love.graphics.push()
love.graphics.translate(400,300) -- center the map
love.graphics.scale(scale)
if map then
map:draw(-x,-y)
end
love.graphics.pop()
if not draw_all then
love.graphics.rectangle('line',wx-padding,wy-padding,ww+padding*2,wh+padding*2)
end
fps = love.timer.getFPS()
if show_help then
local msg = {
'fps: '..fps,
'map name: '..list[list_i],
'scale: '..scale,
'Draw limit: '..tostring(not draw_all),
'Press f1 to toggle help view',
'Press tab to toggle draw control',
'Press space to load map asynchronously',
'Press f2 to load map synchronously',
'Arrow keys to move, mouse wheel to zoom',
'Loading: '..tostring(loading),
}
local complete_msg = table.concat(msg,'\n')
love.graphics.print( complete_msg ,0,0)
end
end