-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.lua
executable file
·237 lines (175 loc) · 4.94 KB
/
level.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
require 'assets.lua'
require 'line.lua'
require 'platform.lua'
require 'enemy.lua'
require 'group.lua'
require 'wall.lua'
require 'image.lua'
local g = love.graphics
local p = love.physics
local a = love.audio
Level = class('Level')
function Level:initialize()
-- self.platforms = nil
-- self.remove = nil
-- self.add = nil
--[[ self.w = w
self.h = h
self.player = Vector:new(20, 170)
world = p.newWorld(0, 0, w, h)
world:setGravity(0, 100)
world:setMeter(64)
world:setCallbacks(collisionBegin, collisionPersist, collisionEnd, nil)
self:addPlatform(0, 300, 500)
self:addPlatform(1100, 400, 400)
self:addPlatform(1300, 500, 300)
self:addPlatform(900, 100, 10, 300, 0, true, true)
self:addPlatform(650, 200, 10, 200, 0, true, true)
self.walls = Group:new()
self.walls:add(Wall:new(200, 350, 100, 10, math.pi/2, true))
self.walls:add(Wall:new(250, 400, 850))
self.walls:add(Wall:new(500, 300, 100))
self.walls:add(Wall:new(1500, 400, 100))
self.enemies = Group:new()
self.enemies:add(Enemy:new(400, 300))
self.enemies:add(Enemy:new(1400, 400))
local img = Assets.LoadImage('texture02.png')
self.postit = Image:new(img, 397, 6, 480, 475)
music = a.newSource('assets/sounds/level.ogg')
music:setVolume(0.8)
music:setLooping(true)
music:play()
]]--
local img = Assets.LoadImage('texture01.png')
self.exitImage = Image:new(img, 7, 526, 122, 91)
local img3 = Assets.LoadImage('texture03.png')
self.retryImage = Image:new(img3, 3, 653, 66, 66)
self.timeLine1 = Image:new(img3, 3, 817, 800, 69)
self.timeLine2 = Image:new(img3, 3, 817+74, 800, 69)
self.arrow = Image:new(img3, 3, 720, 66, 66)
-- self.exit = Rect:new(Vector:new(1200, 540), Vector:new(60, 60), 0,255,0,128)
end
function Level:addPlatform(x, y, w, h, mass, wall, vertical)
self.platforms = self.platforms or {}
self.platforms.size = self.platforms.size or 0
self.platforms.size = self.platforms.size + 1
self.platforms[ self.platforms.size ] = Platform:new(x,y,w, h, mass, wall, vertical)
end
function collisionBegin(a, b, contact)
if a and a.collisionBegin then
a:collisionBegin(b,contact)
end
if b and b.collisionBegin then
b:collisionBegin(a,contact)
end
end
function collisionPersist(a, b, contact)
if a and a.collisionPersist then
a:collisionPersist(b,contact)
end
if b and b.collisionPersist then
b:collisionPersist(a,contact)
end
end
function collisionEnd(a, b, contact)
if a and a.collisionEnd then
a:collisionEnd(b,contact)
end
if b and b.collisionEnd then
b:collisionEnd(a,contact)
end
end
function Level:atExit(pos)
return pos.x-100 > self.w
end
function Level:erase(line, width)
width = width or 40
self.remove = self.remove or {}
self.add = self.add or {}
local i = 1
local j = 1
for k, platform in ipairs(self.platforms) do
if platform.shape then
local cut, p1, p2 = platform:cut(line, width)
if cut then
platform.shape:setMask(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
self.remove[j] = platform
self.add[i] = p1
self.add[i+1] = p2
i = i + 2
j = j + 1
end
end
end
if self.blocks then
self.blocks:call('cut', line)
end
end
function Level:update(dt)
world:update(dt)
if self.remove then
for k, platform in ipairs(self.remove) do
platform:destroy()
end
self.remove = nil
end
if self.add then
for k, platform in ipairs(self.add) do
self.platforms.size = self.platforms.size + 1
self.platforms[ self.platforms.size ] = platform
end
self.add = nil
end
for k, platform in ipairs(self.platforms) do
platform:update(dt)
end
if self.enemies then
self.enemies:call('checkPlayer')
self.enemies:update(dt)
end
if self.walls then
self.walls:update(dt)
end
if self.blocks then
self.blocks:update(dt)
end
end
function Level:postitClose(pos)
local r = Rect:new(Vector:new(g.getWidth()/2 + self.postit.w/2 - 60, g.getHeight()/2 - self.postit.h/2 + 20), Vector:new(50, 50))
return r:contains(pos)
end
function Level:drawPostit()
self.postit:draw2(g.getWidth()/2 - self.postit.w/2, g.getHeight()/2 - self.postit.h/2)
end
function Level:drawRetry(x)
self.retryImage:draw2(30+x, 45)
end
function Level:retryTest(pos, x)
local r = Rect:new(Vector:new(30 + x, 45), Vector:new(self.retryImage.w, self.retryImage.h))
return r:contains(pos)
end
function Level:draw()
g.setColor(0,0,0,255)
self.exitImage:draw2(self.w - 150, 50)
if self.images then
self.images:call('draw2')
end
for k, platform in ipairs(self.platforms) do
platform:draw()
end
if self.walls then
self.walls:draw()
end
if self.enemies then
self.enemies:draw()
end
if self.blocks then
self.blocks:draw()
end
if self.arrowX then
-- self.arrow:draw2(self.arrowX, g.getHeight() - 150, self.arrow.w, self.arrow.h, 255, 255, 255, 150)
end
self.timeLine1:draw2(0, g.getHeight() - self.timeLine1.h - 3, 800, self.timeLine1.h, 255, 255, 255, 180)
self.timeLine2:draw2(800, g.getHeight() - self.timeLine2.h - 3, 800, self.timeLine2.h, 255, 255, 255, 180)
-- self.exit:draw()
end