הלוח
שיעור 12 מתוך 21 בקורס משחק Roblox: מגדל אינסופי של Coddy.
מסלול מכשולים מתנהל בסבבים: המתנה קצרה בלובי, ואז מגדל חדש ומרוץ אל הפסגה. השחקנים צריכים לראות מה קורה, לכן יש בלובי Board, חלק שטוח שפונה אל נקודת ההופעה.
טקסט על חלק הוא SurfaceGui שמכיל TextLabel. UDim2.fromScale(1, 1) גורם לתווית למלא את כל המשטח, ו-TextScaled מתאים את גודל המילים כדי שייכנסו:
local gui = Instance.new("SurfaceGui")
gui.Parent = workspace.Lobby.Board
local boardLabel = Instance.new("TextLabel")
boardLabel.Size = UDim2.fromScale(1, 1)
boardLabel.TextScaled = true
boardLabel.Text = "Endless Tower"
boardLabel.Parent = guiספירה לאחור היא לולאת for שסופרת לאחור בצעדים של -1, וממתינה שנייה בכל פעם:
for i = 3, 1, -1 do
print("Lift off in " .. i)
task.wait(1)
endאתגר
בינוניספרו לאחור לקראת כל מגדל בלוח שבחדר ההמתנה.
- הוסיפו SurfaceGui ל־
workspace.Lobby.Board, ובו TextLabel בשםboardLabel, ששמוStatus, שגודלוUDim2.fromScale(1, 1), וש־TextScaled מופעל בו. - כתבו את
setBoard(text), שמגדירה אתboardLabel.Text. - לפני בניית המגדל, ספרו את
iלאחור מ־Settings.Intermissionעד 1:setBoard("Next tower in " .. i), ואזtask.wait(1).
לחצו על שחק: הלוח סופר לאחור מ־5, ואז המגדל מופיע. לאחר מכן לחצו על בדיקה.
נסו בעצמכם
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Settings = require(game.ReplicatedStorage.Settings)
local stages = ServerStorage.Stages
local tower = nil
local lava = nil
print("Each tower has " .. Settings.StageCount .. " stages")
-- כל שחקן מקבל Wins בטבלת המובילים
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Parent = leaderstats
end)
-- שיעור 12: The Board מופיע כאן
-- כל דבר עם התג Kill מסיים חיים
local function killOnTouch(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
-- מדרגה נעלמת דוהה זמן קצר אחרי שמישהו נוחת עליה, ואז חוזרת
local function makeVanish(part)
part.Touched:Connect(function(hit)
if part:GetAttribute("Gone") or not hit.Parent:FindFirstChild("Humanoid") then
return
end
part:SetAttribute("Gone", true)
task.wait(Settings.VanishDelay)
part.Transparency = 0.8
part.CanCollide = false
task.wait(Settings.VanishTime)
part.Transparency = 0
part.CanCollide = true
part:SetAttribute("Gone", nil)
end)
end
-- לייזר נע אל ההיסט Slide שלו ובחזרה, ללא הפסקה
local function makeSlide(part)
local info = TweenInfo.new(Settings.SlideTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true)
local goal = { Position = part.Position + part:GetAttribute("Slide") }
TweenService:Create(part, info, goal):Play()
end
-- משטח קפיצה מעיף לאוויר את מי שנוחת עליו
local function bounce(hit)
local root = hit.Parent:FindFirstChild("HumanoidRootPart")
if root then
root.AssemblyLinearVelocity = Vector3.new(0, Settings.BouncePower, 0)
end
end
-- העצמים המסתובבים מסתובבים מעט בכל פריים
RunService.Heartbeat:Connect(function(dt)
for _, spinner in CollectionService:GetTagged("Spinner") do
if spinner:IsDescendantOf(workspace) then
spinner:PivotTo(spinner:GetPivot() * CFrame.Angles(0, math.rad(Settings.SpinSpeed) * dt, 0))
end
end
end)
-- הפעל כל מכשול בשלב לפי התגים שלו
local function setupStage(stage)
for _, part in stage:GetDescendants() do
if part:HasTag("Kill") then
part.Touched:Connect(killOnTouch)
end
if part:HasTag("Vanish") then
makeVanish(part)
end
if part:HasTag("Conveyor") then
part.AssemblyLinearVelocity = part.CFrame.LookVector * Settings.BeltSpeed
end
if part:HasTag("Slider") then
makeSlide(part)
end
if part:HasTag("Bounce") then
part.Touched:Connect(bounce)
end
end
end
-- בחר שלב כלשהו באקראי
local function pickStage()
local all = stages:GetChildren()
return all[math.random(1, #all)]
end
-- מקם עותק של מודל בראש המגדל; מחזיר את העותק ואת הגובה החדש של המגדל
local function stack(template, bottom)
local copy = template:Clone()
local box, size = copy:GetBoundingBox()
local lift = bottom - (box.Position.Y - size.Y / 2)
copy:PivotTo(copy:GetPivot() + Vector3.new(0, lift, 0))
copy.Parent = tower
return copy, bottom + size.Y
end
-- בנה מגדל אקראי חדש מלמטה למעלה
local function buildTower()
tower = Instance.new("Model")
tower.Name = "Tower"
tower.Parent = workspace
local top = 0
for i = 1, Settings.StageCount do
local stage, newTop = stack(pickStage(), top)
top = newTop
setupStage(stage)
end
stack(ServerStorage.Finish, top)
return top
end
-- הלבה עולה מהקרקע עד ממש מתחת לראש המגדל
local function startLava(top)
lava = Instance.new("Part")
lava.Name = "Lava"
lava.Anchored = true
lava.CanCollide = false
lava.Size = Vector3.new(30, 2, 30)
lava.Position = Vector3.new(0, -2, 0)
lava.Color = Color3.fromRGB(255, 90, 20)
lava.Material = Enum.Material.Neon
lava.Parent = workspace
lava.Touched:Connect(killOnTouch)
local info = TweenInfo.new(top / Settings.LavaSpeed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, Settings.LavaDelay)
TweenService:Create(lava, info, { Position = Vector3.new(0, top - 2, 0) }):Play()
end
startLava(buildTower())
כל השיעורים ביחידה משחק Roblox: מגדל אינסופי
תרגלו בעצמכם: Roblox אונליין