docs(45) + feat(g46): «Кликер»

g45 docs: CodeBoth g45_main.

g46 паритет (заменил simpleClicker fallback):
- GOAL=200, points/perClick/autoIncome
- Heartbeat: каждую секунду points += autoIncome → checkWin
- BindableEvents CubeClicked/BuyPower/BuyAuto
- g46_cube: ClickDetector → CubeClicked:Fire + sparks
- g46_up1/up2: Heartbeat distance(3) + '[E] Купить ...' + InputBegan E
- buyPower: -20 + perClick+=2
- buyAuto: -40 + autoIncome+=3
This commit is contained in:
min 2026-06-09 23:07:25 +03:00
parent 1c5e5fe5bb
commit d758fdfbe6
2 changed files with 162 additions and 3 deletions

View File

@ -4350,7 +4350,166 @@ end)`,
// остальные target-скрипты → красят примитив на касание). // остальные target-скрипты → красят примитив на касание).
// Это даёт «хоть что-то рабочее» в любой игре до того как напишем // Это даёт «хоть что-то рабочее» в любой игре до того как напишем
// полноценный Lua-скрипт. Когда дописываем игру — добавляем сюда явный override. // полноценный Lua-скрипт. Когда дописываем игру — добавляем сюда явный override.
'clicker': { g46_main: simpleClicker() }, 'clicker': {
g46_main: `-- === ИГРА «КЛИКЕР» — главный скрипт (Lua) ===
${SNIPPET_BROADCAST}
local RunService = game:GetService("RunService")
local GOAL = 200
local points = 0
local perClick = 1
local autoIncome = 0
local won = false
__rbxl_score_set(0)
__rbxl_show_text("Кликай по жёлтому кубу! Цель: 200 очков", 4)
local clickSound = Instance.new("Sound", workspace)
clickSound.SoundId = "click"; clickSound.Volume = 0.6
local pickupSound = Instance.new("Sound", workspace)
pickupSound.SoundId = "pickup"; pickupSound.Volume = 0.7
local winSound = Instance.new("Sound", workspace)
winSound.SoundId = "win"; winSound.Volume = 1
local function checkWin()
if not won and points >= GOAL then
won = true
__rbxl_show_text("Победа! Накоплено 200 очков!", 5)
winSound:Play()
local px = __rbxl_player_x()
local py = __rbxl_player_y()
local pz = __rbxl_player_z()
__rbxl_spawn_particles("confetti", px, py + 3, pz, 3, 3)
end
end
-- Авто-доход каждую секунду
local autoTimer = 0
RunService.Heartbeat:Connect(function(dt)
if won then return end
autoTimer = autoTimer + dt
if autoTimer < 1 then return end
autoTimer = 0
if autoIncome > 0 then
points = points + autoIncome
__rbxl_score_set(points)
checkWin()
end
end)
-- Клик по кубу
local clickEvent = getEvent("CubeClicked")
clickEvent.Event:Connect(function()
if won then return end
points = points + perClick
__rbxl_score_set(points)
clickSound:Play()
checkWin()
end)
-- Покупка силы клика (20)
local powerEvent = getEvent("BuyPower")
powerEvent.Event:Connect(function()
if points < 20 then
__rbxl_show_text("Нужно 20 очков для улучшения!", 1.5)
return
end
points = points - 20
perClick = perClick + 2
__rbxl_score_set(points)
pickupSound:Play()
__rbxl_show_text("Сила клика: +" .. perClick .. " за клик", 2)
end)
-- Покупка авто-дохода (40)
local autoEvent = getEvent("BuyAuto")
autoEvent.Event:Connect(function()
if points < 40 then
__rbxl_show_text("Нужно 40 очков для авто-дохода!", 1.5)
return
end
points = points - 40
autoIncome = autoIncome + 3
__rbxl_score_set(points)
pickupSound:Play()
__rbxl_show_text("Авто-доход: +" .. autoIncome .. " в секунду", 2)
end)`,
g46_cube: `-- === Скрипт куба-кликера (Lua) ===
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local part = script.Parent
-- ClickDetector делает куб кликабельным
local cd = Instance.new("ClickDetector")
cd.Parent = part
cd.MouseClick:Connect(function()
__rbxl_spawn_particles("sparks", part.Position.X, part.Position.Y + 1, part.Position.Z, 0.3, 1)
local ev = ReplicatedStorage:FindFirstChild("CubeClicked")
if ev then ev:Fire() end
end)`,
g46_up1: `-- === Скрипт улучшения «сила клика» (20 очков) (Lua) ===
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local part = script.Parent
local hintVisible = false
RunService.Heartbeat:Connect(function()
local px = __rbxl_player_x()
local pz = __rbxl_player_z()
local dx = part.Position.X - px
local dz = part.Position.Z - pz
local dist = math.sqrt(dx*dx + dz*dz)
local near = dist <= 3
if near ~= hintVisible then
hintVisible = near
if near then
__rbxl_hud_set("g46_up1_hint", "[E] Купить +силу клика (20)", 50, 75, "#ffe44a", 20)
else
__rbxl_hud_set("g46_up1_hint", nil)
end
end
end)
UserInputService.InputBegan:Connect(function(input, gp)
if gp then return end
if not hintVisible then return end
if input.KeyCode ~= Enum.KeyCode.E then return end
local ev = ReplicatedStorage:FindFirstChild("BuyPower")
if ev then ev:Fire() end
end)`,
g46_up2: `-- === Скрипт улучшения «авто-доход» (40 очков) (Lua) ===
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local part = script.Parent
local hintVisible = false
RunService.Heartbeat:Connect(function()
local px = __rbxl_player_x()
local pz = __rbxl_player_z()
local dx = part.Position.X - px
local dz = part.Position.Z - pz
local dist = math.sqrt(dx*dx + dz*dz)
local near = dist <= 3
if near ~= hintVisible then
hintVisible = near
if near then
__rbxl_hud_set("g46_up2_hint", "[E] Купить авто-доход (40)", 50, 75, "#ffe44a", 20)
else
__rbxl_hud_set("g46_up2_hint", nil)
end
end
end)
UserInputService.InputBegan:Connect(function(input, gp)
if gp then return end
if not hintVisible then return end
if input.KeyCode ~= Enum.KeyCode.E then return end
local ev = ReplicatedStorage:FindFirstChild("BuyAuto")
if ev then ev:Fire() end
end)`,
},
}; };
// ══════════════════════════════════════════════════════════════════ // ══════════════════════════════════════════════════════════════════

View File

@ -6515,7 +6515,7 @@ game.scene.spawn('user:3', {
<h3 className="lessonH">Шаг 2. Главный скрипт</h3> <h3 className="lessonH">Шаг 2. Главный скрипт</h3>
<ScriptKind kind="global" /> <ScriptKind kind="global" />
<Code>{`// === ИГРА «СТРЕЛЯЛКА-АРЕНА» — главный скрипт === <CodeBoth game="arena-shooter" script="g45_main">{`// === ИГРА «СТРЕЛЯЛКА-АРЕНА» — главный скрипт ===
let score = 0; let score = 0;
const GOAL = 15; const GOAL = 15;
@ -6577,7 +6577,7 @@ game.every(1.8, () => {
} }
} }
}); });
});`}</Code> });`}</CodeBoth>
<p>Разберём:</p> <p>Разберём:</p>
<ul> <ul>
<li><code>game.onHpChange((e) ={'>'} ...)</code> <li><code>game.onHpChange((e) ={'>'} ...)</code>