Hacia la torre
Lección 12 de 18 del curso Juego de Roblox: Torre infinita de Coddy.
Cuando termina la cuenta regresiva, comienza la ronda: construye la torre, inicia la lava y mueve a todos los jugadores a la primera etapa. Mantén las etapas en una tabla mientras las construyes, de modo que towerStages[1] sea la etapa inferior:
towerStages[i] = stageUn personaje es un Model, así que PivotTo lo mueve entero. Colócalo unos pocos studs por encima de la plataforma Start, no dentro de ella, para que aterrice encima:
player.Character:PivotTo(towerStages[1].Start.CFrame + Vector3.new(0, 4, 0))Después, el tablero cuenta la ronda hacia atrás, igual que en el vestíbulo.
Desafío
Intermedio- Cerca de la parte superior:
local towerStages = {}. EnbuildTower, vacíalo al principio y guarda cada etapa comotowerStages[i] = stage. - Escribe
startRound(): construye la torre, inicia la lava y mueve el personaje de cada jugador a 4 studs por encima detowerStages[1].Start. - Al final: después de la cuenta regresiva del vestíbulo, llama a
startRound()y luego cuenta hacia atrás desdeSettings.RoundLength, mostrandoClimb! 20 seconds left,Climb! 19 seconds left, ...
Pulsa Jugar. Después, Comprobar.
Pruébalo tú mismo
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")
-- Cada jugador recibe Wins en la tabla de clasificación
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)
-- El tablero del vestíbulo
local gui = Instance.new("SurfaceGui")
gui.Parent = workspace.Lobby.Board
local boardLabel = Instance.new("TextLabel")
boardLabel.Name = "Status"
boardLabel.Size = UDim2.fromScale(1, 1)
boardLabel.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
boardLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
boardLabel.TextScaled = true
boardLabel.Text = "Endless Tower"
boardLabel.Parent = gui
local function setBoard(text)
boardLabel.Text = text
end
-- Cualquier cosa con la etiqueta Kill acaba con una vida
local function killOnTouch(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
-- Una plataforma que desaparece se desvanece poco después de que alguien caiga sobre ella y luego reaparece
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
-- Un láser se desliza hasta la posición indicada por Slide y vuelve, indefinidamente
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
-- Una plataforma de rebote lanza por los aires a quien caiga sobre ella
local function bounce(hit)
local root = hit.Parent:FindFirstChild("HumanoidRootPart")
if root then
root.AssemblyLinearVelocity = Vector3.new(0, Settings.BouncePower, 0)
end
end
-- Los objetos giratorios giran un poco en cada fotograma
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)
-- Activa todos los obstáculos de una etapa según sus etiquetas
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
-- Una etapa cualquiera, elegida al azar
local function pickStage()
local all = stages:GetChildren()
return all[math.random(1, #all)]
end
-- Coloca una copia de un modelo encima de la torre; devuelve la copia y la nueva altura máxima
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
-- Construye una nueva torre aleatoria de abajo arriba
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
-- La lava sube desde el suelo hasta justo debajo de la cima de la torre
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
-- Haz la cuenta regresiva y luego construye la torre
for i = Settings.Intermission, 1, -1 do
setBoard("Next tower in " .. i)
task.wait(1)
end
local top = buildTower()
startLava(top)
Esta lección incluye un breve cuestionario. Empieza la lección para responderlo y registrar tu progreso.