Menu
CoddyTech

הצפה עולה

שיעור 11 מתוך 20 בקורס משחק Roblox: הישרדות באסונות של Coddy.

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

TweenService משנה מאפיין בצורה חלקה לאורך זמן: מתארים כמה זמן באמצעות TweenInfo, נותנים את ערכי היעד בטבלה, ואז מפעילים אותו באמצעות Play:

local rise = TweenInfo.new(6, Enum.EasingStyle.Linear)
TweenService:Create(water, rise, { Position = water.Position + Vector3.new(0, 3, 0) }):Play()

Enum.EasingStyle.Linear שומר על קצב קבוע; ברירת המחדל מתחילה מהר ומאטה. ה־tween פועל מעצמו, כך שספירת הזמן לאחור של הסבב נמשכת בזמן שהמים עולים.

challenge icon

אתגר

בינוני

גרמו למים להציף את האי.

  1. קחו את TweenService בראש הקובץ.
  2. בסוף Disasters.Flood, הנפישו את מיקום המים 8 יחידות למעלה במשך Settings.RoundLength * 0.8 שניות, באמצעות Enum.EasingStyle.Linear.

לחצו על "שחק": המים עולים מעל האי ועוצרים מתחת לפסגות הסלעים. לאחר מכן לחצו על "בדיקה".

נסו בעצמכם

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Settings = require(game.ReplicatedStorage.Settings)

local lobbySpawn = workspace.LobbySpawn

print("Rounds last " .. Settings.RoundLength .. " seconds")

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

-- לוח הסטטוס בלובי
local gui = Instance.new("SurfaceGui")
gui.Parent = workspace.StatusBoard

local status = Instance.new("TextLabel")
status.Name = "Status"
status.Size = UDim2.fromScale(1, 1)
status.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
status.TextColor3 = Color3.fromRGB(255, 255, 255)
status.TextScaled = true
status.Text = "Welcome to Disaster Survival!"
status.Parent = gui

local function setStatus(text)
	status.Text = text
end

local function teleport(player, target)
	local character = player.Character
	if character then
		character:PivotTo(target.CFrame + Vector3.new(0, 4, 0))
	end
end

local function defeat(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

-- האסונות, לפי שם
local Disasters = {}

function Disasters.Flood(map)
	local base = map.Base
	local water = Instance.new("Part")
	water.Name = "Water"
	water.Anchored = true
	water.CanCollide = false
	water.Transparency = 0.3
	water.Color = Color3.fromRGB(40, 120, 255)
	water.Size = Vector3.new(base.Size.X + 10, 1, base.Size.Z + 10)
	water.Position = base.Position - Vector3.new(0, 2, 0)
	water.Parent = map
	water.Touched:Connect(defeat)
	-- שיעור 11: כאן יופיע השיטפון העולה
end

-- הלולאה של סבבי המשחק
while true do
	for seconds = Settings.Intermission, 1, -1 do
		setStatus("Intermission: " .. seconds)
		task.wait(1)
	end

	local map = ServerStorage.Maps.Island:Clone()
	map.Name = "Map"
	map.Parent = workspace

	local survivors = {}
	for _, player in Players:GetPlayers() do
		local character = player.Character
		if character and character.Humanoid.Health > 0 then
			teleport(player, map.Spawn)
			survivors[player] = true
			character.Humanoid.Died:Connect(function()
				survivors[player] = nil
			end)
		end
	end

	Disasters.Flood(map)
	for seconds = Settings.RoundLength, 1, -1 do
		setStatus("Time left: " .. seconds)
		task.wait(1)
	end

	local names = {}
	for player in survivors do
		player.leaderstats.Wins.Value += 1
		teleport(player, lobbySpawn)
		table.insert(names, player.Name)
	end
	map:Destroy()
	if #names > 0 then
		setStatus("Winners: " .. table.concat(names, ", "))
	else
		setStatus("Nobody survived!")
	end
	task.wait(3)
end

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

תרגלו בעצמכם: Roblox אונליין