Menu
CoddyTech

Lava Ascendente

Lição 11 de 21 do curso Jogo de Roblox: Torre Infinita da Coddy.

Esperar na parte de baixo não deve ser seguro. Uma camada de lava começa embaixo da torre e, após Settings.LavaDelay segundos, sobe continuamente até ficar 2 studs abaixo do topo, então todos precisam continuar subindo.

Um tween pode esperar antes de começar: o sexto argumento de TweenInfo.new é um atraso em segundos. Para uma subida constante, o tempo do tween é a distância dividida pela velocidade:

-- 60 studs a 3 studs por segundo, após 4 segundos
local info = TweenInfo.new(60 / 3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 4)

A lava não é sólida (CanCollide false), então ninguém pode ficar em cima dela, e seu evento Touched usa killOnTouch, a mesma função dos blocos mortais. Ela começa na altura -2 e sobe até top - 2, exatamente top studs.

challenge icon

Desafio

Médio

A lava sobe por baixo da torre.

  1. Faça buildTower retornar top e termine o script com startLava(buildTower()).
  2. Escreva startLava(top): defina lava no escopo global como uma Part ancorada chamada Lava, com CanCollide false, em (0, -2, 0) e Touched conectado a killOnTouch.
  3. Anime-a até (0, top - 2, 0) ao longo de top / Settings.LavaSpeed segundos, com Linear e atraso de Settings.LavaDelay.

Pressione “Jogar”: depois de 10 segundos, a lava começa a subir por baixo de você. Em seguida, pressione “Verificar”.

Experimente você mesmo

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

-- Todo jogador recebe Wins no placar de líderes
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)

-- Qualquer coisa com a tag Kill tira uma vida
local function killOnTouch(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

-- Uma plataforma que desaparece fica transparente logo depois que alguém pisa nela e, então, 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

-- Um laser desliza até o deslocamento definido por Slide e volta, 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

-- Uma plataforma de impulso lança para o alto quem cair nela
local function bounce(hit)
	local root = hit.Parent:FindFirstChild("HumanoidRootPart")
	if root then
		root.AssemblyLinearVelocity = Vector3.new(0, Settings.BouncePower, 0)
	end
end

-- Os obstáculos giratórios giram um pouco a cada quadro
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)

-- Ative todos os obstáculos de uma fase de acordo com suas 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

-- Uma fase qualquer, escolhida aleatoriamente
local function pickStage()
	local all = stages:GetChildren()
	return all[math.random(1, #all)]
end

-- Coloque uma cópia de um modelo no topo da torre; retorna a cópia e a nova altura do topo
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

-- Construa uma nova torre aleatória, de baixo para cima
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

-- Lição 11: Rising Lava entra aqui

buildTower()
quiz iconTeste seus conhecimentos

Esta lição inclui um quiz rápido. Comece a lição para respondê-lo e acompanhar seu progresso.

Todas as lições de Jogo de Roblox: Torre Infinita

Pratique por conta própria: Playground de Roblox