forked from alesan99/mari0_ae
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatformspawner.lua
43 lines (37 loc) · 974 Bytes
/
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
platformspawner = class:new()
function platformspawner:init(x, y, direction, size)
self.x = x
self.y = y
self.direction = direction
self.timer = 0
self.size = size
self.speed = platformjustspeed
self.delay = platformspawndelay
if type(size) == "string" then
local v = size:split("|")
self.size = tonumber(v[1])
self.speed = tonumber(v[2])
self.delay = tonumber(v[3])
if v[4] ~= nil then
self.direction = v[4]
end
end
end
function platformspawner:update(dt)
self.timer = self.timer + dt
if self.timer > self.delay then
if self.direction == "up" then
local obj = platform:new(self.x, self.y+1, "justup", self.size)
obj.speedy = -self.speed
table.insert(objects["platform"], obj)
else
local obj = platform:new(self.x, self.y-0.5, "justdown", self.size)
obj.speedy = self.speed
table.insert(objects["platform"], obj)
end
self.timer = self.timer - self.delay
end
if self.x < xscroll - .5 then
return true
end
end