Menu
CoddyTech

Dans la tour

Leçon 12 sur 18 du cours Jeu Roblox : tour sans fin de Coddy.

Lorsque le compte à rebours se termine, la manche commence : construis la tour, démarre la lave et déplace chaque joueur sur le premier étage. Garde les étages dans une table au fur et à mesure que tu les construis, afin que towerStages[1] soit l’étage du bas :

towerStages[i] = stage

Un personnage est un Model, donc PivotTo le déplace en entier. Place-le à quelques studs au-dessus du pad Start, pas à l’intérieur, et il atterrira dessus :

player.Character:PivotTo(towerStages[1].Start.CFrame + Vector3.new(0, 4, 0))

Ensuite, le tableau décompte la manche, comme dans le salon.

challenge icon

Défi

Moyen
  1. Près du début : local towerStages = {}. Dans buildTower, videz-le au début et enregistrez chaque étage avec towerStages[i] = stage.
  2. Écrivez startRound() : construisez la tour, démarrez la lave et déplacez le personnage de chaque joueur à 4 studs au-dessus de towerStages[1].Start.
  3. À la fin : après le compte à rebours du lobby, appelez startRound(), puis effectuez un compte à rebours à partir de Settings.RoundLength, en affichant Climb! 20 seconds left, Climb! 19 seconds left, ...

Appuyez sur Play. Puis sur Check.

Essayez vous-même

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")

-- Chaque joueur reçoit Wins dans le classement
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)

-- Le panneau dans le hall
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

-- Tout objet portant le tag Kill met fin à une vie
local function killOnTouch(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

-- Une marche escamotable s’estompe peu après que quelqu’un y a atterri, puis réapparaît
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 laser glisse jusqu’au décalage Slide, puis revient, indéfiniment
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

-- Un tremplin propulse en l’air quiconque atterrit dessus
local function bounce(hit)
	local root = hit.Parent:FindFirstChild("HumanoidRootPart")
	if root then
		root.AssemblyLinearVelocity = Vector3.new(0, Settings.BouncePower, 0)
	end
end

-- Les objets Spinner tournent un peu à chaque image
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)

-- Active chaque obstacle d’une étape selon ses tags
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

-- Une étape choisie au hasard
local function pickStage()
	local all = stages:GetChildren()
	return all[math.random(1, #all)]
end

-- Place une copie d’un modèle au sommet de la tour ; renvoie la copie et la nouvelle hauteur du sommet
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

-- Construis une nouvelle tour aléatoire, de bas en haut
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 lave monte depuis le sol jusqu’à juste en dessous du sommet de la tour
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

-- Faire le compte à rebours, puis construire la tour
for i = Settings.Intermission, 1, -1 do
	setBoard("Next tower in " .. i)
	task.wait(1)
end
local top = buildTower()
startLava(top)
quiz iconTestez-vous

Cette leçon comprend un petit quiz. Commencez la leçon pour y répondre et suivre votre progression.

Toutes les leçons de Jeu Roblox : tour sans fin