Menu
CoddyTech

웨이브

Coddy의 Roblox 게임: 타워 디펜스 코스 레슨. 18개 중 4번째.

좀비 한 마리로는 게임이라고 할 수 없습니다. Settings.Waves에는 각 웨이브가 적 이름 목록으로 나열되어 있습니다:

Waves = {
	{ "Zombie", "Zombie", "Zombie" },
	{ "Zombie", "Runner" },
}

runWave(list)는 적을 하나씩 생성하며, 각 적 생성 간격은 Settings.SpawnGap초입니다. 그런 다음 workspace.Enemies가 비워질 때까지 기다리므로, 현재 웨이브가 끝난 뒤에만 다음 웨이브가 시작됩니다. 각 웨이브가 시작되기 전에 플레이어에게는 준비할 Settings.WaveBreak초가 주어집니다.

메인 루프는 웨이브를 순서대로 진행합니다: for i, list in Settings.Waves do.

challenge icon

챌린지

쉬움
  1. runWave(list)를 작성하세요. 목록의 적을 하나씩 생성하고, 각각 생성한 후 Settings.SpawnGap만큼 기다린 다음 enemies에 자식이 없어질 때까지 기다리세요.
  2. 한 번만 생성하던 부분을 Settings.Waves를 반복하는 루프로 바꾸세요. Settings.WaveBreak만큼 기다린 다음 웨이브를 실행하세요.

이 레슨의 월드에는 짧은 웨이브가 두 번 있습니다. 플레이를 누른 다음 확인을 누르세요.

직접 해보기

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

local enemies = workspace.Enemies

print("The base can take " .. Settings.BaseHealth .. " hits")

-- 순서대로 나열된 경유 지점들 (이름은 1, 2, 3...)
local waypoints = workspace.Path.Waypoints:GetChildren()
table.sort(waypoints, function(a, b)
	return tonumber(a.Name) < tonumber(b.Name)
end)

-- workspace의 속성으로 저장된 기지 체력: 모든 클라이언트가 읽을 수 있음
workspace:SetAttribute("BaseHealth", Settings.BaseHealth)

-- 모든 플레이어가 리더보드에서 Money를 받음
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = Settings.StartMoney
	money.Parent = leaderstats
end)

-- 적이 기지에 도달함
local function damageBase(amount)
	local health = math.max(0, workspace:GetAttribute("BaseHealth") - amount)
	workspace:SetAttribute("BaseHealth", health)
end

-- 적을 경로를 따라 이동시킴. MoveTo는 8초가 지나면 이동 시도를 중단하고 이를 알림
-- (MoveToFinished가 false를 반환), 따라서 느린 적은 도착할 때까지 다시 이동 명령을 받음.
local function walkPath(enemy)
	local humanoid = enemy.Humanoid
	for i = 2, #waypoints do
		repeat
			humanoid:MoveTo(waypoints[i].Position)
		until humanoid.MoveToFinished:Wait() or not enemy.Parent
		if not enemy.Parent then
			return
		end
	end
	-- 적이 기지에 도달함
	damageBase(1)
	enemy:Destroy()
end

-- 입구에 나타나 경로를 따라 이동하는 새로운 적
local function spawnEnemy(kind)
	local enemy = ServerStorage.Enemies[kind]:Clone()
	-- 첫 번째 경유 지점 바로 위에 배치됨
	enemy:PivotTo(waypoints[1].CFrame + Vector3.new(0, 5, 0))
	enemy.Parent = enemies
	task.spawn(walkPath, enemy)
	return enemy
end

-- 지금은 적 한 마리만
spawnEnemy("Zombie")
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

Roblox 게임: 타워 디펜스의 모든 레슨