Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- go.property("speed", 6)
- local grid = 460
- local platform_heights = { 100, 200, 350 }
- local coins = 3
- function init(self)
- self.gridw = 0
- self.spawns = {}
- end
- function update(self, dt)
- self.gridw = self.gridw + self.speed
- if self.gridw >= grid then
- self.gridw = 0
- -- Maybe spawn a platform at random height
- if math.random() > 0.2 then
- local h = platform_heights[math.random(#platform_heights)]
- local f = "#platform_factory"
- local coins = coins
- if math.random() > 0.5 then
- f = "#platform_long_factory"
- coins = coins * 2 -- Twice the number of coins on long platforms
- end
- local p = factory.create(f, vmath.vector3(1600, h, 0), nil, {}, 0.6)
- msg.post(p, "set_speed", { speed = self.speed })
- msg.post(p, "create_coins", { coins = coins })
- table.insert(self.spawns, p)
- end
- end
- end
- function on_message(self, message_id, message, sender)
- if message_id == hash("reset") then
- -- Tell the hero to reset.
- msg.post("hero#script", "reset")
- -- Delete all platforms
- for i,p in ipairs(self.spawns) do
- go.delete(p)
- end
- self.spawns = {}
- elseif message_id == hash("delete_spawn") then
- for i,p in ipairs(self.spawns) do
- if p == message.id then
- table.remove(self.spawns, i)
- go.delete(p)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement