Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Создание GUI элементов
- local screenGui = Instance.new("ScreenGui")
- screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
- local backgroundFrame = Instance.new("Frame")
- backgroundFrame.Parent = screenGui
- backgroundFrame.Size = UDim2.new(1, 0, 1, 0) -- Во весь экран
- backgroundFrame.Position = UDim2.new(0, 0, 0, 0)
- backgroundFrame.BackgroundColor3 = Color3.new(1, 1, 1) -- Белый фон
- local sheepImage = Instance.new("ImageLabel")
- sheepImage.Name = "SheepImage"
- sheepImage.Parent = backgroundFrame
- sheepImage.Size = UDim2.new(0, 100, 0, 100) -- Размер барашка
- sheepImage.Position = UDim2.new(0.1, 0, 0.7, 0) -- Позиция барашка слева и чуть ниже
- sheepImage.Image = "rbxassetid://108390234749539" -- ID изображения барашка
- sheepImage.BackgroundTransparency = 1 -- Прозрачный фон
- local fenceImage = Instance.new("ImageLabel")
- fenceImage.Name = "FenceImage"
- fenceImage.Parent = backgroundFrame
- fenceImage.Size = UDim2.new(0, 200, 0, 50) -- Размер забора
- fenceImage.Position = UDim2.new(1, 0, 0.75, 0) -- Начальная позиция забора за экраном справа
- fenceImage.Image = "rbxassetid://70673399094620" -- ID изображения забора
- fenceImage.BackgroundTransparency = 1 -- Прозрачный фон
- local gameOverText = Instance.new("TextLabel")
- gameOverText.Parent = backgroundFrame
- gameOverText.Size = UDim2.new(0.5, 0, 0.1, 0)
- gameOverText.Position = UDim2.new(0.25, 0, 0.4, 0)
- gameOverText.Text = "Игра окончена"
- gameOverText.TextScaled = true
- gameOverText.Visible = false
- gameOverText.BackgroundTransparency = 1 -- Прозрачный фон
- local countdownText = Instance.new("TextLabel")
- countdownText.Parent = backgroundFrame
- countdownText.Size = UDim2.new(0.5, 0, 0.1, 0)
- countdownText.Position = UDim2.new(0.25, 0, 0.5, 0)
- countdownText.TextScaled = true
- countdownText.Visible = false
- countdownText.BackgroundTransparency = 1 -- Прозрачный фон
- local jumpCounterText = Instance.new("TextLabel")
- jumpCounterText.Parent = backgroundFrame
- jumpCounterText.Size = UDim2.new(0.1, 0, 0.05, 0)
- jumpCounterText.Position = UDim2.new(0, 0, 0, 0)
- jumpCounterText.TextScaled = true
- jumpCounterText.Text = "Прыжки: 0"
- jumpCounterText.BackgroundTransparency = 1 -- Прозрачный фон
- -- Скрипт для прыжка барашка и движения забора
- local userInputService = game:GetService("UserInputService")
- local jumpHeight = 0.1 -- Высота прыжка (в масштабах UDim2)
- local jumpDuration = 0.5
- local isJumping = false
- local gameOver = false
- local jumpCounter = 0
- local function resetGame()
- print("Сброс игры")
- gameOverText.Visible = false
- countdownText.Visible = false
- sheepImage.Position = UDim2.new(0.1, 0, 0.7, 0)
- fenceImage.Position = UDim2.new(1, 0, 0.75, 0)
- gameOver = false
- jumpCounter = 0
- jumpCounterText.Text = "Прыжки: 0"
- wait(1) -- Небольшая задержка перед началом движения забора
- moveFence()
- end
- local function countdown()
- print("Начало отсчета")
- for i = 5, 1, -1 do
- countdownText.Text = tostring(i)
- wait(1)
- end
- resetGame()
- end
- local function endGame()
- print("Конец игры")
- gameOver = true
- gameOverText.Visible = true
- countdownText.Visible = true
- countdown()
- end
- local function checkCollision()
- local sheepLeft = sheepImage.AbsolutePosition.X
- local sheepRight = sheepLeft + sheepImage.AbsoluteSize.X
- local sheepTop = sheepImage.AbsolutePosition.Y
- local sheepBottom = sheepTop + sheepImage.AbsoluteSize.Y
- local fenceLeft = fenceImage.AbsolutePosition.X
- local fenceRight = fenceLeft + fenceImage.AbsoluteSize.X
- local fenceTop = fenceImage.AbsolutePosition.Y
- local fenceBottom = fenceTop + fenceImage.AbsoluteSize.Y
- if sheepRight > fenceLeft and sheepLeft < fenceRight and sheepBottom > fenceTop and sheepTop < fenceBottom then
- print("Столкновение обнаружено")
- endGame()
- end
- end
- local function jump()
- if isJumping or gameOver then return end
- isJumping = true
- local originalPosition = sheepImage.Position
- local targetPosition = UDim2.new(originalPosition.X.Scale, originalPosition.X.Offset, originalPosition.Y.Scale - jumpHeight, originalPosition.Y.Offset)
- sheepImage:TweenPosition(targetPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, jumpDuration, true, function()
- sheepImage:TweenPosition(originalPosition, Enum.EasingDirection.In, Enum.EasingStyle.Quad, jumpDuration, true, function()
- isJumping = false
- end)
- end)
- end
- local function moveFence()
- if gameOver then return end
- print("Движение забора")
- local startPosition = UDim2.new(1, 0, 0.75, 0)
- local endPosition = UDim2.new(-0.2, 0, 0.75, 0) -- Конечная позиция забора за экраном слева
- fenceImage.Position = startPosition
- fenceImage:TweenPosition(endPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 2, true, function()
- if not gameOver then
- checkCollision()
- if fenceImage.Position.X.Scale < sheepImage.Position.X.Scale then
- jumpCounter = jumpCounter + 1
- jumpCounterText.Text = "Прыжки: " .. jumpCounter
- end
- moveFence() -- Повторное движение забора
- end
- end)
- end
- userInputService.InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.Space then
- jump()
- end
- if input.KeyCode == Enum.KeyCode.RightControl then
- screenGui:Destroy()
- end
- end)
- userInputService.TouchTap:Connect(function()
- jump()
- end)
- -- Добавляем проверку столкновения в основной цикл
- game:GetService("RunService").RenderStepped:Connect(function()
- if not gameOver then
- checkCollision()
- end
- end)
- moveFence() -- Начать движение забора
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement