Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- warn([[
- = Made by KrYn0MoRe (AlmightyToast) =
- - Settings added
- - Boosting added (hold space)
- ]])
- local plr = game:GetService("Players").LocalPlayer
- --
- ScreenGui0 = Instance.new("ScreenGui")
- Frame1 = Instance.new("Frame")
- Frame2 = Instance.new("Frame")
- TextBox3 = Instance.new("TextBox")
- TextButton4 = Instance.new("TextButton")
- TextButton5 = Instance.new("TextButton")
- Frame6 = Instance.new("Frame")
- TextButton7 = Instance.new("TextButton")
- TextButton8 = Instance.new("TextButton")
- TextButton9 = Instance.new("TextButton")
- TextButton10 = Instance.new("TextButton")
- Frame11 = Instance.new("Frame")
- TextLabel12 = Instance.new("TextLabel")
- TextLabel13 = Instance.new("TextLabel")
- TextLabel14 = Instance.new("TextLabel")
- TextLabel15 = Instance.new("TextLabel")
- TextLabel16 = Instance.new("TextLabel")
- ScreenGui0.Parent = nil
- ScreenGui0.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
- Frame1.Name = "Main"
- Frame1.Parent = ScreenGui0
- Frame1.Position = UDim2.new(0.5, -250, 0.5, -250)
- Frame1.Size = UDim2.new(0, 500, 0, 500)
- Frame1.BackgroundColor = BrickColor.new("Institutional white")
- Frame1.BackgroundColor3 = Color3.new(1, 1, 1)
- Frame1.BackgroundTransparency = 1
- Frame2.Name = "Map"
- Frame2.Parent = Frame1
- Frame2.Size = UDim2.new(1, 0, 1, 0)
- Frame2.BackgroundColor = BrickColor.new("Institutional white")
- Frame2.BackgroundColor3 = Color3.new(1, 1, 1)
- TextBox3.Name = "Title"
- TextBox3.Parent = Frame1
- TextBox3.Position = UDim2.new(0, 0, -0.200000003, 50)
- TextBox3.Size = UDim2.new(1, 0, 0, 50)
- TextBox3.BackgroundColor = BrickColor.new("Institutional white")
- TextBox3.BackgroundColor3 = Color3.new(1, 1, 1)
- TextBox3.BackgroundTransparency = 1
- TextBox3.Font = Enum.Font.SourceSans
- TextBox3.FontSize = Enum.FontSize.Size14
- TextBox3.Text = "Score: 0"
- TextBox3.TextColor = BrickColor.new("Institutional white")
- TextBox3.TextColor3 = Color3.new(1, 1, 1)
- TextBox3.TextScaled = true
- TextBox3.TextSize = 14
- TextBox3.TextStrokeTransparency = 0
- TextBox3.TextWrap = true
- TextBox3.TextWrapped = true
- TextButton4.Name = "settings_button"
- TextButton4.Parent = Frame1
- TextButton4.Position = UDim2.new(1.01800001, 0, -0.0020000299, 0)
- TextButton4.Size = UDim2.new(0, 100, 0, 100)
- TextButton4.BackgroundColor = BrickColor.new("Institutional white")
- TextButton4.BackgroundColor3 = Color3.new(1, 1, 1)
- TextButton4.BackgroundTransparency = 0.5
- TextButton4.Font = Enum.Font.SourceSans
- TextButton4.FontSize = Enum.FontSize.Size14
- TextButton4.Text = "Settings"
- TextButton4.TextColor = BrickColor.new("Institutional white")
- TextButton4.TextColor3 = Color3.new(1, 1, 1)
- TextButton4.TextScaled = true
- TextButton4.TextSize = 14
- TextButton4.TextStrokeTransparency = 0
- TextButton4.TextWrap = true
- TextButton4.TextWrapped = true
- TextButton5.Name = "close"
- TextButton5.Parent = Frame1
- TextButton5.Position = UDim2.new(0.931999981, 0, -0.0839999989, 0)
- TextButton5.Size = UDim2.new(0, 34, 0, 34)
- TextButton5.BackgroundColor = BrickColor.new("Really red")
- TextButton5.BackgroundColor3 = Color3.new(1, 0, 0)
- TextButton5.Font = Enum.Font.SourceSans
- TextButton5.FontSize = Enum.FontSize.Size14
- TextButton5.Text = "X"
- TextButton5.TextColor = BrickColor.new("Institutional white")
- TextButton5.TextColor3 = Color3.new(1, 1, 1)
- TextButton5.TextScaled = true
- TextButton5.TextSize = 14
- TextButton5.TextStrokeTransparency = 0
- TextButton5.TextWrap = true
- TextButton5.TextWrapped = true
- Frame6.Name = "Settings"
- Frame6.Parent = Frame1
- Frame6.Visible = false
- Frame6.Size = UDim2.new(1, 0, 1, 0)
- Frame6.BackgroundColor = BrickColor.new("Institutional white")
- Frame6.BackgroundColor3 = Color3.new(1, 1, 1)
- TextButton7.Name = "theme"
- TextButton7.Parent = Frame6
- TextButton7.Position = UDim2.new(0.399999976, 0, 0.717999995, 0)
- TextButton7.Size = UDim2.new(0, 100, 0, 100)
- TextButton7.BackgroundColor = BrickColor.new("Institutional white")
- TextButton7.BackgroundColor3 = Color3.new(1, 1, 1)
- TextButton7.Font = Enum.Font.SourceSans
- TextButton7.FontSize = Enum.FontSize.Size14
- TextButton7.Text = "LightMode"
- TextButton7.TextColor = BrickColor.new("Institutional white")
- TextButton7.TextColor3 = Color3.new(1, 1, 1)
- TextButton7.TextScaled = true
- TextButton7.TextSize = 14
- TextButton7.TextStrokeTransparency = 0
- TextButton7.TextWrap = true
- TextButton7.TextWrapped = true
- TextButton8.Name = "trail"
- TextButton8.Parent = Frame6
- TextButton8.Position = UDim2.new(0.699999928, 0, 0.717999995, 0)
- TextButton8.Size = UDim2.new(0, 100, 0, 100)
- TextButton8.BackgroundColor = BrickColor.new("Really red")
- TextButton8.BackgroundColor3 = Color3.new(1, 0, 0)
- TextButton8.Font = Enum.Font.SourceSans
- TextButton8.FontSize = Enum.FontSize.Size14
- TextButton8.Text = "Trail Fade"
- TextButton8.TextColor = BrickColor.new("Institutional white")
- TextButton8.TextColor3 = Color3.new(1, 1, 1)
- TextButton8.TextScaled = true
- TextButton8.TextSize = 14
- TextButton8.TextStrokeTransparency = 0
- TextButton8.TextWrap = true
- TextButton8.TextWrapped = true
- TextButton9.Name = "color"
- TextButton9.Parent = Frame6
- TextButton9.Position = UDim2.new(0.101999953, 0, 0.717999995, 0)
- TextButton9.Size = UDim2.new(0, 100, 0, 100)
- TextButton9.BackgroundColor = BrickColor.new("Lime green")
- TextButton9.BackgroundColor3 = Color3.new(0, 1, 0)
- TextButton9.Font = Enum.Font.SourceSans
- TextButton9.FontSize = Enum.FontSize.Size14
- TextButton9.Text = "Snake Color 2"
- TextButton9.TextColor = BrickColor.new("Institutional white")
- TextButton9.TextColor3 = Color3.new(1, 1, 1)
- TextButton9.TextScaled = true
- TextButton9.TextSize = 14
- TextButton9.TextStrokeTransparency = 0
- TextButton9.TextWrap = true
- TextButton9.TextWrapped = true
- TextButton10.Name = "start"
- TextButton10.Parent = Frame1
- TextButton10.Position = UDim2.new(1.01800001, 0, 0.199999973, 0)
- TextButton10.Size = UDim2.new(0, 100, 0, 100)
- TextButton10.BackgroundColor = BrickColor.new("Institutional white")
- TextButton10.BackgroundColor3 = Color3.new(1, 1, 1)
- TextButton10.BackgroundTransparency = 0.5
- TextButton10.Font = Enum.Font.SourceSans
- TextButton10.FontSize = Enum.FontSize.Size14
- TextButton10.Text = "Start"
- TextButton10.TextColor = BrickColor.new("Institutional white")
- TextButton10.TextColor3 = Color3.new(1, 1, 1)
- TextButton10.TextScaled = true
- TextButton10.TextSize = 14
- TextButton10.TextStrokeTransparency = 0
- TextButton10.TextWrap = true
- TextButton10.TextWrapped = true
- Frame11.Name = "Input"
- Frame11.Parent = Frame1
- Frame11.Position = UDim2.new(-0.459999979, 0, 0.197999999, 0)
- Frame11.Size = UDim2.new(0.405999988, 0, 0.540000021, 0)
- Frame11.BackgroundColor = BrickColor.new("Institutional white")
- Frame11.BackgroundColor3 = Color3.new(1, 1, 1)
- TextLabel12.Name = "w"
- TextLabel12.Parent = Frame11
- TextLabel12.Position = UDim2.new(0.374384224, 0, 0.0962962955, 0)
- TextLabel12.Size = UDim2.new(0, 50, 0, 50)
- TextLabel12.BackgroundColor = BrickColor.new("Really red")
- TextLabel12.BackgroundColor3 = Color3.new(1, 0, 0)
- TextLabel12.Font = Enum.Font.SourceSans
- TextLabel12.FontSize = Enum.FontSize.Size14
- TextLabel12.Text = "W"
- TextLabel12.TextColor = BrickColor.new("Really black")
- TextLabel12.TextColor3 = Color3.new(0, 0, 0)
- TextLabel12.TextScaled = true
- TextLabel12.TextSize = 14
- TextLabel12.TextWrap = true
- TextLabel12.TextWrapped = true
- TextLabel13.Name = "s"
- TextLabel13.Parent = Frame11
- TextLabel13.Position = UDim2.new(0.374384224, 0, 0.34074074, 0)
- TextLabel13.Size = UDim2.new(0, 50, 0, 50)
- TextLabel13.BackgroundColor = BrickColor.new("Really red")
- TextLabel13.BackgroundColor3 = Color3.new(1, 0, 0)
- TextLabel13.Font = Enum.Font.SourceSans
- TextLabel13.FontSize = Enum.FontSize.Size14
- TextLabel13.Text = "S"
- TextLabel13.TextColor = BrickColor.new("Really black")
- TextLabel13.TextColor3 = Color3.new(0, 0, 0)
- TextLabel13.TextScaled = true
- TextLabel13.TextSize = 14
- TextLabel13.TextWrap = true
- TextLabel13.TextWrapped = true
- TextLabel14.Name = "d"
- TextLabel14.Parent = Frame11
- TextLabel14.Position = UDim2.new(0.68472904, 0, 0.34074074, 0)
- TextLabel14.Size = UDim2.new(0, 50, 0, 50)
- TextLabel14.BackgroundColor = BrickColor.new("Really red")
- TextLabel14.BackgroundColor3 = Color3.new(1, 0, 0)
- TextLabel14.Font = Enum.Font.SourceSans
- TextLabel14.FontSize = Enum.FontSize.Size14
- TextLabel14.Text = "D"
- TextLabel14.TextColor = BrickColor.new("Really black")
- TextLabel14.TextColor3 = Color3.new(0, 0, 0)
- TextLabel14.TextScaled = true
- TextLabel14.TextSize = 14
- TextLabel14.TextWrap = true
- TextLabel14.TextWrapped = true
- TextLabel15.Name = "a"
- TextLabel15.Parent = Frame11
- TextLabel15.Position = UDim2.new(0.0738915801, 0, 0.34074074, 0)
- TextLabel15.Size = UDim2.new(0, 50, 0, 50)
- TextLabel15.BackgroundColor = BrickColor.new("Lime green")
- TextLabel15.BackgroundColor3 = Color3.new(0, 1, 0)
- TextLabel15.Font = Enum.Font.SourceSans
- TextLabel15.FontSize = Enum.FontSize.Size14
- TextLabel15.Text = "A"
- TextLabel15.TextColor = BrickColor.new("Really black")
- TextLabel15.TextColor3 = Color3.new(0, 0, 0)
- TextLabel15.TextScaled = true
- TextLabel15.TextSize = 14
- TextLabel15.TextWrap = true
- TextLabel15.TextWrapped = true
- TextLabel16.Name = "space"
- TextLabel16.Parent = Frame11
- TextLabel16.Position = UDim2.new(0.0738915503, 0, 0.577777803, 0)
- TextLabel16.Size = UDim2.new(0, 174, 0, 96)
- TextLabel16.BackgroundColor = BrickColor.new("Really red")
- TextLabel16.BackgroundColor3 = Color3.new(1, 0, 0)
- TextLabel16.Font = Enum.Font.SourceSans
- TextLabel16.FontSize = Enum.FontSize.Size14
- TextLabel16.Text = "Boost (Space)"
- TextLabel16.TextColor = BrickColor.new("Really black")
- TextLabel16.TextColor3 = Color3.new(0, 0, 0)
- TextLabel16.TextScaled = true
- TextLabel16.TextSize = 14
- TextLabel16.TextWrap = true
- TextLabel16.TextWrapped = true
- --
- ScreenGui0.Parent = plr:FindFirstChildOfClass('PlayerGui')
- script.Parent = ScreenGui0
- local cube_ui = Instance.new("Frame")
- cube_ui.Name = "cube"
- cube_ui.Parent = script
- cube_ui.Size = UDim2.new(0, 30, 0, 30)
- cube_ui.BackgroundColor = BrickColor.new("Institutional white")
- cube_ui.BackgroundColor3 = Color3.new(1, 1, 1)
- local gui = script.Parent
- local main = gui.Main
- local _settings = main.Settings
- local title = main.Title
- local start_button = main.start
- local settings_button = main.settings_button
- local theme_button = _settings.theme
- local trail_button = _settings.trail
- local color_button = _settings.color
- local close_button = main.close
- local input_ui = main.Input
- local map = main.Map
- local food = {}
- local cubes = {}
- local body = {}
- local last_direction = 'a'
- local direction = last_direction
- local c_direction = direction
- local default_rate = 0.15
- local rate = default_rate
- local max_rate = 0--.15
- local rate_interval = 0.001
- local map_size = 510
- local cube_size = 30
- local score = 0
- local theme = 1 -- 1 = lightmode, 2 = darkmode
- local color = 2
- local x,y = 0,0
- local boost = false
- local eyes
- local themes = {
- function()
- theme_button.Text = 'Light Mode'
- _settings.BackgroundColor3 = Color3.new(1,1,1)
- input_ui.BackgroundColor3 = Color3.new(1,1,1)
- start_button.BackgroundColor3 = Color3.new(1,1,1)
- theme_button.BackgroundColor3 = Color3.new(1,1,1)
- settings_button.BackgroundColor3 = Color3.new(1,1,1)
- map.BackgroundColor3 = Color3.new(1,1,1)
- end;
- function()
- theme_button.Text = 'Dark Mode'
- _settings.BackgroundColor3 = Color3.fromRGB(77, 77, 77)
- input_ui.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
- start_button.BackgroundColor3 = Color3.new(0,0,0)
- theme_button.BackgroundColor3 = Color3.new(0,0,0)
- settings_button.BackgroundColor3 = Color3.new(0,0,0)
- map.BackgroundColor3 = Color3.fromRGB(49, 49, 49)
- end;
- }
- local snake_colors = {
- Color3.new(1, 0, 1), -- pink
- Color3.new(0, 1, 0), -- green
- Color3.new(0, 0, 1), -- blue
- Color3.new(1, 1, 0), -- yellow
- }
- main.Position = UDim2.new(0.5,-map_size/2,0.5,-map_size/2)
- main.Size = UDim2.new(0,map_size,0,map_size)
- local playing = false
- local paused = false
- local can_pause = false
- local trail = false
- local main_music = Instance.new("Sound",gui)
- main_music.SoundId = 'rbxassetid://704165118'
- main_music.Looped = true
- main_music.Volume = 0
- main_music:Play()
- game:GetService("TweenService"):Create(main_music,TweenInfo.new(1),{Volume = 1}):Play()
- theme_button.MouseButton1Click:Connect(function()
- local click_s = Instance.new("Sound",gui)
- click_s.SoundId = 'rbxassetid://452267918'
- click_s.Volume = 0.5
- click_s:Play()
- theme = theme + 1
- if theme > #themes then
- theme = 1
- end
- themes[theme]()
- update_grid()
- end)
- close_button.MouseButton1Click:Connect(function()
- gui:Destroy()
- end)
- trail_button.MouseButton1Click:Connect(function()
- local click_s = Instance.new("Sound",gui)
- click_s.SoundId = 'rbxassetid://452267918'
- click_s.Volume = 0.5
- click_s:Play()
- trail = not trail
- if trail then
- trail_button.BackgroundColor3 = Color3.new(0,1,0)
- else
- trail_button.BackgroundColor3 = Color3.new(1,0,0)
- end
- for i = 1,#body do
- color_cube(body[i],i)
- end
- end)
- settings_button.MouseButton1Click:Connect(function()
- local click_s = Instance.new("Sound",gui)
- click_s.SoundId = 'rbxassetid://271111328'
- click_s.Volume = 0.7
- click_s:Play()
- _settings.Visible = not _settings.Visible
- end)
- color_button.MouseButton1Click:Connect(function()
- local click_s = Instance.new("Sound",gui)
- click_s.SoundId = 'rbxassetid://452267918'
- click_s.Volume = 0.5
- click_s:Play()
- color = color + 1
- if color > #snake_colors then
- color = 1
- end
- color_button.Text = 'Snake Color ' .. color
- color_button.BackgroundColor3 = snake_colors[color]
- for i = 1,#body do
- color_cube(body[i],i)
- end
- end)
- start_button.MouseButton1Click:Connect(function()
- local click_s = Instance.new("Sound",gui)
- click_s.SoundId = 'rbxassetid://452267918'
- click_s.Volume = 0.5
- click_s:Play()
- if playing and can_pause then
- paused = not paused
- if paused then
- start_button.Text = 'Resume'
- boost = false
- else
- start_button.Text = 'Pause'
- end
- elseif not playing and not paused then
- if main_music then
- game:GetService("TweenService"):Create(main_music,TweenInfo.new(1),{Volume = 0}):Play()
- game:GetService("Debris"):AddItem(main_music)
- end
- start()
- end
- end)
- function update_input()
- input_ui['w'].BackgroundColor3 = Color3.new(1,0,0)
- input_ui['a'].BackgroundColor3 = Color3.new(1,0,0)
- input_ui['s'].BackgroundColor3 = Color3.new(1,0,0)
- input_ui['d'].BackgroundColor3 = Color3.new(1,0,0)
- input_ui[c_direction].BackgroundColor3 = Color3.new(0,1,0)
- if boost then
- input_ui['space'].BackgroundColor3 = Color3.new(0,1,0)
- else
- input_ui['space'].BackgroundColor3 = Color3.new(1,0,0)
- end
- end
- game:GetService("UserInputService").InputBegan:Connect(function(input,gamepress)
- if input.UserInputType == Enum.UserInputType.Keyboard and playing and not gamepress then
- local key = input.KeyCode
- if key == Enum.KeyCode.A then
- local s = 'a'
- if s ~= c_direction then
- c_direction = s
- end
- update_input()
- elseif key == Enum.KeyCode.D then
- local s = 'd'
- if s ~= c_direction then
- c_direction = s
- end
- update_input()
- elseif key == Enum.KeyCode.W then
- local s = 'w'
- if s ~= c_direction then
- c_direction = s
- end
- update_input()
- elseif key == Enum.KeyCode.S then
- local s = 's'
- if s ~= c_direction then
- c_direction = s
- end
- update_input()
- elseif key == Enum.KeyCode.Space then
- boost = true
- update_input()
- end
- end
- end)
- game:GetService("UserInputService").InputEnded:Connect(function(input,gamepress)
- if input.UserInputType == Enum.UserInputType.Keyboard and boost and playing and not gamepress then
- local key = input.KeyCode
- --[[
- key = tostring(key)
- key = string.lower(string.sub(key,string.len(key),string.len(key)))
- if key == c_direction then
- boost = false
- end
- ]]
- if key == Enum.KeyCode.Space then
- boost = false
- update_input()
- end
- end
- end)
- function add_food(add)
- local cube = cubes[math.random(1,#cubes)]
- if not table.find(body,cube) then
- if add then
- score = score + 1
- rate = rate-rate_interval
- if max_rate > rate then
- rate = max_rate
- end
- update_score()
- local eat_s = Instance.new("Sound",gui)
- eat_s.SoundId = 'rbxassetid://4959631727'
- eat_s.Volume = 0.4
- eat_s:Play()
- end
- table.insert(food,#food+1,cube)
- color_cube(cube)
- else
- add_food(add)
- end
- end
- function add_body()
- local rng = math.random(1,#cubes)
- local cube = cubes[rng]
- if not table.find(food,cube) then
- y = cube.y.Value
- x = cube.x.Value
- table.insert(body,#body+1,cube)
- else
- add_body()
- end
- end
- function add_eyes()
- eyes = cube_ui:Clone()
- eyes.Position = UDim2.new(0,0,0,0)
- eyes.Size = UDim2.new(1,0,1,0)
- eyes.BackgroundTransparency = 1
- eyes.Parent = body[1]
- local s = map_size/cube_size/5
- local e1 = Instance.new("Frame")
- e1.BackgroundColor3 = Color3.new()
- e1.Position = UDim2.new(0,s,0,s)
- e1.Size = UDim2.new(0,s,0,s)
- e1.Parent = eyes
- local e2 = Instance.new("Frame")
- e2.BackgroundColor3 = Color3.new()
- e2.Position = UDim2.new(0,s,1,-(s*2))
- e2.Size = UDim2.new(0,s,0,s)
- e2.Parent = eyes
- end
- function color_cube(v,i)
- if table.find(food,v) then
- v.BackgroundColor3 = Color3.new(1,0,0)
- elseif table.find(body,v) then
- if trail and body[1] ~= v then
- v.BackgroundColor3 = Color3.new(
- snake_colors[color].r-(i/#body),
- snake_colors[color].g-(i/#body),
- snake_colors[color].b-(i/#body)
- )
- else
- v.BackgroundColor3 = Color3.new(
- snake_colors[color].r,
- snake_colors[color].g,
- snake_colors[color].b
- )
- end
- else
- if theme == 2 then
- v.BackgroundColor3 = Color3.fromRGB(49, 49, 49)
- elseif theme == 3 then
- v.BackgroundColor3 = Color3.fromRGB(255, 170, 0)
- else
- v.BackgroundColor3 = Color3.new(1,1,1)
- end
- end
- end
- function move(cdir)
- if c_direction ~= direction and c_direction ~= last_direction then
- last_direction = direction
- end
- direction = c_direction
- if cdir then
- direction = cdir
- else
- cdir = direction
- end
- local rot = 0
- if cdir == 'a' then -- left
- x = x - 1
- rot = 0
- elseif cdir == 'd' then -- right
- x = x + 1
- rot = 180
- elseif cdir == 'w' then -- up
- y = y - 1 -- reversed
- rot = 90
- elseif cdir == 's' then -- down
- y = y + 1 -- reversed
- rot = -90
- end
- if 0 >= x or 0 >= y or x > cube_size or y > cube_size then
- return lose()
- end
- --warn('x: ' .. x .. 'y:' .. y)
- local opposite = false
- if last_direction == 'a' and direction == 'd' then
- opposite = true
- elseif last_direction == 'w' and direction == 's' then
- opposite = true
- elseif last_direction == 's' and direction == 'w' then
- opposite = true
- elseif last_direction == 'd' and direction == 'a' then
- opposite = true
- end
- local last_c = nil
- local next_cube = cubes[(y*cube_size-cube_size)+x]
- if table.find(food,next_cube) then
- local b2 = {unpack(body)}
- for i = 1,#body do
- body[i+1] = b2[i]
- end
- body[1] = next_cube
- eyes.Rotation = rot
- eyes.Parent = body[1]
- food[table.find(food,next_cube)] = nil
- for i = 1,#body do
- color_cube(body[i],i)
- end
- add_food(true)
- return
- end
- for i = 1,#body do
- if not last_c then
- last_c = body[i]
- color_cube(last_c,i)
- if next_cube and not table.find(body,next_cube) then
- body[i] = next_cube
- eyes.Rotation = rot
- eyes.Parent = body[i]
- color_cube(last_c,i)
- elseif next_cube and table.find(body,next_cube) and opposite then
- boost = false
- direction = last_direction
- c_direction = direction
- update_input()
- if last_direction == 'a' then -- center
- x = x - 1
- elseif last_direction == 'd' then -- center
- x = x + 1
- elseif last_direction == 'w' then -- center
- y = y - 1 -- reversed
- elseif last_direction == 's' then -- center
- y = y + 1 -- reversed
- end
- direction = cdir
- return move(last_direction)
- else
- eyes.Rotation = rot
- eyes.Parent = body[i]
- return lose()
- end
- else
- local last_c2 = body[i]
- body[i] = last_c
- color_cube(last_c2,i)
- last_c = last_c2
- end
- color_cube(body[i],i)
- end
- end
- function update_grid()
- for i,v in pairs(cubes) do
- if table.find(food,v) then
- v.BackgroundColor3 = Color3.new(1,0,0)
- elseif table.find(body,v) then
- v.BackgroundColor3 = Color3.new(0,1,0)
- else
- if theme == 2 then
- v.BackgroundColor3 = Color3.fromRGB(49, 49, 49)
- elseif theme == 3 then
- v.BackgroundColor3 = Color3.fromRGB(255, 170, 0)
- else
- v.BackgroundColor3 = Color3.new(1,1,1)
- end
- end
- end
- end
- function set()
- map:ClearAllChildren()
- food = {}
- body = {}
- cubes = {}
- boost = false
- --direction = 'a'
- rate = default_rate
- score = 0
- x,y = 0,0
- if eyes then
- eyes:Destroy()
- end
- --title.Text = 'Score: ' .. score
- --playing = false
- --paused = false
- for Y = 1,cube_size do
- for X = 1,cube_size do
- local cu = cube_ui:Clone()
- if theme == 2 then
- cu.BackgroundColor3 = Color3.fromRGB(49, 49, 49)
- else
- cu.BackgroundColor3 = Color3.new(1,1,1)
- end
- cu.Name = (Y .. ' ' .. X)
- local yv = Instance.new("IntValue")
- yv.Name = 'y'
- yv.Value = Y
- yv.Parent = cu
- local xv = Instance.new("IntValue")
- xv.Name = 'x'
- xv.Value = X
- xv.Parent = cu
- local s = map_size/cube_size
- cu.Position = UDim2.new(0,s*X-s,0,s*Y-s)
- cu.Size = UDim2.new(0,s,0,s)
- cu.Parent = map
- table.insert(cubes,(Y*cube_size-cube_size)+X,cu)
- end
- wait(0)
- end
- add_body()
- add_eyes()
- add_food()
- update_grid()
- end
- function lose()
- can_pause = false
- title.Text = 'Ended with score of ' .. score
- start_button.Text = '...'
- local death_s = Instance.new("Sound",gui)
- death_s.SoundId = 'rbxassetid://4649069508'
- death_s.Volume = 1
- death_s:Play()
- local death_s2 = Instance.new("Sound",gui)
- death_s2.SoundId = 'rbxassetid://3037922660'
- death_s2.Volume = 1
- death_s2:Play()
- for i = 1,10 do
- for i,v in pairs(body) do
- v.BackgroundColor3 = Color3.new(1,0,0)
- end
- wait(1/2/i)
- for i = 1,#body do
- color_cube(body[i],i)
- end
- wait(1/2/i)
- end
- start_button.Text = 'Start'
- main_music = Instance.new("Sound",gui)
- main_music.SoundId = 'rbxassetid://704165118'
- main_music.Looped = true
- main_music.Volume = 0
- main_music:Play()
- game:GetService("TweenService"):Create(main_music,TweenInfo.new(1),{Volume = 1}):Play()
- playing = false
- end
- function update_score()
- title.Text = 'Score: ' .. tostring(score)
- end
- function start()
- if not playing and not paused then else return end
- playing = true
- can_pause = false
- start_button.Text = 'Starting..'
- set()
- local t = 5
- for i = t,0,-1 do
- title.Text = 'Starting.. (' .. i .. ')'
- wait(1)
- end
- title.Text = 'Go!'
- local start_s = Instance.new("Sound",gui)
- start_s.SoundId = 'rbxassetid://3044638823'
- start_s.Volume = 1
- start_s:Play()
- wait(1)
- can_pause = true
- start_button.Text = 'Pause'
- update_score()
- while playing do
- if not paused then
- move()
- --update_grid()
- end
- if boost then
- wait(rate/2)
- else
- wait(rate)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement