Menu
CoddyTech

Lave montante

Leçon 11 sur 21 du cours Jeu Roblox : Tour infinie de Coddy.

Attendre en bas ne devrait pas être sans danger. Une nappe de lave apparaît sous la tour et, après Settings.LavaDelay secondes, monte régulièrement jusqu'à se trouver à 2 studs sous le sommet, donc tout le monde doit continuer à grimper.

Une interpolation peut attendre avant de démarrer : le sixième argument de TweenInfo.new est un délai en secondes. Pour une montée régulière, la durée de l'interpolation est égale à la distance divisée par la vitesse :

-- 60 studs à raison de 3 studs par seconde, après 4 secondes
local info = TweenInfo.new(60 / 3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 4)

La lave n'est pas solide (CanCollide false), donc personne ne peut se tenir dessus, et son événement Touched utilise killOnTouch, la même fonction que les briques mortelles. Elle commence à une hauteur de -2 et monte jusqu'à top - 2, soit exactement top studs.

challenge icon

Défi

Moyen

La lave monte sous la tour.

  1. Fais en sorte que buildTower renvoie top, et termine le script par startLava(buildTower()).
  2. Écris startLava(top) : définis une variable lava de niveau supérieur comme une Part ancrée nommée Lava, avec CanCollide à false, aux coordonnées (0, -2, 0), et connecte Touched à killOnTouch.
  3. Anime-la jusqu’à (0, top - 2, 0) en top / Settings.LavaSpeed secondes, avec une interpolation Linear et un délai de Settings.LavaDelay.

Clique sur « Jouer » : après 10 secondes, la lave commence à monter sous tes pieds. Puis clique sur « Vérifier ».

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

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)

-- 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 qui disparaît s’estompe peu après qu’un joueur y atterrit, 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 dans les airs 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 tournants pivotent 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)

-- Activer tous les obstacles d’une étape selon leurs 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

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

-- Placer 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

-- Construire 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)
end

-- Leçon 11 : la lave montante va ici

buildTower()
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 infinie

Entraînez-vous par vous-même : Playground Roblox