Run it
Copy the script and paste it into your executor.
Players = :()
CoreGui = :()
UserInputService = :()
CoreGui:()
CoreGui.SnakeGameGui:()
gridSize =
boardWidth =
boardHeight =
snake = {}
direction = .(, )
nextDirection = direction
foodPos = .(, )
score =
gameRunning =
moveInterval =
lastMove =
sg = .()
sg.Name =
sg.Parent = CoreGui
mainFrame = .()
mainFrame.Size = .(, boardWidth * gridSize + , , boardHeight * gridSize + )
mainFrame.Position = .(, -(boardWidth * gridSize) / , , -(boardHeight * gridSize) / )
mainFrame.BackgroundColor3 = .(, , )
mainFrame.BorderSizePixel =
mainFrame.Active =
mainFrame.Draggable =
mainFrame.Parent = sg
title = .()
title.Size = .(, -, , )
title.Text =
title.TextColor3 = .(, , )
title.BackgroundColor3 = .(, , )
title.Font = .Font.SourceSansBold
title.TextSize =
title.TextXAlignment = .TextXAlignment.Left
title.Parent = mainFrame
scoreLabel = .()
scoreLabel.Size = .(, , , )
scoreLabel.Position = .(, , , )
scoreLabel.Text =
scoreLabel.TextColor3 = .(, , )
scoreLabel.BackgroundTransparency =
scoreLabel.Font = .Font.SourceSansBold
scoreLabel.TextSize =
scoreLabel.Parent = mainFrame
board = .()
board.Size = .(, boardWidth * gridSize, , boardHeight * gridSize)
board.Position = .(, , , )
board.BackgroundColor3 = .(, , )
board.BorderColor3 = .(, , )
board.ClipsDescendants =
board.Parent = mainFrame
controls = .()
controls.Size = .(, , , )
controls.Position = .(, -, , -)
controls.BackgroundTransparency =
controls.Parent = mainFrame
(text, pos, dir)
btn = .()
btn.Size = .(, , , )
btn.Position = pos
btn.Text = text
btn.BackgroundColor3 = .(, , )
btn.TextColor3 = .(, , )
btn.Font = .Font.SourceSansBold
btn.TextSize =
btn.Parent = controls
btn.MouseButton1Click:(()
(dir.X ~= -direction.X dir.X == ) (dir.Y ~= -direction.Y dir.Y == )
nextDirection = dir
)
(, .(, , , ), .(, -))
(, .(, , , ), .(, ))
(, .(, , , ), .(-, ))
(, .(, , , ), .(, ))
closeBtn = .()
closeBtn.Size = .(, , , )
closeBtn.Position = .(, -, , )
closeBtn.Text =
closeBtn.TextColor3 = .(, , )
closeBtn.BackgroundColor3 = .(, , )
closeBtn.BorderSizePixel =
closeBtn.TextSize =
closeBtn.Parent = mainFrame
closeBtn.MouseButton1Click:(()
gameRunning =
sg:()
)
()
valid =
valid
valid =
foodPos = .(.(, boardWidth - ), .(, boardHeight - ))
_, segment (snake)
segment == foodPos valid =
()
board:()
foodFrame = .()
foodFrame.Size = .(, gridSize - , , gridSize - )
foodFrame.Position = .(, foodPos.X * gridSize, , foodPos.Y * gridSize)
foodFrame.BackgroundColor3 = .(, , )
foodFrame.BorderSizePixel =
foodFrame.Parent = board
i, segment (snake)
segFrame = .()
segFrame.Size = .(, gridSize - , , gridSize - )
segFrame.Position = .(, segment.X * gridSize, , segment.Y * gridSize)
segFrame.BackgroundColor3 = (i == ) .(, , ) .(, , )
segFrame.BorderSizePixel =
segFrame.Parent = board
()
snake = {.(, ), .(, )}
direction = .(, )
nextDirection = direction
score =
scoreLabel.Text = .. score
()
gameRunning =
UserInputService.InputBegan:((input, processed)
processed
input.KeyCode == .KeyCode.W input.KeyCode == .KeyCode.Up
direction.Y == nextDirection = .(, -)
input.KeyCode == .KeyCode.S input.KeyCode == .KeyCode.Down
direction.Y == nextDirection = .(, )
input.KeyCode == .KeyCode.A input.KeyCode == .KeyCode.Left
direction.X == nextDirection = .(-, )
input.KeyCode == .KeyCode.D input.KeyCode == .KeyCode.Right
direction.X == nextDirection = .(, )
)
()
:().Heartbeat:(()
gameRunning
now = .()
now - lastMove >= moveInterval
lastMove = now
direction = nextDirection
head = snake[]
newHead = head + direction
newHead.X < newHead.X >= boardWidth newHead.Y < newHead.Y >= boardHeight
()
i, segment (snake)
segment == newHead
()
.(snake, , newHead)
newHead == foodPos
score = score +
scoreLabel.Text = .. score
()
.(snake)
()
)
Just a snake mini game

Universal