project/build/default_html5/main/level2.scriptc
2025-08-25 01:59:20 +01:00

155 lines
No EOL
3.5 KiB
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

ñ
Ù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("level2:/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),
}
for loop=1,5,1 do
local ids = collectionfactory.create("amulets#amulet_factory", positions[loop], nil)
local amulet_id = ids[hash("/amulets.go")]
table.insert(self.amulets, amulet_id)
local init_table = { creator = msg.url() }
msg.post(amulet_id, "creator", init_table)
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 ids = collectionfactory.create("curses#curse_factory", vmath.vector3(900,560,0.0), nil)
local curse_id = ids[hash("/curses")]
table.insert(self.curses, curse_id)
local msg_table = { creator = msg.url() }
msg.post(curse_id, "creator", msg_table)
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("/pause#sprite", "enable")
msg.post("/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("/player#player", "unpause")
for i, id in ipairs(self.curses) do
local id_url = msg.url(id)
msg.post(id_url, "unpause")
msg.post("/pause#sprite", "disable")
end
end
end
end
@main/level2.script"