function init(self) msg.post(".", "acquire_input_focus") self.timer = 0 self.curse_created = false self.timeout = 2.0 self.curse_count = 0 self.curses = {} self.amulet_count = 0 self.amulets = {} self.mummy_timer = 0 self.paused = false createamulets(self) msg.post("level1:/pause#sprite", "disable") end function createamulets(self) local positions = { vmath.vector3(800,75,0.3), vmath.vector3(100,200,0.3), vmath.vector3(850,325,0.3), vmath.vector3(400,450,0.3), vmath.vector3(300,580,0.3), vmath.vector3(600,600,0.3), } local props = { [hash("/amulets#level1")] = { creator = msg.url() } } for loop=1,5,1 do local ids = collectionfactory.create("amulets#amulet_factory", positions[loop], nil, props) local amulet_id = ids[hash("/amulets.go")] table.insert(self.amulets, amulet_id) end end function update(self, dt) if not self.paused then self.timer = self.timer + dt if self.timer >= self.timeout then self.timer = 0 self.curse_created = false end self.mummy_timer = self.mummy_timer - dt if self.mummy_timer < 0 then sprite.play_flipbook("mummy#still", hash("stillmummy")) msg.post("mummy#curse", "disable") msg.post("mummy#still", "enable") end if not self.curse_created then self.curse_created = true self.timeout = math.random() * 2 + 2 self.mummy_timer = 0.5 sprite.play_flipbook("mummy#curse", hash("cursemummy")) msg.post("mummy#curse", "enable") msg.post("mummy#still", "disable") local props = { [hash("/curses#level1")] = { creator = msg.url() } } local ids = collectionfactory.create("curses#curse_factory", vmath.vector3(900,560,0.0), nil, props) local curse_id = ids[hash("/curses.go")] table.insert(self.curses, curse_id) self.curse_count = self.curse_count + 1 end end end function on_message(self, message_id, message, sender) if message_id == hash("curse_deleted") then for i, id in ipairs(self.curses) do local id_url = msg.url(id) if id_url.path == sender.path then print("Matched and removing:", id) go.delete(id) table.remove(self.curses, i) break end end self.curse_count = 0 for _ in pairs(self.curses) do self.curse_count = self.curse_count + 1 end print ("Curse removed, we now have " .. self.curse_count .. " curses left") end if message_id == hash("amulet_deleted") then for i, id in ipairs(self.amulets) do local id_url = msg.url(id) if id_url.path == sender.path then print("Matched and removing:", id) go.delete(id) table.remove(self.amulets, i) break end end self.amulet_count = 0 for _ in pairs(self.amulets) do self.amulet_count = self.amulet_count + 1 end print ("Amulet removed, we now have " .. self.amulet_count .. " amulets left") end end function on_input(self, action_id, action) if action_id == hash("escape") and action.pressed then msg.post("main:/controller#main", "escape") elseif action_id == hash("pause") and action.pressed then if not self.paused then self.paused = true msg.post("level1:/pause#sprite", "enable") msg.post("level1:/player#player", "pause") for i, id in ipairs(self.curses) do local id_url = msg.url(id) msg.post(id_url, "pause") end else self.paused = false msg.post("level1:/player#player", "unpause") for i, id in ipairs(self.curses) do local id_url = msg.url(id) msg.post(id_url, "unpause") msg.post("level1:/pause#sprite", "disable") end end end end @main/level1.script"