1380 lines
62 KiB
Lua
1380 lines
62 KiB
Lua
-- Paste into the Roblox Studio Command Bar (Edit mode) to build or rebuild Workspace.PopItObstacleCourse.
|
||
-- Builds / rebuilds Workspace.PopItObstacleCourse (10 pop-it rooms) behind the west end wall of the
|
||
-- North_W ("Candy party") room. Safe to re-run: the old course is replaced, the entrance is cut only once.
|
||
local ServerStorage = game:GetService("ServerStorage")
|
||
local CHS = game:GetService("ChangeHistoryService")
|
||
local SSS = game:GetService("ServerScriptService")
|
||
local StarterPlayer = game:GetService("StarterPlayer")
|
||
|
||
local LOG = {}
|
||
local function say(...) local t = {} for i, v in ipairs({ ... }) do t[i] = tostring(v) end table.insert(LOG, table.concat(t, " ")) end
|
||
|
||
local ENTRY_ZONE = "North_W"
|
||
local school = workspace:FindFirstChild("School")
|
||
assert(school, "Workspace.School not found")
|
||
local wallsFolder = school.Walls
|
||
|
||
------------------------------------------------------------------ 1. entry room + end wall
|
||
local minX, maxX, minZ, maxZ = math.huge, -math.huge, math.huge, -math.huge
|
||
for _, m in ipairs(school.PopIts:GetDescendants()) do
|
||
if m:IsA("Model") and m:GetAttribute("Zone") == ENTRY_ZONE then
|
||
local fr = m:FindFirstChild("RubberFrame")
|
||
local p = fr and fr.Position or m:GetPivot().Position
|
||
minX, maxX = math.min(minX, p.X), math.max(maxX, p.X)
|
||
minZ, maxZ = math.min(minZ, p.Z), math.max(maxZ, p.Z)
|
||
end
|
||
end
|
||
assert(minX < math.huge, "entry zone tiles not found")
|
||
local roomCenter = Vector3.new((minX + maxX) / 2, 0, (minZ + maxZ) / 2)
|
||
local roomSize = Vector3.new(maxX - minX + 7.5, 0, maxZ - minZ + 7.5)
|
||
local longAxis = roomSize.X >= roomSize.Z and Vector3.xAxis or Vector3.zAxis
|
||
local halfLen = (longAxis == Vector3.xAxis and roomSize.X or roomSize.Z) / 2
|
||
say(string.format("Entry room %s centre (%.1f, %.1f) size %.1f x %.1f, long axis %s", ENTRY_ZONE, roomCenter.X, roomCenter.Z, roomSize.X, roomSize.Z, longAxis == Vector3.xAxis and "X" or "Z"))
|
||
|
||
local function thinAxis(p)
|
||
local s = p.Size
|
||
if s.X <= s.Y and s.X <= s.Z then return p.CFrame.RightVector, s.X end
|
||
if s.Z <= s.Y then return p.CFrame.LookVector, s.Z end
|
||
return p.CFrame.UpVector, s.Y
|
||
end
|
||
|
||
local backup = ServerStorage:FindFirstChild("PopItCourse_EntranceBackup")
|
||
local entrance = backup and backup:FindFirstChild("OriginalWall")
|
||
local wallCF, wallSize
|
||
local FLOOR_TOP = 0.88
|
||
for _, f in ipairs(school.FloorCollider:GetChildren()) do FLOOR_TOP = f.Position.Y + f.Size.Y / 2 break end
|
||
|
||
-- course length (sum of rooms, see ROOMS below)
|
||
local ROOM_LEN = { 36, 40, 44, 48, 36, 56, 44, 40, 50, 48 }
|
||
local TOTAL = 0
|
||
for _, l in ipairs(ROOM_LEN) do TOTAL += l end
|
||
local HALFW = 15.75 -- outer half-width of the corridor (walls inner face at 14.25)
|
||
|
||
local function annexClear(origin, fwd)
|
||
local cf = CFrame.lookAt(origin, origin + fwd)
|
||
local centre = cf * CFrame.new(0, 22, -(0.5 + TOTAL / 2 + 1))
|
||
local hits = workspace:GetPartBoundsInBox(centre, Vector3.new(HALFW * 2 + 1, 60, TOTAL + 2), OverlapParams.new())
|
||
local bad = {}
|
||
for _, h in ipairs(hits) do
|
||
local existing = workspace:FindFirstChild("PopItObstacleCourse")
|
||
if h.Name ~= "Baseplate" and not (existing and h:IsDescendantOf(existing)) then
|
||
table.insert(bad, h:GetFullName())
|
||
end
|
||
end
|
||
return #bad == 0, bad
|
||
end
|
||
|
||
local origin, fwd
|
||
if entrance then
|
||
-- entrance already cut on a previous run: reuse stored geometry
|
||
wallCF, wallSize = entrance.CFrame, entrance.Size
|
||
fwd = backup:GetAttribute("Forward")
|
||
origin = backup:GetAttribute("Origin")
|
||
say("Entrance already exists (previous run) - reusing it")
|
||
else
|
||
local candidates = {}
|
||
for _, w in ipairs(wallsFolder:GetChildren()) do
|
||
if w.Name == "Wall" and w:IsA("BasePart") then
|
||
local n, th = thinAxis(w)
|
||
if math.abs(n:Dot(longAxis)) > 0.99 then
|
||
local rel = w.Position - roomCenter
|
||
local along = rel:Dot(longAxis)
|
||
local lateral = (rel - longAxis * along)
|
||
lateral = Vector3.new(lateral.X, 0, lateral.Z).Magnitude
|
||
if math.abs(math.abs(along) - halfLen) < 2 and lateral < 2 then
|
||
local out = longAxis * math.sign(along)
|
||
table.insert(candidates, { wall = w, out = out, th = th })
|
||
end
|
||
end
|
||
end
|
||
end
|
||
for _, c in ipairs(candidates) do
|
||
local o = Vector3.new(c.wall.Position.X, 0, c.wall.Position.Z) + c.out * (c.th / 2)
|
||
local ok, bad = annexClear(o, c.out)
|
||
say(string.format("End wall at (%.1f, %.1f) outward (%d,%d): %s", c.wall.Position.X, c.wall.Position.Z, c.out.X, c.out.Z, ok and "FREE" or ("blocked by " .. #bad .. " parts, e.g. " .. tostring(bad[1]))))
|
||
if ok and not origin then
|
||
origin, fwd, entrance = o, c.out, c.wall
|
||
wallCF, wallSize = c.wall.CFrame, c.wall.Size
|
||
end
|
||
end
|
||
if not origin then
|
||
return "ABORT: no end wall with free space behind it\n" .. table.concat(LOG, "\n")
|
||
end
|
||
end
|
||
|
||
local CCF = CFrame.lookAt(origin, origin + fwd) -- local -Z = forward (u), local X = right (v)
|
||
local function L(u, y, v) return CCF * CFrame.new(v, y, -u) end
|
||
local UP = Vector3.yAxis
|
||
|
||
local rec = CHS:TryBeginRecording("Build PopItObstacleCourse")
|
||
|
||
------------------------------------------------------------------ 2. cut the entrance (once)
|
||
local OPEN_HALF = 7.5 -- half width of the wall opening (jambs fill 5.9..7.5 -> 11.8 clear like other doors)
|
||
local OPEN_TOP = 19.12 -- opening height above the floor surface (header 17.52..19.12)
|
||
if not backup then
|
||
backup = Instance.new("Folder")
|
||
backup.Name = "PopItCourse_EntranceBackup"
|
||
backup:SetAttribute("Origin", origin)
|
||
backup:SetAttribute("Forward", fwd)
|
||
local orig = entrance:Clone()
|
||
orig.Name = "OriginalWall"
|
||
orig.Parent = backup
|
||
-- wall lateral axis = horizontal axis of the wall that is not the thin one
|
||
local n = thinAxis(entrance)
|
||
local lat = UP:Cross(n).Unit
|
||
local function latSize(p) return math.abs(p.CFrame:VectorToObjectSpace(lat).X) * p.Size.X + math.abs(p.CFrame:VectorToObjectSpace(lat).Y) * p.Size.Y + math.abs(p.CFrame:VectorToObjectSpace(lat).Z) * p.Size.Z end
|
||
local W = latSize(entrance)
|
||
local bottom = entrance.Position.Y - entrance.Size.Y / 2
|
||
local top = entrance.Position.Y + entrance.Size.Y / 2
|
||
local th = select(2, thinAxis(entrance))
|
||
local centre = Vector3.new(entrance.Position.X, 0, entrance.Position.Z)
|
||
local offset = (origin - centre):Dot(lat) -- 0 here: course centred on the room axis
|
||
local function piece(name, l0, l1, y0, y1)
|
||
local p = entrance:Clone()
|
||
p.Name = name
|
||
p.Size = Vector3.new(th, y1 - y0, l1 - l0)
|
||
p.CFrame = CFrame.lookAt(centre + lat * ((l0 + l1) / 2) + UP * ((y0 + y1) / 2), centre + lat * ((l0 + l1) / 2) + UP * ((y0 + y1) / 2) + lat) * CFrame.Angles(0, 0, 0)
|
||
-- lookAt makes local Z = -lat; size Z spans lateral, X spans thin axis
|
||
p.Size = Vector3.new(th, y1 - y0, l1 - l0)
|
||
p:SetAttribute("PopItCourseEntrance", true)
|
||
p.Parent = wallsFolder
|
||
return p
|
||
end
|
||
piece("Wall", -W / 2, offset - OPEN_HALF, bottom, top)
|
||
piece("Wall", offset + OPEN_HALF, W / 2, bottom, top)
|
||
piece("Lintel", offset - OPEN_HALF, offset + OPEN_HALF, FLOOR_TOP + OPEN_TOP, top)
|
||
entrance:Destroy()
|
||
-- skirting neon strip that runs across the new doorway
|
||
for _, s in ipairs(school.Lighting:GetChildren()) do
|
||
if s.Name == "SkirtNeon" and s:IsA("BasePart") then
|
||
local d = (s.Position - centre)
|
||
if math.abs(d:Dot(n)) < 2 and math.abs(d:Dot(lat) - offset) < latSize(s) / 2 then
|
||
local o = s:Clone() o.Name = "OriginalSkirt" o.Parent = backup
|
||
local sw = latSize(s)
|
||
local sc = (Vector3.new(s.Position.X, 0, s.Position.Z) - centre):Dot(lat)
|
||
for _, seg in ipairs({ { sc - sw / 2, offset - OPEN_HALF }, { offset + OPEN_HALF, sc + sw / 2 } }) do
|
||
if seg[2] - seg[1] > 0.2 then
|
||
local p = s:Clone()
|
||
local mid = (seg[1] + seg[2]) / 2
|
||
local pos = s.Position + lat * (mid - sc)
|
||
p.CFrame = CFrame.lookAt(pos, pos + lat)
|
||
p.Size = Vector3.new(s.Size.X <= s.Size.Z and s.Size.X or s.Size.Z, s.Size.Y, seg[2] - seg[1])
|
||
p:SetAttribute("PopItCourseEntrance", true)
|
||
p.Parent = school.Lighting
|
||
end
|
||
end
|
||
s:Destroy()
|
||
end
|
||
end
|
||
end
|
||
backup.Parent = ServerStorage
|
||
say("Entrance cut into the end wall; originals saved in ServerStorage.PopItCourse_EntranceBackup")
|
||
end
|
||
|
||
------------------------------------------------------------------ 3. course root
|
||
local old = workspace:FindFirstChild("PopItObstacleCourse")
|
||
if old then old:Destroy() say("Old PopItObstacleCourse removed (rebuild)") end
|
||
local course = Instance.new("Model")
|
||
course.Name = "PopItObstacleCourse"
|
||
course.ModelStreamingMode = Enum.ModelStreamingMode.Persistent
|
||
course:SetAttribute("CourseCF", CCF)
|
||
course:SetAttribute("Length", TOTAL)
|
||
course:SetAttribute("HalfWidth", 14.25)
|
||
course:SetAttribute("ReturnCF", CFrame.lookAt(origin - fwd * 12 + UP * FLOOR_TOP, origin + UP * FLOOR_TOP))
|
||
|
||
local SM = Enum.Material.SmoothPlastic
|
||
local PL = Enum.Material.Plastic
|
||
local NEON = Enum.Material.Neon
|
||
local WHITE = Color3.new(1, 1, 1)
|
||
local function rgb(r, g, b) return Color3.fromRGB(r, g, b) end
|
||
|
||
local function part(parent, name, cf, size, color, mat, opts)
|
||
local p = Instance.new("Part")
|
||
p.Name = name
|
||
p.Anchored = true
|
||
p.Size = size
|
||
p.CFrame = cf
|
||
p.Color = color or WHITE
|
||
p.Material = mat or SM
|
||
p.TopSurface = Enum.SurfaceType.Smooth
|
||
p.BottomSurface = Enum.SurfaceType.Smooth
|
||
if opts then for k, v in pairs(opts) do p[k] = v end end
|
||
p.Parent = parent
|
||
return p
|
||
end
|
||
local function deco(p) p.CanCollide = false p.CanQuery = false p.CanTouch = false p.CastShadow = false return p end
|
||
local function boxU(parent, name, u0, u1, v0, v1, y0, y1, color, mat, opts)
|
||
return part(parent, name, L((u0 + u1) / 2, (y0 + y1) / 2, (v0 + v1) / 2), Vector3.new(v1 - v0, y1 - y0, u1 - u0), color, mat, opts)
|
||
end
|
||
|
||
------------------------------------------------------------------ 4. pop-it tiles (clones of the game's own templates)
|
||
local templates, tplCount = {}, 0
|
||
for _, t in ipairs(ServerStorage.PopItTemplates:GetChildren()) do
|
||
local v = t:GetAttribute("ColorVariant")
|
||
if v and not templates[v] then templates[v] = t tplCount += 1 end
|
||
end
|
||
local CANDY = { "Coral", "Orange", "Yellow", "Lime", "Turquoise", "SkyBlue", "Blue", "Pink", "Purple" }
|
||
local SPOOKY = { rgb(140, 70, 215), rgb(125, 215, 45), rgb(75, 40, 120), rgb(170, 110, 240) }
|
||
local tileCount = 0
|
||
local function makeTile(parent, surfaceCF, scale, variant, recolor, moving)
|
||
local t = templates[variant] or templates.Pink or ServerStorage.PopItTemplates:GetChildren()[1]
|
||
local m = t:Clone()
|
||
m.Name = "PopIt"
|
||
if math.abs(scale - 1) > 1e-3 then m:ScaleTo(m:GetScale() * scale) end
|
||
local frame = m:FindFirstChild("RubberFrame")
|
||
local off = frame.CFrame:ToObjectSpace(m:GetPivot())
|
||
m:PivotTo(surfaceCF * CFrame.new(0, -0.33 * scale, 0) * CFrame.Angles(math.rad(90), 0, 0) * off)
|
||
for _, d in ipairs(m:GetDescendants()) do
|
||
if d:IsA("BasePart") then
|
||
d.Anchored = true
|
||
d.CanCollide = false
|
||
d.CanTouch = false
|
||
d.CanQuery = false
|
||
if recolor then d.Color = (d == frame) and recolor or recolor:Lerp(WHITE, 0.16) end
|
||
if moving and d.Name:match("^Bubble_") then d.Name = "M" .. d.Name end
|
||
end
|
||
end
|
||
m.Parent = parent
|
||
tileCount += 1
|
||
if tileCount % 25 == 0 then task.wait() end
|
||
return m
|
||
end
|
||
-- covers a sizeV x sizeU rectangle whose top-centre is surfaceCF with pop-its
|
||
local function popitSurface(parent, surfaceCF, sizeV, sizeU, palette, moving)
|
||
local small, large = math.min(sizeV, sizeU), math.max(sizeV, sizeU)
|
||
local nS = math.max(1, math.floor(small / 7.5 + 0.5))
|
||
local tile = small / nS
|
||
local nL = math.max(1, math.floor(large / tile + 0.5))
|
||
tile = math.min(tile, large / nL)
|
||
local nV, nU
|
||
if sizeV <= sizeU then nV, nU = nS, nL else nV, nU = nL, nS end
|
||
local sV, sU = sizeV / nV, sizeU / nU
|
||
local scale = tile / 7.5 * 0.985
|
||
local tiles = {}
|
||
for i = 1, nV do
|
||
for j = 1, nU do
|
||
local variant, recolor = palette(i, j)
|
||
local cf = surfaceCF * CFrame.new((i - (nV + 1) / 2) * sV, 0, -((j - (nU + 1) / 2) * sU))
|
||
table.insert(tiles, makeTile(parent, cf, scale, variant, recolor, moving))
|
||
end
|
||
end
|
||
return tiles
|
||
end
|
||
local function candyChecker(seed) return function(i, j) return CANDY[(i + j + (seed or 0)) % #CANDY + 1] end end
|
||
local function candyColumns(seed) return function(i, j) return CANDY[(i + (seed or 0)) % #CANDY + 1] end end
|
||
local function spookyChecker(seed) return function(i, j) return "Purple", SPOOKY[(i + j + (seed or 0)) % 2 + 1 + ((j % 3 == 0) and 2 or 0)] end end
|
||
local function single(v, c) return function() return v, c end end
|
||
-- block with pop-its on top (u/v local to the room offset)
|
||
local function popBlock(parent, name, u0, u1, v0, v1, y0, top, color, palette)
|
||
local b = boxU(parent, name, u0, u1, v0, v1, y0, top, color, PL)
|
||
popitSurface(parent, L((u0 + u1) / 2, top, (v0 + v1) / 2), v1 - v0, u1 - u0, palette)
|
||
return b
|
||
end
|
||
|
||
------------------------------------------------------------------ 5. themes, decor helpers
|
||
local THEMES = {
|
||
candy = { wall = rgb(205, 55, 165), jamb = rgb(180, 40, 145), neon = rgb(255, 95, 10), ceiling = rgb(110, 30, 105),
|
||
ground = rgb(235, 120, 195), pit = rgb(150, 40, 120), block = rgb(255, 170, 215), glow = rgb(255, 95, 10), glowCore = rgb(255, 177, 98),
|
||
cloud = rgb(255, 200, 235), puff = rgb(255, 216, 241), light = rgb(255, 190, 230),
|
||
bulbs = { rgb(255, 60, 150), rgb(0, 220, 255), rgb(120, 255, 80), rgb(255, 220, 40) } },
|
||
spooky = { wall = rgb(80, 35, 125), jamb = rgb(60, 25, 95), neon = rgb(120, 255, 40), ceiling = rgb(45, 20, 70),
|
||
ground = rgb(60, 30, 95), pit = rgb(35, 15, 55), block = rgb(110, 60, 170), glow = rgb(120, 255, 40), glowCore = rgb(194, 249, 111),
|
||
cloud = rgb(190, 150, 255), puff = rgb(215, 190, 255), light = rgb(200, 170, 255),
|
||
bulbs = { rgb(170, 60, 255), rgb(120, 255, 40), rgb(255, 140, 0), rgb(230, 230, 255) } },
|
||
}
|
||
local CEIL = 50
|
||
local BOTTOM = -6.05
|
||
|
||
-- props from the game (wall decorations), oriented like on the north wall
|
||
local PROP_SRC = {}
|
||
local northFace = -126.75
|
||
for _, m in ipairs(wallsFolder.Props:GetChildren()) do
|
||
if m:IsA("Model") and not PROP_SRC[m.Name] and m:GetPivot().Position.Z < -120 then PROP_SRC[m.Name] = m end
|
||
end
|
||
local Fo = CFrame.lookAt(Vector3.new(0, 0, northFace), Vector3.new(0, 0, northFace + 1))
|
||
local function prop(parent, name, u, y, side)
|
||
local src = PROP_SRC[name]
|
||
if not src then return end
|
||
local rel = Fo:ToObjectSpace(src:GetPivot())
|
||
rel = CFrame.new(0, 0, rel.Position.Z) * rel.Rotation
|
||
local wallPt = L(u, y, side * 14.25).Position
|
||
local inward = (CCF.RightVector * -side)
|
||
local m = src:Clone()
|
||
m:PivotTo(CFrame.lookAt(wallPt, wallPt + inward) * rel)
|
||
for _, d in ipairs(m:GetDescendants()) do if d:IsA("BasePart") then deco(d) d.Anchored = true end end
|
||
m.Parent = parent
|
||
return m
|
||
end
|
||
|
||
local function sign(parent, cf, text, sub, theme)
|
||
local p = deco(part(parent, "Sign", cf, Vector3.new(9, 6, 0.4), theme.jamb, SM))
|
||
local g = Instance.new("SurfaceGui")
|
||
g.Face = Enum.NormalId.Front
|
||
g.CanvasSize = Vector2.new(360, 240)
|
||
g.LightInfluence = 0
|
||
g.Parent = p
|
||
local function lbl(t, y, h, size, col)
|
||
local l = Instance.new("TextLabel")
|
||
l.BackgroundTransparency = 1
|
||
l.Size = UDim2.new(1, -20, h, 0)
|
||
l.Position = UDim2.new(0, 10, y, 0)
|
||
l.Font = Enum.Font.FredokaOne
|
||
l.TextScaled = true
|
||
l.Text = t
|
||
l.TextColor3 = col
|
||
local s = Instance.new("UIStroke") s.Thickness = 4 s.Color = rgb(60, 20, 70) s.Parent = l
|
||
l.Parent = g
|
||
end
|
||
lbl(text, 0.04, 0.6, 1, rgb(255, 235, 60))
|
||
if sub then lbl(sub, 0.66, 0.3, 1, WHITE) end
|
||
return p
|
||
end
|
||
|
||
local function doorFrame(parent, Ub, S, themeA, themeB)
|
||
boxU(parent, "Jamb", Ub - 1.55, Ub + 1.55, -OPEN_HALF, -5.9, S, S + OPEN_TOP, themeB.jamb, PL)
|
||
boxU(parent, "Jamb", Ub - 1.55, Ub + 1.55, 5.9, OPEN_HALF, S, S + OPEN_TOP, themeB.jamb, PL)
|
||
boxU(parent, "Header", Ub - 1.55, Ub + 1.55, -OPEN_HALF, OPEN_HALF, S + OPEN_TOP - 1.6, S + OPEN_TOP, themeB.jamb, PL)
|
||
for _, side in ipairs({ -1, 1 }) do
|
||
local th = side < 0 and themeA or themeB
|
||
local uc = Ub + side * 1.7
|
||
local top = math.min(S + OPEN_TOP + 1.4, CEIL - 0.05)
|
||
deco(boxU(parent, "DoorNeon", uc - 0.15, uc + 0.15, -OPEN_HALF - 1.4, OPEN_HALF + 1.4, top - 1.4, top, th.neon, NEON))
|
||
deco(boxU(parent, "DoorNeon", uc - 0.15, uc + 0.15, -OPEN_HALF - 1.4, -OPEN_HALF, S, top, th.neon, NEON))
|
||
deco(boxU(parent, "DoorNeon", uc - 0.15, uc + 0.15, OPEN_HALF, OPEN_HALF + 1.4, S, top, th.neon, NEON))
|
||
end
|
||
end
|
||
-- wall across the corridor at u = Ub, with a doorway whose floor is at S (nil = solid)
|
||
local function crossWall(parent, Ub, S, themeA, themeB)
|
||
local c = themeB.wall
|
||
if not S then
|
||
boxU(parent, "Wall", Ub - 0.75, Ub + 0.75, -HALFW, HALFW, BOTTOM, CEIL, c, PL)
|
||
return
|
||
end
|
||
boxU(parent, "Wall", Ub - 0.75, Ub + 0.75, -HALFW, -OPEN_HALF, BOTTOM, CEIL, c, PL)
|
||
boxU(parent, "Wall", Ub - 0.75, Ub + 0.75, OPEN_HALF, HALFW, BOTTOM, CEIL, c, PL)
|
||
boxU(parent, "Threshold", Ub - 0.75, Ub + 0.75, -OPEN_HALF, OPEN_HALF, BOTTOM, S, c, PL)
|
||
if S + OPEN_TOP < CEIL then boxU(parent, "Lintel", Ub - 0.75, Ub + 0.75, -OPEN_HALF, OPEN_HALF, S + OPEN_TOP, CEIL, c, PL) end
|
||
doorFrame(parent, Ub, S, themeA, themeB)
|
||
end
|
||
|
||
local function cloud(parent, u, v, y, theme, size)
|
||
local s = size or 2
|
||
local m = Instance.new("Model") m.Name = "Cloud"
|
||
local c = deco(part(m, "CloudLamp", L(u, y, v), Vector3.new(4, 4, 4) * s, theme.cloud, SM, { Shape = Enum.PartType.Ball }))
|
||
local offs = { { 0.74, -0.16, 2.28, 2.9 }, { -1.94, 0.2, 1.41, 3.3 }, { -1.94, 0.5, -1.41, 3.1 }, { 0.74, 0.22, -2.28, 3.0 }, { 2.4, -0.3, 0, 3.2 }, { 0, 0.9, 0, 3.4 } }
|
||
for _, o in ipairs(offs) do
|
||
deco(part(m, "Puff", L(u, y, v) * CFrame.new(o[1] * s, o[2] * s, o[3] * s), Vector3.new(o[4], o[4], o[4]) * s, theme.puff, SM, { Shape = Enum.PartType.Ball }))
|
||
end
|
||
deco(part(m, "String", L(u, (y + CEIL) / 2 + s, v), Vector3.new(0.15, CEIL - y - 2 * s, 0.15), WHITE, SM))
|
||
local l = Instance.new("PointLight") l.Brightness = 1.4 l.Range = 34 l.Color = theme.light l.Shadows = false l.Parent = c
|
||
m.Parent = parent
|
||
end
|
||
|
||
local function garland(parent, U0, U1, theme)
|
||
local f = Instance.new("Folder") f.Name = "Garland" f.Parent = parent
|
||
for _, side in ipairs({ -1, 1 }) do
|
||
local k = 0
|
||
for u = U0 + 2, U1 - 2, 3.5 do
|
||
k += 1
|
||
local seg = ((u - U0) % 14) / 14
|
||
local y = 46.4 - 1.5 * math.sin(seg * math.pi)
|
||
deco(part(f, "Bulb", L(u, y, side * 13.5), Vector3.new(1.3, 1.3, 1.3), theme.bulbs[k % #theme.bulbs + 1], NEON, { Shape = Enum.PartType.Ball }))
|
||
end
|
||
-- glow strip along the top of the side wall, same look as the school's GlowStrip
|
||
deco(boxU(f, "GlowHalo", U0, U1, side * 14.1 - 0.1, side * 14.1 + 0.1, 46.5, 49.9, theme.glow, NEON, { Transparency = 0.72 }))
|
||
deco(boxU(f, "GlowCore", U0, U1, side * 13.95 - 0.1, side * 13.95 + 0.1, 47.9, 48.5, theme.glowCore, NEON))
|
||
end
|
||
end
|
||
|
||
local function shell(room, U0, U1, theme, groundTop, groundColor)
|
||
boxU(room, "Ground", U0, U1, -HALFW, HALFW, BOTTOM, groundTop, groundColor or theme.ground, PL)
|
||
boxU(room, "Wall", U0, U1, -HALFW, -14.25, BOTTOM, CEIL, theme.wall, PL)
|
||
boxU(room, "Wall", U0, U1, 14.25, HALFW, BOTTOM, CEIL, theme.wall, PL)
|
||
boxU(room, "Ceiling", U0, U1, -HALFW, HALFW, CEIL, CEIL + 1.5, theme.ceiling, PL)
|
||
garland(room, U0, U1, theme)
|
||
cloud(room, (U0 + U1) / 2, 0, 43, theme, 1.8)
|
||
end
|
||
|
||
local CHECKPOINT_TRIGGER_H = 9
|
||
local function checkpoint(room, idx, U0, u0, u1, S, theme)
|
||
local trig = boxU(room, "CheckpointTrigger", U0 + u0, U0 + u1, -14.2, 14.2, S, S + CHECKPOINT_TRIGGER_H, WHITE, SM,
|
||
{ Transparency = 1, CanCollide = false, CanQuery = false, CanTouch = true, CastShadow = false })
|
||
trig:SetAttribute("Index", idx)
|
||
-- flag on the left wall side
|
||
local flag = Instance.new("Model") flag.Name = "CheckpointFlag" flag:SetAttribute("Index", idx)
|
||
local base = L(U0 + (u0 + u1) / 2, S, -12.5)
|
||
deco(part(flag, "Pole", base * CFrame.new(0, 4, 0), Vector3.new(0.4, 8, 0.4), WHITE, SM))
|
||
deco(part(flag, "Knob", base * CFrame.new(0, 8.2, 0), Vector3.new(0.9, 0.9, 0.9), rgb(255, 220, 40), NEON, { Shape = Enum.PartType.Ball }))
|
||
deco(part(flag, "Cloth", base * CFrame.new(1.6, 6.8, 0), Vector3.new(3, 2, 0.15), rgb(255, 255, 255), SM))
|
||
deco(part(flag, "Base", base * CFrame.new(0, 0.35, 0), Vector3.new(1.6, 0.5, 1.6), theme.jamb, SM))
|
||
flag.Parent = room
|
||
room:SetAttribute("SpawnCF", L(U0 + (u0 + u1) / 2, S, 0))
|
||
return trig
|
||
end
|
||
|
||
local function kin(m, kind, attrs)
|
||
m:SetAttribute("Kind", kind)
|
||
for k, v in pairs(attrs) do m:SetAttribute(k, v) end
|
||
local n = 0
|
||
for _, d in ipairs(m:GetDescendants()) do if d:IsA("BasePart") then n += 1 end end
|
||
m:SetAttribute("PartCount", n)
|
||
m:AddTag("PopCourseKinematic")
|
||
end
|
||
|
||
------------------------------------------------------------------ 6. rooms
|
||
local TITLES = { "Радужная лестница", "Мост и молоты", "Горка и шар", "Лавовые островки", "Конфетная вертушка",
|
||
"Летающие платформы", "Зефирные прессы", "Лифты-привидения", "Исчезающие плитки", "Батут и финиш" }
|
||
local G = FLOOR_TOP
|
||
local L1 = G + 7.2 -- after the stairs
|
||
local L3 = L1 + 9.6 -- after the slide
|
||
local L8 = L3 + 12 -- after the lifts
|
||
-- floor level at each boundary B0..B10
|
||
local LEVEL = { [0] = G, L1, L1, L3, L3, L3, L3, L3, L8, L8, nil }
|
||
|
||
local U = { [0] = 0 }
|
||
for i = 1, 10 do U[i] = U[i - 1] + ROOM_LEN[i] end
|
||
local function themeOf(i) return i <= 6 and THEMES.candy or THEMES.spooky end
|
||
|
||
-- entrance frame + threshold in the existing wall (owned by the course model)
|
||
do
|
||
local ent = Instance.new("Folder") ent.Name = "Entrance" ent.Parent = course
|
||
local th = wallSize and math.min(wallSize.X, wallSize.Z) or 1.5
|
||
boxU(ent, "Threshold", -th, 0.05, -OPEN_HALF, OPEN_HALF, G - 2, G, THEMES.candy.jamb, PL)
|
||
doorFrame(ent, -th / 2, G, THEMES.candy, THEMES.candy)
|
||
sign(ent, L(-th - 0.3, G + 24, 0) * CFrame.Angles(0, math.pi, 0), "Поп-ит трасса", "10 испытаний →", THEMES.candy)
|
||
end
|
||
|
||
local rooms = {}
|
||
for i = 1, 10 do
|
||
local r = Instance.new("Model")
|
||
r.Name = string.format("Room%02d", i)
|
||
r:SetAttribute("Index", i)
|
||
r:SetAttribute("Title", TITLES[i])
|
||
r:SetAttribute("U0", U[i - 1])
|
||
r:SetAttribute("U1", U[i])
|
||
r.Parent = course
|
||
rooms[i] = r
|
||
local th = themeOf(i)
|
||
-- cross wall at the start of the room (B_{i-1}); B0 is the existing school wall
|
||
if i > 1 then crossWall(r, U[i - 1], LEVEL[i - 1], themeOf(i - 1), th) end
|
||
if i == 10 then crossWall(r, U[10], nil, th, th) end
|
||
-- number sign on the right wall near the room start
|
||
sign(r, L(U[i - 1] + 8, (LEVEL[i - 1] or L8) + 11, 14.05) * CFrame.Angles(0, math.rad(90), 0), tostring(i), TITLES[i], th)
|
||
-- wall props: 2 per side, high on the walls
|
||
local names = i <= 6 and { "Lollipop", "CandyCane", "Donut", "IceCream", "Gift", "Peppermint", "WrappedCandy", "Star" } or { "Ghost", "Pumpkin", "Bat", "Web", "SpookyCandy", "Ghost", "HangingSpider", "Bat" }
|
||
local len = ROOM_LEN[i]
|
||
for k, side in ipairs({ -1, 1 }) do
|
||
prop(r, names[(i * 3 + k) % #names + 1], U[i - 1] + len * 0.3, 37, side)
|
||
prop(r, names[(i * 3 + k + 3) % #names + 1], U[i - 1] + len * 0.72, 33, side)
|
||
end
|
||
end
|
||
|
||
-- shorthand inside a room: a(u) -> absolute u
|
||
local function A(i) local U0 = U[i - 1] return function(u) return U0 + u end end
|
||
|
||
---------------- Room 1: rainbow stairs (ground level -> L1)
|
||
do
|
||
local i, r, th = 1, rooms[1], THEMES.candy
|
||
local a = A(i)
|
||
shell(r, a(0), a(36), th, G)
|
||
popitSurface(r, L(a(4), G, 0), 28.5, 8, candyChecker(0))
|
||
local steps = { { 8, 13 }, { 13, 18 }, { 18, 23 }, { 23, 36 } }
|
||
for k, s in ipairs(steps) do
|
||
popBlock(r, "Step", a(s[1]), a(s[2]), -14.25, 14.25, G - 1, G + 1.8 * k, th.block, candyColumns(k))
|
||
end
|
||
checkpoint(r, 1, a(0), 0, 7, G, th)
|
||
r:SetAttribute("FallY", -1e9)
|
||
r:SetAttribute("Note", "4 steps of 1.8 studs")
|
||
end
|
||
|
||
---------------- Room 2: narrow bridge over a pit, swinging candy hammers
|
||
do
|
||
local i, r, th = 2, rooms[2], THEMES.candy
|
||
local a = A(i)
|
||
local S = L1
|
||
shell(r, a(0), a(40), th, G, th.pit)
|
||
popBlock(r, "EntryPad", a(0), a(6), -14.25, 14.25, G, S, th.block, candyChecker(1))
|
||
popBlock(r, "ExitPad", a(34), a(40), -14.25, 14.25, G, S, th.block, candyChecker(2))
|
||
local bridge = boxU(r, "Bridge", a(6), a(34), -2.6, 2.6, S - 1.2, S, th.block, PL)
|
||
popitSurface(r, L(a(20), S, 0), 5.2, 28, candyChecker(3))
|
||
-- pillars under the bridge
|
||
for _, u in ipairs({ 12, 20, 28 }) do boxU(r, "BridgePillar", a(u - 0.8), a(u + 0.8), -0.8, 0.8, G, S - 1.2, th.jamb, PL) end
|
||
-- cross beam for hammer pivots
|
||
local PIV_Y = S + 17
|
||
boxU(r, "HammerBeam", a(10), a(30), -1, 1, PIV_Y + 0.5, PIV_Y + 2.5, th.jamb, PL)
|
||
for k, u in ipairs({ 13, 20, 27 }) do
|
||
local m = Instance.new("Model") m.Name = "Hammer"
|
||
local piv = L(a(u), PIV_Y, 0)
|
||
local ARM = 14
|
||
deco(part(m, "Axle", piv, Vector3.new(1.2, 1.2, 1.2), WHITE, SM, { Shape = Enum.PartType.Ball }))
|
||
for s = 0, 5 do
|
||
deco(part(m, "Stick", piv * CFrame.new(0, -1 - s * (ARM - 2) / 6 - (ARM - 2) / 12, 0), Vector3.new(0.6, (ARM - 2) / 6, 0.6), s % 2 == 0 and rgb(255, 80, 150) or WHITE, SM))
|
||
end
|
||
local headCF = piv * CFrame.new(0, -ARM, 0)
|
||
local head = deco(part(m, "Head", headCF, Vector3.new(6, 3.6, 3.6), rgb(255, 120, 190), SM, { Shape = Enum.PartType.Cylinder }))
|
||
for _, x in ipairs({ -1.6, 0, 1.6 }) do
|
||
deco(part(m, "Stripe", headCF * CFrame.new(x, 0, 0), Vector3.new(0.5, 3.75, 3.75), WHITE, SM, { Shape = Enum.PartType.Cylinder }))
|
||
end
|
||
for _, x in ipairs({ -3.6, 3.6 }) do
|
||
deco(part(m, "Wrap", headCF * CFrame.new(x, 0, 0), Vector3.new(1.4, 2.4, 2.4), rgb(255, 220, 60), SM, { Shape = Enum.PartType.Ball }))
|
||
end
|
||
m.Parent = r
|
||
kin(m, "Hammer", { PivotCF = piv, Amp = 55, Period = 3.2, Phase = (k - 1) * 1.07, HeadLen = 6, HeadR = 1.8 })
|
||
end
|
||
checkpoint(r, 2, a(0), 0, 6, S, th)
|
||
r:SetAttribute("FallY", S - 3)
|
||
end
|
||
|
||
---------------- Room 3: pop-it slide up, ball rolls down, side pockets
|
||
do
|
||
local i, r, th = 3, rooms[3], THEMES.candy
|
||
local a = A(i)
|
||
local S0, S1 = L1, L3
|
||
shell(r, a(0), a(44), th, G, th.pit)
|
||
popBlock(r, "EntryPad", a(0), a(6), -14.25, 14.25, G, S0, th.block, candyChecker(4))
|
||
popBlock(r, "TopPad", a(34), a(44), -14.25, 14.25, G, S1, th.block, candyChecker(5))
|
||
local run, rise = 28, S1 - S0
|
||
local ang = math.atan2(rise, run)
|
||
local slen = math.sqrt(run * run + rise * rise)
|
||
local slopeCF = L(a(20), (S0 + S1) / 2, 0) * CFrame.Angles(ang, 0, 0)
|
||
part(r, "Slide", slopeCF * CFrame.new(0, -1, 0), Vector3.new(14, 2, slen), th.block, PL)
|
||
-- support wedge under the slide so it reads as solid
|
||
part(r, "SlideBody", slopeCF * CFrame.new(0, -3.5, 0), Vector3.new(13.6, 3, slen - 1), th.jamb, PL)
|
||
popitSurface(r, slopeCF, 14, slen, candyColumns(2))
|
||
-- low curbs along the lane, with gaps at the pockets
|
||
local function h(u) return S0 + (u - 6) * rise / run end
|
||
for _, side in ipairs({ -1, 1 }) do
|
||
for _, seg in ipairs({ { 6.5, 12 }, { 18, 23 }, { 29, 33.5 } }) do
|
||
local um = (seg[1] + seg[2]) / 2
|
||
local l = (seg[2] - seg[1]) / math.cos(ang)
|
||
part(r, "Curb", L(a(um), h(um) + 0.5, side * 7.4) * CFrame.Angles(ang, 0, 0), Vector3.new(0.8, 1, l), WHITE, SM)
|
||
end
|
||
-- pockets (safe niches) at u 12..18 and 23..29
|
||
for k, pu in ipairs({ { 12, 18 }, { 23, 29 } }) do
|
||
local top = h(pu[2]) - 0.2
|
||
popBlock(r, "Pocket", a(pu[1]), a(pu[2]), side > 0 and 7 or -13.5, side > 0 and 13.5 or -7, G, top, th.block, single(CANDY[(k * 2 + side + 3) % #CANDY + 1]))
|
||
end
|
||
end
|
||
-- the ball
|
||
local R = 4.5
|
||
local nrm = slopeCF.UpVector
|
||
local top = L(a(32), h(32), 0).Position + nrm * R
|
||
local bottom = L(a(7.5), h(7.5), 0).Position + nrm * R
|
||
local m = Instance.new("Model") m.Name = "RollingBall"
|
||
local ball = deco(part(m, "Ball", CFrame.new(top), Vector3.new(2 * R, 2 * R, 2 * R), rgb(190, 80, 230), SM, { Shape = Enum.PartType.Ball }))
|
||
deco(part(m, "Ring", CFrame.new(top) * CCF.Rotation, Vector3.new(0.6, 2 * R + 0.1, 2 * R + 0.1), WHITE, SM, { Shape = Enum.PartType.Cylinder }))
|
||
deco(part(m, "Ring", CFrame.new(top) * CCF.Rotation * CFrame.Angles(0, math.rad(90), 0), Vector3.new(0.6, 2 * R + 0.1, 2 * R + 0.1), rgb(255, 220, 60), SM, { Shape = Enum.PartType.Cylinder }))
|
||
m.Parent = r
|
||
kin(m, "Ball", { PivotCF = CFrame.new(top), Top = top, Bottom = bottom, Period = 6.5, RollTime = 3.2, Radius = R, Phase = 0 })
|
||
checkpoint(r, 3, a(0), 0, 6, S0, th)
|
||
r:SetAttribute("FallY", S0 - 3)
|
||
end
|
||
|
||
---------------- Room 4: pop-it islands over glowing lava
|
||
do
|
||
local i, r, th = 4, rooms[4], THEMES.candy
|
||
local a = A(i)
|
||
local S = L3
|
||
shell(r, a(0), a(48), th, G, rgb(90, 25, 20))
|
||
popBlock(r, "EntryPad", a(0), a(6), -14.25, 14.25, G, S, th.block, candyChecker(6))
|
||
popBlock(r, "ExitPad", a(41), a(48), -14.25, 14.25, G, S, th.block, candyChecker(7))
|
||
local lavaTop = S - 7
|
||
local lava = boxU(r, "Lava", a(6), a(41), -14.25, 14.25, G, lavaTop, rgb(255, 80, 0), Enum.Material.CrackedLava, { CanCollide = false, CanQuery = false })
|
||
deco(boxU(r, "LavaGlow", a(6), a(41), -14.25, 14.25, lavaTop, lavaTop + 0.3, rgb(255, 120, 20), NEON, { Transparency = 0.15 }))
|
||
for _, u in ipairs({ 12, 24, 36 }) do
|
||
local pl = Instance.new("PointLight") pl.Color = rgb(255, 120, 40) pl.Range = 30 pl.Brightness = 2
|
||
local holder = deco(part(r, "LavaLight", L(a(u), lavaTop + 1, 0), Vector3.new(1, 1, 1), WHITE, SM, { Transparency = 1 }))
|
||
pl.Parent = holder
|
||
end
|
||
for k, isl in ipairs({ { 12, 0 }, { 23, 3 }, { 34, -3 } }) do
|
||
local u, v = isl[1], isl[2]
|
||
boxU(r, "IslandPillar", a(u - 2.5), a(u + 2.5), v - 2.5, v + 2.5, G, S - 1, rgb(120, 40, 60), PL)
|
||
popBlock(r, "Island", a(u - 3.75), a(u + 3.75), v - 3.75, v + 3.75, S - 1.4, S, th.block, single(CANDY[(k * 3) % #CANDY + 1]))
|
||
end
|
||
checkpoint(r, 4, a(0), 0, 6, S, th)
|
||
r:SetAttribute("FallY", S - 3)
|
||
end
|
||
|
||
---------------- Room 5: rotating candy bar
|
||
do
|
||
local i, r, th = 5, rooms[5], THEMES.candy
|
||
local a = A(i)
|
||
local S = L3
|
||
shell(r, a(0), a(36), th, G, th.pit)
|
||
popBlock(r, "Floor", a(0), a(36), -14.25, 14.25, G, S, th.block, candyChecker(8))
|
||
local piv = L(a(18), S, 0)
|
||
local m = Instance.new("Model") m.Name = "Spinner"
|
||
part(m, "Hub", piv * CFrame.new(0, 1.6, 0) * CFrame.Angles(0, 0, math.rad(90)), Vector3.new(3.2, 3, 3), WHITE, SM, { Shape = Enum.PartType.Cylinder })
|
||
deco(part(m, "Cap", piv * CFrame.new(0, 3.3, 0), Vector3.new(2.4, 2.4, 2.4), rgb(255, 80, 150), SM, { Shape = Enum.PartType.Ball }))
|
||
local BAR_Y, BAR_R, BAR_LEN = 1.6, 0.75, 26
|
||
local nseg = 13
|
||
for s = 1, nseg do
|
||
local x = -BAR_LEN / 2 + (s - 0.5) * BAR_LEN / nseg
|
||
if math.abs(x) > 1.2 then
|
||
deco(part(m, "Bar", piv * CFrame.new(x, BAR_Y, 0), Vector3.new(BAR_LEN / nseg, BAR_R * 2, BAR_R * 2), s % 2 == 0 and WHITE or rgb(255, 70, 120), SM, { Shape = Enum.PartType.Cylinder }))
|
||
end
|
||
end
|
||
for _, x in ipairs({ -BAR_LEN / 2, BAR_LEN / 2 }) do
|
||
deco(part(m, "Tip", piv * CFrame.new(x, BAR_Y, 0), Vector3.new(1.8, 1.8, 1.8), rgb(255, 220, 60), SM, { Shape = Enum.PartType.Ball }))
|
||
end
|
||
m.Parent = r
|
||
kin(m, "Spinner", { PivotCF = piv, Speed = 70, Phase = 0, BarLen = BAR_LEN + 1.8, BarR = BAR_R, BarTop = S + BAR_Y + BAR_R })
|
||
checkpoint(r, 5, a(0), 0, 6, S, th)
|
||
r:SetAttribute("FallY", S - 3)
|
||
end
|
||
|
||
---------------- Room 6: hanging pop-it platforms that shuttle over a chasm
|
||
do
|
||
local i, r, th = 6, rooms[6], THEMES.candy
|
||
local a = A(i)
|
||
local S = L3
|
||
shell(r, a(0), a(56), th, G, th.pit)
|
||
popBlock(r, "EntryPad", a(0), a(7), -14.25, 14.25, G, S, th.block, candyChecker(1))
|
||
popBlock(r, "MidIsland", a(26), a(32), -5, 5, G, S, th.block, candyChecker(2))
|
||
popBlock(r, "ExitPad", a(49), a(56), -14.25, 14.25, G, S, th.block, candyChecker(3))
|
||
-- ceiling rail
|
||
boxU(r, "Rail", a(7), a(49), -0.6, 0.6, 46, 47, th.jamb, PL)
|
||
local function shuttle(name, uA, uB, phase, variant)
|
||
local m = Instance.new("Model") m.Name = name
|
||
local A0 = L(a(uA), S, 0)
|
||
local body = part(m, "Body", A0 * CFrame.new(0, -0.6, 0), Vector3.new(9, 1.2, 8), th.block, PL)
|
||
popitSurface(m, A0, 9, 8, single(variant), true)
|
||
for _, c in ipairs({ { -4, -3.5 }, { 4, -3.5 }, { -4, 3.5 }, { 4, 3.5 } }) do
|
||
local h = 46 - S
|
||
deco(part(m, "Rope", A0 * CFrame.new(c[1], h / 2, c[2]), Vector3.new(0.25, h, 0.25), WHITE, SM))
|
||
end
|
||
deco(part(m, "Trolley", A0 * CFrame.new(0, 46 - S - 0.6, 0), Vector3.new(9, 0.8, 2), th.jamb, SM))
|
||
m.Parent = r
|
||
kin(m, "Mover", { PivotCF = A0, A = A0, B = L(a(uB), S, 0), Travel = 3.2, Dwell = 3.0, Phase = phase })
|
||
end
|
||
shuttle("Shuttle", 11, 22, 0, "Turquoise")
|
||
shuttle("Shuttle", 36, 45, 6.2, "Yellow")
|
||
checkpoint(r, 6, a(0), 0, 7, S, th)
|
||
r:SetAttribute("FallY", S - 3)
|
||
end
|
||
|
||
---------------- Room 7: marshmallow presses (spooky theme starts)
|
||
do
|
||
local i, r, th = 7, rooms[7], THEMES.spooky
|
||
local a = A(i)
|
||
local S = L3
|
||
shell(r, a(0), a(44), th, G, th.pit)
|
||
boxU(r, "Floor", a(0), a(44), -14.25, 14.25, G, S, th.block, PL)
|
||
-- safe zones lime, press zones purple
|
||
local zones = { { 0, 8, true }, { 8, 14, false }, { 14, 19, true }, { 19, 25, false }, { 25, 30, true }, { 30, 36, false }, { 36, 44, true } }
|
||
for _, z in ipairs(zones) do
|
||
popitSurface(r, L(a((z[1] + z[2]) / 2), S, 0), 28.5, z[2] - z[1], z[3] and single("Lime", rgb(125, 215, 45)) or single("Purple", rgb(140, 70, 215)))
|
||
end
|
||
local DROP = 11.4
|
||
for k, u in ipairs({ 11, 22, 33 }) do
|
||
local m = Instance.new("Model") m.Name = "Press"
|
||
local piv = L(a(u), S + 12, 0) -- bottom face of the raised press
|
||
local body = deco(part(m, "Marshmallow", piv * CFrame.new(0, 2.5, 0), Vector3.new(28, 5, 6), rgb(255, 225, 240), SM))
|
||
deco(part(m, "Under", piv * CFrame.new(0, 0.15, 0), Vector3.new(27.6, 0.3, 5.6), rgb(255, 150, 200), NEON))
|
||
deco(part(m, "Top", piv * CFrame.new(0, 5.4, 0), Vector3.new(27, 0.8, 5.4), rgb(255, 170, 220), SM))
|
||
for _, x in ipairs({ -8, 8 }) do
|
||
deco(part(m, "Piston", piv * CFrame.new(x, 5 + (CEIL - S - 17 + DROP + 0.8) / 2, 0), Vector3.new(1.2, CEIL - S - 17 + DROP + 0.8, 1.2), rgb(200, 200, 215), Enum.Material.Metal))
|
||
end
|
||
-- smiley face on both sides
|
||
for _, sd in ipairs({ -1, 1 }) do
|
||
for _, ex in ipairs({ -2, 2 }) do
|
||
deco(part(m, "Eye", piv * CFrame.new(ex, 3.2, sd * 3.02), Vector3.new(0.9, 0.9, 0.1), rgb(40, 20, 50), SM))
|
||
end
|
||
deco(part(m, "Smile", piv * CFrame.new(0, 1.9, sd * 3.02), Vector3.new(2.2, 0.35, 0.1), rgb(40, 20, 50), SM))
|
||
end
|
||
-- floor warning markers at both edges of the footprint (do not move)
|
||
for _, du in ipairs({ -3.2, 3.2 }) do
|
||
deco(part(m, "Marker", L(a(u + du), S + 0.55, 0), Vector3.new(28.4, 0.12, 0.6), rgb(90, 40, 140), NEON))
|
||
end
|
||
m.Parent = r
|
||
kin(m, "Press", { PivotCF = piv, Drop = DROP, Period = 4.8, Phase = (k - 1) * 1.6, HalfU = 3, HalfV = 14, BottomY = S + 12 })
|
||
end
|
||
checkpoint(r, 7, a(0), 0, 7, S, th)
|
||
r:SetAttribute("FallY", S - 3)
|
||
end
|
||
|
||
---------------- Room 8: ghost lifts
|
||
do
|
||
local i, r, th = 8, rooms[8], THEMES.spooky
|
||
local a = A(i)
|
||
local S0, S1 = L3, L8
|
||
local MID = (S0 + S1) / 2
|
||
shell(r, a(0), a(40), th, G, th.pit)
|
||
popBlock(r, "EntryPad", a(0), a(8), -14.25, 14.25, G, S0, th.block, spookyChecker(0))
|
||
popBlock(r, "MidLedge", a(16), a(24), -6, 6, G, MID, th.block, spookyChecker(1))
|
||
popBlock(r, "ExitPad", a(32), a(40), -14.25, 14.25, G, S1, th.block, spookyChecker(0))
|
||
local function lift(uc, y0, y1, phase)
|
||
local m = Instance.new("Model") m.Name = "Lift"
|
||
local A0 = L(a(uc), y0, 0)
|
||
part(m, "Body", A0 * CFrame.new(0, -0.6, 0), Vector3.new(7.8, 1.2, 7.8), th.block, PL)
|
||
popitSurface(m, A0, 7.8, 7.8, single("Purple", rgb(170, 110, 240)), true)
|
||
deco(part(m, "Glow", A0 * CFrame.new(0, -1.3, 0), Vector3.new(7, 0.3, 7), rgb(120, 255, 40), NEON))
|
||
m.Parent = r
|
||
kin(m, "Mover", { PivotCF = A0, A = A0, B = L(a(uc), y1, 0), Travel = 2.8, Dwell = 3.0, Phase = phase })
|
||
-- static ghost tube + friendly ghost
|
||
deco(boxU(r, "GhostTube", a(uc - 4.3), a(uc + 4.3), -4.3, 4.3, y0 - 2, y1 + 9, rgb(170, 110, 255), NEON, { Transparency = 0.85 }))
|
||
prop(r, "Ghost", a(uc), y1 + 13, -1) -- on the left wall next to the lift
|
||
local arrow = deco(part(r, "UpArrow", L(a(uc), y1 + 6, -14.1) * CFrame.Angles(0, math.rad(-90), 0), Vector3.new(4, 4, 0.2), WHITE, SM, { Transparency = 1 }))
|
||
local g = Instance.new("SurfaceGui") g.LightInfluence = 0 g.Parent = arrow
|
||
local t = Instance.new("TextLabel") t.Size = UDim2.fromScale(1, 1) t.BackgroundTransparency = 1 t.Text = "⬆" t.TextScaled = true t.TextColor3 = rgb(120, 255, 40) t.Font = Enum.Font.FredokaOne t.Parent = g
|
||
end
|
||
lift(12, S0, MID, 0)
|
||
lift(28, MID, S1, 5.8)
|
||
checkpoint(r, 8, a(0), 0, 8, S0, th)
|
||
r:SetAttribute("FallY", S0 - 3)
|
||
end
|
||
|
||
---------------- Room 9: vanishing pop-it tiles
|
||
do
|
||
local i, r, th = 9, rooms[9], THEMES.spooky
|
||
local a = A(i)
|
||
local S = L8
|
||
shell(r, a(0), a(50), th, G, th.pit)
|
||
popBlock(r, "EntryPad", a(0), a(7), -14.25, 14.25, G, S, th.block, spookyChecker(1))
|
||
popBlock(r, "ExitPad", a(43), a(50), -14.25, 14.25, G, S, th.block, spookyChecker(0))
|
||
for k, u in ipairs({ 10, 19, 28, 37 }) do
|
||
for lane, v in ipairs({ -4.5, 4.5 }) do
|
||
local m = Instance.new("Model") m.Name = "VanishTile"
|
||
local cf = L(a(u), S, v)
|
||
part(m, "Body", cf * CFrame.new(0, -0.6, 0), Vector3.new(6, 1.2, 6), lane == 1 and rgb(140, 70, 215) or rgb(125, 215, 45), PL)
|
||
popitSurface(m, cf, 6, 6, single("Purple", lane == 1 and rgb(150, 80, 225) or rgb(130, 220, 50)), false)
|
||
m.Parent = r
|
||
kin(m, "Vanish", { PivotCF = cf, Period = 5.4, Phase = (lane - 1) * 2.7 + (k - 1) * 0.55, Solid = 3.2, Blink = 1.0 })
|
||
end
|
||
end
|
||
checkpoint(r, 9, a(0), 0, 7, S, th)
|
||
r:SetAttribute("FallY", S - 3)
|
||
end
|
||
|
||
---------------- Room 10: rainbow trampoline + finish arch
|
||
do
|
||
local i, r, th = 10, rooms[10], THEMES.spooky
|
||
local a = A(i)
|
||
local S = L8
|
||
shell(r, a(0), a(48), th, G, th.pit)
|
||
popBlock(r, "EntryPad", a(0), a(8), -14.25, 14.25, G, S, th.block, spookyChecker(1))
|
||
boxU(r, "TrampolineBase", a(8), a(14), -4, 4, G, S - 1.6, th.jamb, PL)
|
||
local m = Instance.new("Model") m.Name = "Trampoline"
|
||
local padCF = L(a(11), S + 0.2, 0)
|
||
local pad = part(m, "Pad", padCF * CFrame.new(0, -0.5, 0), Vector3.new(7.5, 1, 6), rgb(255, 220, 40), PL)
|
||
popitSurface(m, padCF, 7.5, 6, function(i2) return CANDY[(i2) % #CANDY + 1] end)
|
||
for _, c in ipairs({ { -2.8, -2 }, { 2.8, -2 }, { -2.8, 2 }, { 2.8, 2 } }) do
|
||
for s = 0, 3 do
|
||
deco(part(m, "Spring", L(a(11 + c[2]), S - 1.4 + s * 0.4, c[1]) * CFrame.Angles(0, 0, math.rad(90)), Vector3.new(0.25, 1.4, 1.4), rgb(255, 80, 150), Enum.Material.Metal, { Shape = Enum.PartType.Cylinder }))
|
||
end
|
||
end
|
||
m.Parent = r
|
||
kin(m, "Trampoline", { PivotCF = padCF, Forward = 34, Up = 68, HalfV = 3.9, HalfU = 3.2, BoostTime = 1.8 })
|
||
-- finish platform
|
||
popBlock(r, "FinishPad", a(26), a(48), -14.25, 14.25, G, S, th.block, function(i2, j2) return "Purple", ((i2 + j2) % 2 == 0) and rgb(125, 215, 45) or rgb(140, 70, 215) end)
|
||
-- chequered finish arch at u=40
|
||
local arch = Instance.new("Model") arch.Name = "FinishArch"
|
||
for _, v in ipairs({ -9.5, 9.5 }) do
|
||
for y = 0, 7 do
|
||
for x = 0, 1 do
|
||
deco(part(arch, "Check", L(a(40), S + 0.75 + y * 1.5, v - 0.75 + x * 1.5), Vector3.new(1.5, 1.5, 1.5), ((x + y) % 2 == 0) and WHITE or rgb(25, 25, 30), SM))
|
||
end
|
||
end
|
||
end
|
||
for x = 0, 13 do
|
||
for y = 0, 1 do
|
||
deco(part(arch, "Check", L(a(40), S + 12.75 + y * 1.5, -10.25 + x * 1.5 + 0.75), Vector3.new(1.5, 1.5, 1.5), ((x + y) % 2 == 0) and WHITE or rgb(25, 25, 30), SM))
|
||
end
|
||
end
|
||
sign(arch, L(a(40) - 0.8, S + 16.4, 0) * CFrame.Angles(0, math.pi, 0), "ФИНИШ!", "Ты молодец!", th)
|
||
arch.Parent = r
|
||
local fz = boxU(r, "FinishZone", a(36), a(47), -14, 14, S, S + 10, WHITE, SM, { Transparency = 1, CanCollide = false, CanQuery = false, CanTouch = false })
|
||
-- return pad back to the school
|
||
local rp = deco(boxU(r, "ReturnPad", a(43), a(47), 8, 13, S, S + 0.6, rgb(0, 200, 255), NEON))
|
||
sign(r, L(a(45), S + 6, 14.05) * CFrame.Angles(0, math.rad(90), 0), "⟲ В школу", "встань на синюю плитку", th)
|
||
checkpoint(r, 10, a(0), 0, 8, S, th)
|
||
r:SetAttribute("FallY", S - 3)
|
||
-- final checkpoint 11 on the finish platform
|
||
local trig = boxU(r, "CheckpointTrigger", a(30), a(46), -14.2, 14.2, S, S + 9, WHITE, SM, { Transparency = 1, CanCollide = false, CanQuery = false, CanTouch = true, CastShadow = false })
|
||
trig:SetAttribute("Index", 11)
|
||
r:SetAttribute("FinishSpawnCF", L(a(36), S, 0))
|
||
end
|
||
|
||
course.Parent = workspace
|
||
|
||
------------------------------------------------------------------ 7. scripts
|
||
local function putScript(parent, class, name, src)
|
||
local s = parent:FindFirstChild(name)
|
||
if s and s.ClassName ~= class then s:Destroy() s = nil end
|
||
if not s then s = Instance.new(class) s.Name = name s.Parent = parent end
|
||
s.Source = src
|
||
return s
|
||
end
|
||
putScript(SSS, "Script", "PopItCourseServer", [=====[-- PopIt obstacle course: per-player checkpoints and respawn (server side).
|
||
-- Each player keeps their own checkpoint in the player attribute "PopCourseCP" (0 = not on the course yet).
|
||
-- Touching a room's CheckpointTrigger sets it; dying inside the course respawns at that checkpoint.
|
||
-- Moving obstacles and fall/hazard resets are simulated by StarterPlayerScripts.PopItCourseClient.
|
||
local Players = game:GetService("Players")
|
||
|
||
local course = workspace:WaitForChild("PopItObstacleCourse")
|
||
local ATTR = "PopCourseCP"
|
||
local CCF = course:GetAttribute("CourseCF")
|
||
local LEN = course:GetAttribute("Length")
|
||
local HW = course:GetAttribute("HalfWidth") or 14.25
|
||
|
||
local spawns = {}
|
||
for _, r in ipairs(course:GetChildren()) do
|
||
local idx = r:GetAttribute("Index")
|
||
if idx and r:GetAttribute("SpawnCF") then spawns[idx] = r:GetAttribute("SpawnCF") end
|
||
if r:GetAttribute("FinishSpawnCF") then spawns[11] = r:GetAttribute("FinishSpawnCF") end
|
||
end
|
||
|
||
local function inside(pos)
|
||
local l = CCF:PointToObjectSpace(pos)
|
||
local u = -l.Z
|
||
return u >= -0.5 and u <= LEN + 1 and math.abs(l.X) <= HW + 1.5
|
||
end
|
||
|
||
local function playerFromHit(hit)
|
||
local model = hit:FindFirstAncestorOfClass("Model")
|
||
while model do
|
||
local plr = Players:GetPlayerFromCharacter(model)
|
||
if plr then return plr, model end
|
||
model = model.Parent and model.Parent:FindFirstAncestorOfClass("Model")
|
||
end
|
||
end
|
||
|
||
local function hookTrigger(p)
|
||
local idx = p:GetAttribute("Index")
|
||
if not idx then return end
|
||
p.Touched:Connect(function(hit)
|
||
local plr, char = playerFromHit(hit)
|
||
if not plr then return end
|
||
local hum = char:FindFirstChildOfClass("Humanoid")
|
||
if not hum or hum.Health <= 0 then return end
|
||
if plr:GetAttribute(ATTR) ~= idx then plr:SetAttribute(ATTR, idx) end
|
||
end)
|
||
end
|
||
for _, d in ipairs(course:GetDescendants()) do
|
||
if d:IsA("BasePart") and d.Name == "CheckpointTrigger" then hookTrigger(d) end
|
||
end
|
||
|
||
local diedInside = {}
|
||
local function placeAtCheckpoint(plr, char)
|
||
local cp = plr:GetAttribute(ATTR) or 0
|
||
local cf = spawns[cp]
|
||
if not cf then return end
|
||
local hrp = char:WaitForChild("HumanoidRootPart", 10)
|
||
local hum = char:WaitForChild("Humanoid", 10)
|
||
if not hrp or not hum then return end
|
||
task.wait() -- let the default spawn finish first
|
||
char:PivotTo(cf + Vector3.new(0, hum.HipHeight + hrp.Size.Y / 2 + 0.3, 0))
|
||
end
|
||
|
||
local function onCharacter(plr, char)
|
||
if diedInside[plr] then
|
||
diedInside[plr] = nil
|
||
task.spawn(placeAtCheckpoint, plr, char)
|
||
end
|
||
local hum = char:WaitForChild("Humanoid", 10)
|
||
if hum then
|
||
hum.Died:Connect(function()
|
||
local hrp = char:FindFirstChild("HumanoidRootPart")
|
||
diedInside[plr] = hrp and inside(hrp.Position) and (plr:GetAttribute(ATTR) or 0) > 0 or nil
|
||
end)
|
||
end
|
||
end
|
||
|
||
local function onPlayer(plr)
|
||
if plr:GetAttribute(ATTR) == nil then plr:SetAttribute(ATTR, 0) end
|
||
plr.CharacterAdded:Connect(function(c) onCharacter(plr, c) end)
|
||
if plr.Character then onCharacter(plr, plr.Character) end
|
||
end
|
||
Players.PlayerAdded:Connect(onPlayer)
|
||
for _, p in ipairs(Players:GetPlayers()) do task.spawn(onPlayer, p) end
|
||
Players.PlayerRemoving:Connect(function(p) diedInside[p] = nil end)
|
||
]=====])
|
||
putScript(StarterPlayer.StarterPlayerScripts, "LocalScript", "PopItCourseClient", [=====[-- PopIt obstacle course (client side).
|
||
-- All moving obstacles are animated locally from the shared server clock (workspace:GetServerTimeNow()),
|
||
-- so every player sees the same timing and the local character collides with smooth geometry.
|
||
-- Also: carrying the player on moving platforms, knock-backs, fall / lava / press resets to the
|
||
-- checkpoint of the current room, trampoline launch, pop-its on moving platforms, finish banner.
|
||
local Players = game:GetService("Players")
|
||
local RunService = game:GetService("RunService")
|
||
local SoundService = game:GetService("SoundService")
|
||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||
local CollectionService = game:GetService("CollectionService")
|
||
local TweenService = game:GetService("TweenService")
|
||
local player = Players.LocalPlayer
|
||
|
||
local course = workspace:WaitForChild("PopItObstacleCourse", 120)
|
||
if not course then return end
|
||
local CCF = course:GetAttribute("CourseCF")
|
||
local LEN = course:GetAttribute("Length")
|
||
local HW = course:GetAttribute("HalfWidth") or 14.25
|
||
local FWD = CCF.LookVector
|
||
local UP = Vector3.yAxis
|
||
local assets = ReplicatedStorage:FindFirstChild("PopItAssets")
|
||
local POPPED = assets and assets:FindFirstChild("Popped")
|
||
|
||
local function now() return workspace:GetServerTimeNow() end
|
||
local function smooth(x) x = math.clamp(x, 0, 1) return x * x * (3 - 2 * x) end
|
||
|
||
---------------------------------------------------------------- rooms
|
||
local rooms = {}
|
||
for i = 1, 10 do
|
||
local r = course:WaitForChild(string.format("Room%02d", i), 60)
|
||
if r then
|
||
rooms[i] = { model = r, U0 = r:GetAttribute("U0"), U1 = r:GetAttribute("U1"), FallY = r:GetAttribute("FallY") or -1e9, Spawn = r:GetAttribute("SpawnCF") }
|
||
end
|
||
end
|
||
local function courseUV(pos)
|
||
local l = CCF:PointToObjectSpace(pos)
|
||
return -l.Z, l.X
|
||
end
|
||
local function roomAt(pos)
|
||
local u, v = courseUV(pos)
|
||
if math.abs(v) > HW + 0.5 then return nil end
|
||
for i, r in pairs(rooms) do
|
||
if u >= r.U0 and u < r.U1 then return i, r end
|
||
end
|
||
end
|
||
|
||
---------------------------------------------------------------- HUD
|
||
local gui = Instance.new("ScreenGui")
|
||
gui.Name = "PopCourseHUD"
|
||
gui.ResetOnSpawn = false
|
||
gui.IgnoreGuiInset = true
|
||
gui.DisplayOrder = 20
|
||
gui.Parent = player:WaitForChild("PlayerGui")
|
||
local toastLbl = Instance.new("TextLabel")
|
||
toastLbl.AnchorPoint = Vector2.new(0.5, 0)
|
||
toastLbl.Position = UDim2.new(0.5, 0, 0.12, 0)
|
||
toastLbl.Size = UDim2.new(0.6, 0, 0.07, 0)
|
||
toastLbl.BackgroundTransparency = 1
|
||
toastLbl.Font = Enum.Font.FredokaOne
|
||
toastLbl.TextScaled = true
|
||
toastLbl.TextColor3 = Color3.fromRGB(255, 240, 120)
|
||
toastLbl.TextTransparency = 1
|
||
toastLbl.Text = ""
|
||
toastLbl.Parent = gui
|
||
local toastStroke = Instance.new("UIStroke") toastStroke.Thickness = 3 toastStroke.Color = Color3.fromRGB(60, 20, 70) toastStroke.Transparency = 1 toastStroke.Parent = toastLbl
|
||
local toastToken = 0
|
||
local function toast(text, color)
|
||
toastToken += 1
|
||
local tk = toastToken
|
||
toastLbl.Text = text
|
||
toastLbl.TextColor3 = color or Color3.fromRGB(255, 240, 120)
|
||
toastLbl.TextTransparency = 0
|
||
toastStroke.Transparency = 0
|
||
task.delay(1.8, function()
|
||
if tk ~= toastToken then return end
|
||
TweenService:Create(toastLbl, TweenInfo.new(0.4), { TextTransparency = 1 }):Play()
|
||
TweenService:Create(toastStroke, TweenInfo.new(0.4), { Transparency = 1 }):Play()
|
||
end)
|
||
end
|
||
|
||
local banner = Instance.new("TextLabel")
|
||
banner.AnchorPoint = Vector2.new(0.5, 0.5)
|
||
banner.Position = UDim2.new(0.5, 0, 0.35, 0)
|
||
banner.Size = UDim2.new(0.8, 0, 0.16, 0)
|
||
banner.BackgroundTransparency = 1
|
||
banner.Font = Enum.Font.FredokaOne
|
||
banner.TextScaled = true
|
||
banner.TextColor3 = Color3.fromRGB(255, 225, 35)
|
||
banner.Text = "🏁 ФИНИШ! Все 10 испытаний пройдены! 🏁"
|
||
banner.Visible = false
|
||
banner.Parent = gui
|
||
local bs = Instance.new("UIStroke") bs.Thickness = 5 bs.Color = Color3.fromRGB(45, 25, 10) bs.Parent = banner
|
||
local bannerScale = Instance.new("UIScale") bannerScale.Parent = banner
|
||
|
||
---------------------------------------------------------------- sounds (same presets as the pop-it floor)
|
||
local function presetSounds()
|
||
local presets = SoundService:FindFirstChild("SoundPresets")
|
||
local active = presets and presets:FindFirstChild(SoundService:GetAttribute("SelectedSoundPreset") or "Classic")
|
||
local folder = active or SoundService:FindFirstChild("PopItSounds")
|
||
local list = {}
|
||
if folder then for _, s in ipairs(folder:GetChildren()) do if s:IsA("Sound") and s.SoundId ~= "" then table.insert(list, s) end end end
|
||
return list
|
||
end
|
||
local lastPop = 0
|
||
local function playPop(speed, volumeMul)
|
||
local t = os.clock()
|
||
if t - lastPop < 0.12 then return end
|
||
lastPop = t
|
||
local list = presetSounds()
|
||
if #list == 0 then return end
|
||
local s = list[math.random(#list)]:Clone()
|
||
s.PlaybackSpeed = s.PlaybackSpeed * (speed or 1) * (0.94 + math.random() * 0.12)
|
||
s.Volume = s.Volume * (volumeMul or 1)
|
||
s.Parent = SoundService
|
||
s:Play()
|
||
s.Ended:Once(function() s:Destroy() end)
|
||
task.delay(4, function() if s.Parent then s:Destroy() end end)
|
||
end
|
||
|
||
---------------------------------------------------------------- character helpers
|
||
local function getChar()
|
||
local c = player.Character
|
||
local h = c and c:FindFirstChildOfClass("Humanoid")
|
||
local r = c and c:FindFirstChild("HumanoidRootPart")
|
||
if h and r and h.Health > 0 then return c, h, r end
|
||
end
|
||
local function footY(h, r) return r.Position.Y - (h.HipHeight + r.Size.Y / 2) end
|
||
|
||
local lastReset = 0
|
||
local function resetTo(i, msg)
|
||
local c, h, r = getChar()
|
||
if not c or not rooms[i] then return end
|
||
if os.clock() - lastReset < 0.6 then return end
|
||
lastReset = os.clock()
|
||
r.AssemblyLinearVelocity = Vector3.zero
|
||
r.AssemblyAngularVelocity = Vector3.zero
|
||
c:PivotTo(rooms[i].Spawn + Vector3.new(0, h.HipHeight + r.Size.Y / 2 + 0.3, 0))
|
||
toast(msg or "Ой! Попробуй ещё раз 💪")
|
||
end
|
||
|
||
local lastKnock = 0
|
||
local function knock(vel, msg)
|
||
local c, h, r = getChar()
|
||
if not c then return end
|
||
if os.clock() - lastKnock < 0.8 then return end
|
||
lastKnock = os.clock()
|
||
h:ChangeState(Enum.HumanoidStateType.Freefall)
|
||
r.AssemblyLinearVelocity = vel
|
||
playPop(0.6, 1.6)
|
||
if msg then toast(msg, Color3.fromRGB(255, 170, 220)) end
|
||
end
|
||
|
||
---------------------------------------------------------------- kinematic objects
|
||
local kin = {}
|
||
local moverBodies = {}
|
||
local function register(m)
|
||
local n = m:GetAttribute("PartCount") or 0
|
||
local t0 = os.clock()
|
||
while true do
|
||
local c = 0
|
||
for _, d in ipairs(m:GetDescendants()) do if d:IsA("BasePart") then c += 1 end end
|
||
if c >= n or os.clock() - t0 > 15 then break end
|
||
task.wait(0.2)
|
||
end
|
||
local e = { m = m, kind = m:GetAttribute("Kind"), base = m:GetAttribute("PivotCF"), parts = {}, rel = {}, bubbles = {} }
|
||
for _, d in ipairs(m:GetDescendants()) do
|
||
if d:IsA("BasePart") and d.Name ~= "Marker" then
|
||
table.insert(e.parts, d)
|
||
table.insert(e.rel, e.base:ToObjectSpace(d.CFrame))
|
||
if d.Name:match("^MBubble_") then
|
||
table.insert(e.bubbles, { part = d, index = #e.parts, size = d.Size, pressed = false, last = 0 })
|
||
end
|
||
elseif d:IsA("BasePart") and d.Name == "Marker" then
|
||
e.markers = e.markers or {}
|
||
table.insert(e.markers, d)
|
||
end
|
||
end
|
||
for k, v in pairs(m:GetAttributes()) do e[k] = v end
|
||
e.body = m:FindFirstChild("Body")
|
||
e.head = m:FindFirstChild("Head")
|
||
e.pad = m:FindFirstChild("Pad")
|
||
e.cf = e.base
|
||
e.orig = {}
|
||
for idx, p in ipairs(e.parts) do e.orig[idx] = p.Transparency end
|
||
if e.kind == "Mover" and e.body then table.insert(moverBodies, e.body) e.body:SetAttribute("_mover", true) end
|
||
table.insert(kin, e)
|
||
end
|
||
for _, m in ipairs(CollectionService:GetTagged("PopCourseKinematic")) do
|
||
if m:IsDescendantOf(course) then task.spawn(register, m) end
|
||
end
|
||
|
||
local function place(e, T)
|
||
e.cf = T
|
||
local cfs = table.create(#e.parts)
|
||
for i, rel in ipairs(e.rel) do cfs[i] = T * rel end
|
||
workspace:BulkMoveTo(e.parts, cfs, Enum.BulkMoveMode.FireCFrameChanged)
|
||
end
|
||
|
||
local function moverCF(e, t)
|
||
local cycle = 2 * (e.Dwell + e.Travel)
|
||
local tc = (t + e.Phase) % cycle
|
||
local a
|
||
if tc < e.Dwell then a = 0
|
||
elseif tc < e.Dwell + e.Travel then a = smooth((tc - e.Dwell) / e.Travel)
|
||
elseif tc < 2 * e.Dwell + e.Travel then a = 1
|
||
else a = 1 - smooth((tc - 2 * e.Dwell - e.Travel) / e.Travel) end
|
||
return e.A:Lerp(e.B, a)
|
||
end
|
||
|
||
local rayParams = RaycastParams.new()
|
||
rayParams.FilterType = Enum.RaycastFilterType.Include
|
||
|
||
local boostUntil, boostSpeed, lastBounce = 0, 0, 0
|
||
local finishShown = false
|
||
local inFinish = false
|
||
local lastReturn = 0
|
||
|
||
local function pressMovingBubbles(e, h, r, t)
|
||
local c = player.Character
|
||
local feet = {}
|
||
for _, n in ipairs({ "LeftFoot", "RightFoot", "Left Leg", "Right Leg" }) do
|
||
local f = c and c:FindFirstChild(n)
|
||
if f then table.insert(feet, f.CFrame:PointToWorldSpace(Vector3.new(0, -f.Size.Y / 2, 0))) end
|
||
end
|
||
local newCount, sum, col = 0, Vector3.zero, nil
|
||
for _, b in ipairs(e.bubbles) do
|
||
local p = b.part
|
||
local hit = false
|
||
for _, fp in ipairs(feet) do
|
||
local l = p.CFrame:PointToObjectSpace(fp)
|
||
if l.Z > -2.2 and l.Z < 0.8 and math.abs(l.X) < b.size.X / 2 + 0.9 and math.abs(l.Y) < b.size.Y / 2 + 0.9 then hit = true break end
|
||
end
|
||
if hit then
|
||
b.last = t
|
||
if not b.pressed then
|
||
b.pressed = true
|
||
newCount += 1
|
||
sum += p.Position
|
||
col = p.Color
|
||
local sz = b.size
|
||
p.Size = Vector3.new(sz.X * 1.05, sz.Y * 1.05, sz.Z * 0.35)
|
||
e.rel[b.index] = e.rel[b.index] * CFrame.new(0, 0, sz.Z * 0.325)
|
||
end
|
||
elseif b.pressed and t - b.last > 0.15 then
|
||
b.pressed = false
|
||
p.Size = b.size
|
||
e.rel[b.index] = e.rel[b.index] * CFrame.new(0, 0, -b.size.Z * 0.325)
|
||
end
|
||
end
|
||
if newCount > 0 then
|
||
playPop()
|
||
if POPPED then POPPED:Fire(newCount, sum / newCount, col) end
|
||
end
|
||
end
|
||
|
||
RunService.PreSimulation:Connect(function(dt)
|
||
local t = now()
|
||
local c, h, r = getChar()
|
||
|
||
-- which moving platform is the character standing on (before moving it)
|
||
local standOn
|
||
if r and #moverBodies > 0 then
|
||
rayParams.FilterDescendantsInstances = moverBodies
|
||
local res = workspace:Raycast(r.Position, Vector3.new(0, -(h.HipHeight + r.Size.Y / 2 + 1.5), 0), rayParams)
|
||
if res then standOn = res.Instance end
|
||
end
|
||
|
||
local roomIdx = r and roomAt(r.Position)
|
||
|
||
for _, e in ipairs(kin) do
|
||
local k = e.kind
|
||
if k == "Mover" then
|
||
local old = e.cf
|
||
local T = moverCF(e, t)
|
||
place(e, T)
|
||
if r and standOn == e.body then
|
||
local d = T.Position - old.Position
|
||
if d.Magnitude > 0 and d.Magnitude < 3 then r.CFrame = r.CFrame + d end
|
||
pressMovingBubbles(e, h, r, os.clock())
|
||
elseif #e.bubbles > 0 then
|
||
pressMovingBubbles(e, h, nil, os.clock())
|
||
end
|
||
elseif k == "Hammer" then
|
||
local ang = math.rad(e.Amp) * math.sin((t + e.Phase) / e.Period * 2 * math.pi)
|
||
place(e, e.base * CFrame.Angles(0, 0, ang))
|
||
if r and e.head then
|
||
local l = e.head.CFrame:PointToObjectSpace(r.Position)
|
||
if math.abs(l.X) < e.HeadLen / 2 + 1 and math.sqrt(l.Y * l.Y + l.Z * l.Z) < e.HeadR + 1.6 then
|
||
knock(-FWD * 32 + UP * 26, "Бум! Конфетный молот 🍬")
|
||
end
|
||
end
|
||
elseif k == "Spinner" then
|
||
local ang = math.rad((e.Speed * t + (e.Phase or 0)) % 360)
|
||
place(e, e.base * CFrame.Angles(0, ang, 0))
|
||
if r then
|
||
local centre = e.base.Position
|
||
local dir = (e.base * CFrame.Angles(0, ang, 0)).RightVector
|
||
local rel = r.Position - centre
|
||
rel = Vector3.new(rel.X, 0, rel.Z)
|
||
local along = rel:Dot(dir)
|
||
local perp = (rel - dir * along).Magnitude
|
||
if math.abs(along) < e.BarLen / 2 and math.abs(along) > 1.5 and perp < e.BarR + 1.3 and footY(h, r) < e.BarTop - 0.1 then
|
||
local tangential = Vector3.new(dir.Z, 0, -dir.X) * math.sign(along * e.Speed)
|
||
knock(tangential * 26 + UP * 30, "Прыгай через перекладину! ⬆")
|
||
end
|
||
end
|
||
elseif k == "Ball" then
|
||
local tc = (t + (e.Phase or 0)) % e.Period
|
||
local visible = tc < e.RollTime
|
||
local a = math.clamp(tc / e.RollTime, 0, 1)
|
||
local pos = e.Top:Lerp(e.Bottom, a)
|
||
local dist = (e.Bottom - e.Top).Magnitude * a
|
||
local axis = FWD:Cross(UP).Unit
|
||
local T = CFrame.new(pos) * CFrame.fromAxisAngle(axis, dist / e.Radius)
|
||
if not visible then T = CFrame.new(e.Top - UP * 200) end
|
||
place(e, T)
|
||
-- fade in at the top, fade out at the bottom
|
||
local fade = 0
|
||
if visible then
|
||
if tc < 0.25 then fade = 1 - tc / 0.25 elseif tc > e.RollTime - 0.35 then fade = (tc - (e.RollTime - 0.35)) / 0.35 end
|
||
end
|
||
for idx, p in ipairs(e.parts) do p.Transparency = math.max(e.orig[idx], fade) end
|
||
if r and visible and fade < 0.5 and (r.Position - pos).Magnitude < e.Radius + 1.8 then
|
||
local down = (e.Bottom - e.Top)
|
||
down = Vector3.new(down.X, 0, down.Z).Unit
|
||
knock(down * 30 + UP * 24, "Уклоняйся в кармашки! 🎳")
|
||
end
|
||
elseif k == "Press" then
|
||
local tc = (t + e.Phase) % e.Period
|
||
local off, state = 0, "idle"
|
||
if tc < 2.0 then off, state = 0, "idle"
|
||
elseif tc < 3.0 then off, state = 0.6 * (tc - 2.0), "warn"
|
||
elseif tc < 3.25 then off, state = 0.6 + (e.Drop - 0.6) * ((tc - 3.0) / 0.25) ^ 2, "slam"
|
||
elseif tc < 4.0 then off, state = e.Drop, "down"
|
||
else off, state = e.Drop * (1 - smooth((tc - 4.0) / 0.8)), "rise" end
|
||
local shake = state == "warn" and math.sin(tc * 60) * 0.12 or 0
|
||
place(e, e.base * CFrame.new(shake, -off, 0))
|
||
if e.markers then
|
||
local col
|
||
if state == "idle" then col = Color3.fromRGB(90, 40, 140)
|
||
elseif state == "warn" then col = (math.floor(tc * 8) % 2 == 0) and Color3.fromRGB(255, 40, 40) or Color3.fromRGB(255, 220, 40)
|
||
elseif state == "rise" then col = Color3.fromRGB(255, 140, 40)
|
||
else col = Color3.fromRGB(255, 30, 30) end
|
||
for _, mk in ipairs(e.markers) do mk.Color = col end
|
||
end
|
||
local under = e.m:FindFirstChild("Under")
|
||
if under then under.Color = (state == "warn" or state == "slam" or state == "down") and Color3.fromRGB(255, 50, 50) or Color3.fromRGB(255, 150, 200) end
|
||
if r and (state == "slam" or state == "down" or state == "rise") then
|
||
local bottom = e.BottomY - off
|
||
local l = e.base:PointToObjectSpace(r.Position)
|
||
if math.abs(l.Z) < e.HalfU + 0.6 and math.abs(l.X) < e.HalfV + 0.6 and bottom < r.Position.Y + 2.4 and bottom > footY(h, r) - 1 then
|
||
resetTo(roomIdx or 7, "Ой, пресс! Жди, пока он поднимется 🍡")
|
||
end
|
||
end
|
||
elseif k == "Vanish" then
|
||
local tc = (t + e.Phase) % e.Period
|
||
local state = tc < e.Solid and "solid" or (tc < e.Solid + e.Blink and "blink" or "gone")
|
||
if state ~= e.state or state == "blink" then
|
||
local tr
|
||
if state == "solid" then tr = nil
|
||
elseif state == "blink" then tr = (math.floor((tc - e.Solid) * 8) % 2 == 0) and 0.65 or nil
|
||
else tr = 1 end
|
||
for idx, p in ipairs(e.parts) do
|
||
p.Transparency = tr and math.max(tr, e.orig[idx]) or e.orig[idx]
|
||
local pressed = p:FindFirstChildWhichIsA("BasePart")
|
||
if pressed and state == "gone" then pressed.Transparency = 1 end
|
||
end
|
||
if e.body then e.body.CanCollide = state ~= "gone" end
|
||
e.state = state
|
||
elseif state == "gone" then
|
||
for _, p in ipairs(e.parts) do if p.Transparency < 1 then p.Transparency = 1 end end
|
||
end
|
||
elseif k == "Trampoline" then
|
||
if r and e.pad and os.clock() - lastBounce > 0.7 then
|
||
local l = e.base:PointToObjectSpace(r.Position)
|
||
local fy = footY(h, r) - e.base.Position.Y
|
||
if math.abs(l.X) < e.HalfV + 0.6 and math.abs(l.Z) < e.HalfU + 0.6 and fy < 1.2 and fy > -1 then
|
||
lastBounce = os.clock()
|
||
h:ChangeState(Enum.HumanoidStateType.Freefall)
|
||
r.AssemblyLinearVelocity = FWD * e.Forward + UP * e.Up
|
||
boostUntil = os.clock() + e.BoostTime
|
||
boostSpeed = e.Forward
|
||
playPop(0.45, 2)
|
||
toast("Ура-а-а! 🌈", Color3.fromRGB(150, 255, 120))
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
if not r then return end
|
||
|
||
-- trampoline flight: a LinearVelocity along the course holds the forward speed (Humanoid air control
|
||
-- would otherwise brake it); vertical motion stays free. Removed on landing or after BoostTime.
|
||
if os.clock() < boostUntil and os.clock() - lastBounce > 0.25 and h.FloorMaterial ~= Enum.Material.Air then boostUntil = 0 end
|
||
local lv = r:FindFirstChild("PopCourseBoost")
|
||
if os.clock() < boostUntil then
|
||
if not lv then
|
||
local att = r:FindFirstChild("PopCourseBoostAtt") or Instance.new("Attachment")
|
||
att.Name = "PopCourseBoostAtt"
|
||
att.Parent = r
|
||
lv = Instance.new("LinearVelocity")
|
||
lv.Name = "PopCourseBoost"
|
||
lv.Attachment0 = att
|
||
lv.RelativeTo = Enum.ActuatorRelativeTo.World
|
||
lv.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
|
||
lv.LineDirection = FWD
|
||
lv.LineVelocity = boostSpeed
|
||
lv.ForceLimitMode = Enum.ForceLimitMode.Magnitude
|
||
lv.MaxForce = 60000
|
||
lv.Parent = r
|
||
end
|
||
elseif lv then
|
||
lv:Destroy()
|
||
end
|
||
|
||
-- falls, lava
|
||
if roomIdx then
|
||
local room = rooms[roomIdx]
|
||
if r.Position.Y < room.FallY then
|
||
resetTo(roomIdx, roomIdx == 4 and "Горячо! Лава 🔥 Попробуй ещё раз" or nil)
|
||
end
|
||
else
|
||
local u, v = courseUV(r.Position)
|
||
if u > 0 and u < LEN and math.abs(v) < HW + 3 and r.Position.Y < -20 then resetTo(1) end
|
||
end
|
||
|
||
-- finish zone / return pad
|
||
local r10 = rooms[10] and rooms[10].model
|
||
local fz = r10 and r10:FindFirstChild("FinishZone")
|
||
if fz then
|
||
local l = fz.CFrame:PointToObjectSpace(r.Position)
|
||
local inside = math.abs(l.X) < fz.Size.X / 2 and math.abs(l.Y) < fz.Size.Y / 2 and math.abs(l.Z) < fz.Size.Z / 2
|
||
if inside and not inFinish and not finishShown then
|
||
finishShown = true
|
||
banner.Visible = true
|
||
bannerScale.Scale = 0.3
|
||
TweenService:Create(bannerScale, TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.Out), { Scale = 1 }):Play()
|
||
local snd = SoundService:FindFirstChild("LevelUpSound")
|
||
if snd then SoundService:PlayLocalSound(snd) end
|
||
task.delay(4, function() banner.Visible = false end)
|
||
task.delay(20, function() finishShown = false end)
|
||
end
|
||
inFinish = inside
|
||
end
|
||
local rp = r10 and r10:FindFirstChild("ReturnPad")
|
||
if rp and os.clock() - lastReturn > 2 then
|
||
local l = rp.CFrame:PointToObjectSpace(r.Position)
|
||
if math.abs(l.X) < rp.Size.X / 2 + 0.3 and math.abs(l.Z) < rp.Size.Z / 2 + 0.3 and l.Y < 5 and l.Y > -1 then
|
||
lastReturn = os.clock()
|
||
local cf = course:GetAttribute("ReturnCF")
|
||
c:PivotTo(cf + Vector3.new(0, h.HipHeight + r.Size.Y / 2 + 0.3, 0))
|
||
toast("С возвращением в школу! 🏫")
|
||
end
|
||
end
|
||
end)
|
||
|
||
---------------------------------------------------------------- checkpoint flags (local colours)
|
||
local flags = {}
|
||
for _, d in ipairs(course:GetDescendants()) do
|
||
if d:IsA("Model") and d.Name == "CheckpointFlag" then table.insert(flags, d) end
|
||
end
|
||
local lastCP = player:GetAttribute("PopCourseCP") or 0
|
||
local function refreshFlags()
|
||
local cp = player:GetAttribute("PopCourseCP") or 0
|
||
for _, f in ipairs(flags) do
|
||
local cloth = f:FindFirstChild("Cloth")
|
||
if cloth then cloth.Color = (f:GetAttribute("Index") or 99) <= cp and Color3.fromRGB(120, 255, 60) or Color3.fromRGB(255, 255, 255) end
|
||
end
|
||
if cp > lastCP and cp >= 1 and cp <= 10 then
|
||
toast(string.format("Чекпоинт %d ✔ %s", cp, rooms[cp] and rooms[cp].model:GetAttribute("Title") or ""), Color3.fromRGB(150, 255, 120))
|
||
end
|
||
lastCP = cp
|
||
end
|
||
player:GetAttributeChangedSignal("PopCourseCP"):Connect(refreshFlags)
|
||
refreshFlags()
|
||
]=====])
|
||
|
||
if rec then CHS:FinishRecording(rec, Enum.FinishRecordingOperation.Commit) end
|
||
|
||
local parts = 0
|
||
for _, d in ipairs(course:GetDescendants()) do if d:IsA("BasePart") then parts += 1 end end
|
||
say(string.format("Course built: %d rooms, %d pop-it tiles, %d parts, length %.0f studs", #rooms, tileCount, parts, TOTAL))
|
||
say(string.format("Origin (%.2f, %.2f, %.2f) forward (%d, %d, %d)", origin.X, origin.Y, origin.Z, fwd.X, fwd.Y, fwd.Z))
|
||
for i = 1, 10 do
|
||
local s = rooms[i]:GetAttribute("SpawnCF").Position
|
||
say(string.format("Room%02d %-20s u %.0f..%.0f spawn (%.1f, %.1f, %.1f)", i, TITLES[i], U[i - 1], U[i], s.X, s.Y, s.Z))
|
||
end
|
||
return table.concat(LOG, "\n")
|