-
Notifications
You must be signed in to change notification settings - Fork 17
/
platformspawner.lua
56 lines (48 loc) · 1.16 KB
/
platformspawner.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
platformspawner = class("platformspawner")
function platformspawner:init(x, y, r)
self.x = x
self.y = y
self.dir = "up"
self.timer = 0
self.size = 3
self.speed = platformjustspeed
self.spawndelay = platformspawndelay
--Input list
self.r = {unpack(r)}
table.remove(self.r, 1)
table.remove(self.r, 1)
--DIRECTION
if #self.r > 0 then
self.dir = self.r[1]
table.remove(self.r, 1)
end
--SIZE
if #self.r > 0 then
self.size = tonumber(self.r[1])
table.remove(self.r, 1)
end
--SPEED
if #self.r > 0 then
self.speed = self.r[1]
table.remove(self.r, 1)
end
--SPAWNDELAY
if #self.r > 0 then
self.spawndelay = tonumber(self.r[1])
table.remove(self.r, 1)
end
end
function platformspawner:update(dt)
self.timer = self.timer + dt
if self.timer > self.spawndelay then
if self.dir == "up" then
table.insert(objects["platform"], platform:new(self.x, self.y+1, {0, 0, self.size, 0, 0, 0, self.speed}, "justup"))
else
table.insert(objects["platform"], platform:new(self.x, self.y-0.5, {0, 0, self.size, 0, 0, 0, self.speed}, "justdown"))
end
self.timer = self.timer - self.spawndelay
end
if self.x < xscroll - .5 then
return true
end
end