function init(self) sprite.play_flipbook("#sprite", hash("curse")) self.velocity = vmath.vector3(0, 0, 0) self.direction = vmath.vector3(-1, 0, 0) self.speed = 250 self.gravity = -5000 self.angle = 0 self.amulet_visible = false self.testing_amulet = false self.dying = false self.dying_timer = 1 self.paused = false end function final(self) print ("Curse dead") end function update(self, dt) if not self.paused then if self.dying then self.dying_timer = self.dying_timer - dt if self.dying_timer < 0 then msg.post(self.creator, "curse_deleted") end end if self.deleted then return end self.velocity.x = self.direction.x * self.speed local pos = go.get_position() pos = pos + self.velocity * dt if pos.x < 24 or pos.y < 0 then self.deleted = true msg.post(self.creator, "curse_deleted") elseif pos.x > 1030 then pos.x = 1030 end if not self.deleted then local centre = vmath.vector3(pos.x, pos.y, 0) local platform = pos + vmath.vector3(0, -20, 0) local platform_result = physics.raycast(centre, platform, { hash("platform") }) if platform_result then local point = platform_result.position - pos if platform_result.normal.x <= 0 then self.direction.x = -1 else self.direction.x = 1 end self.grounded = true self.velocity.y = 0 if point.y > -20 then pos.y = pos.y + (point.y + 20) end else self.grounded = false end if not self.grounded then self.velocity.y = self.velocity.y + self.gravity * dt end go.set_position(pos) local angle = math.rad(self.angle) local rot = vmath.quat_rotation_z(angle) go.set_rotation(rot) self.angle = self.angle + (self.direction.x * -12) end end end function on_message(self, message_id, message, sender) if message_id == hash("contact_point_response") then if message.group == hash("holding_amulet") then if self.testing_amulet == false then msg.post("/holding_amulet#holdingamulet", "testing_amulet") self.testing_amulet = true end end end if message_id == hash("visible") then self.amulet_visible = true end if message_id == hash("testing_amulet_response") then if message.visible == true then sprite.play_flipbook("#sprite", hash("explosion")) self.deleted = true self.dying = true msg.post("/player#player", "add 100 points") end end if message_id == hash("dying") then msg.post(sender, ("curse_dying_reply"), {dying = self.dying}) end if message_id == hash("pause") then self.paused = true end if message_id == hash("unpause") then self.paused = false end if message_id == hash("creator") then self.creator = message.creator end end @main/curse.script"