Menu
CoddyTech

לבה עולה

שיעור 10 מתוך 18 בקורס משחק Roblox: מגדל אינסופי של Coddy.

המתנה בתחתית לא אמורה להיות בטוחה. יריעת לבה מתחילה מתחת למגדל, ולאחר השהיה קצרה עולה בהתמדה עד שהיא נמצאת 2 studs מתחת לחלק העליון, כך שכולם צריכים להמשיך לטפס.

אפשר להשהות tween לפני שהוא מתחיל: הארגומנט השישי של TweenInfo.new הוא השהיה בשניות. כדי שהטיפוס יהיה אחיד, הזמן של ה-tween הוא המרחק חלקי המהירות:

local seconds = top / Settings.LavaSpeed
local info = TweenInfo.new(seconds, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, Settings.LavaDelay)

הלבה אינה מוצקה (CanCollide false), כך שאף אחד לא יכול לעמוד עליה, והאירוע Touched שלה משתמש ב-killOnTouch, אותה פונקציה כמו של לבני ההריגה. היא מתחילה בגובה -2 ועולה עד top - 2, בדיוק top studs.

challenge icon

אתגר

בינוני
  1. בסמוך להתחלה: local lava = nil. יש להגדיר את buildTower כך שתחזיר את top.
  2. כתבו את startLava(top): צרו Part מעוגן בשם Lava, ללא CanCollide, בגודל 30 על 2 על 30, במיקום Vector3.new(0, -2, 0), בצבע כתום מסוג Neon (Color3.fromRGB(255, 90, 20)), בתוך workspace, וחברו את Touched ל־killOnTouch. בצעו Tween ל־Position אל Vector3.new(0, top - 2, 0) במשך top / Settings.LavaSpeed שניות, בסגנון Linear, לאחר השהיה של Settings.LavaDelay.
  3. בסוף: local top = buildTower() ואז startLava(top).

הלבה בשיעור הזה מהירה, כדי שהבדיקה תהיה קצרה. לחצו על Play, ואז על Check.

נסו בעצמכם

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

-- כל שחקן מקבל 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)

-- כל דבר עם התג 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)
end

buildTower()
quiz iconבחנו את עצמכם

השיעור הזה כולל חידון קצר. התחילו את השיעור כדי לענות עליו ולעקוב אחרי ההתקדמות.

כל השיעורים ביחידה משחק Roblox: מגדל אינסופי