Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- warn([[
- = Made by KrYn0MoRe (AlmightyToast) =
- - WIP NOT DONE YET
- ]])
- 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")
- 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 = "close"
- TextButton4.Parent = Frame1
- TextButton4.Position = UDim2.new(0.931999981, 0, -0.0839999989, 0)
- TextButton4.Size = UDim2.new(0, 34, 0, 34)
- TextButton4.BackgroundColor = BrickColor.new("Really red")
- TextButton4.BackgroundColor3 = Color3.new(1, 0, 0)
- TextButton4.Font = Enum.Font.SourceSans
- TextButton4.FontSize = Enum.FontSize.Size14
- TextButton4.Text = "X"
- 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 = "start"
- TextButton5.Parent = Frame1
- TextButton5.Position = UDim2.new(1.02199996, 0, -2.98023224e-08, 0)
- TextButton5.Size = UDim2.new(0, 100, 0, 100)
- TextButton5.BackgroundColor = BrickColor.new("Institutional white")
- TextButton5.BackgroundColor3 = Color3.new(1, 1, 1)
- TextButton5.BackgroundTransparency = 0.5
- TextButton5.Font = Enum.Font.SourceSans
- TextButton5.FontSize = Enum.FontSize.Size14
- TextButton5.Text = "Start"
- 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
- --
- ScreenGui0.Parent = plr:FindFirstChildOfClass('PlayerGui')
- script.Parent = ScreenGui0
- local cube_ui = Instance.new("TextLabel")
- cube_ui.Name = "cube"
- cube_ui.Text = ''
- 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 title = main.Title
- local start_button = main.start
- local close_button = main.close
- local map = main.Map
- local direction = ''
- local nums = {}
- local cubes = {}
- local m = 4
- local map_size = 500
- local cube_size = map_size/m
- local score = 0
- local playing = false
- local paused = false
- local can_pause = false
- local can_press = false
- local colors = {
- [2] = Color3.fromRGB(85, 255, 255),
- [4] = Color3.fromRGB(85, 170, 255),
- [8] = Color3.fromRGB(0, 0, 255),
- [16] = Color3.fromRGB(255, 170, 0),
- [32] = Color3.fromRGB(170, 0, 0),
- [64] = Color3.fromRGB(255, 0, 0),
- [128] = Color3.fromRGB(170, 170, 0),
- [256] = Color3.fromRGB(0, 255, 0),
- [512] = Color3.fromRGB(255, 255, 0),
- [1024] = Color3.fromRGB(255, 255, 0),
- }
- 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 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()
- close_button.MouseButton1Click:Connect(function()
- gui:Destroy()
- 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'
- 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)
- game:GetService("UserInputService").InputBegan:Connect(function(input,gamepress)
- if input.UserInputType == Enum.UserInputType.Keyboard and playing and can_press and not paused and not gamepress then
- local key = input.KeyCode
- if key == Enum.KeyCode.A then
- local s = 'a'
- direction = s
- move()
- elseif key == Enum.KeyCode.D then
- local s = 'd'
- direction = s
- move()
- elseif key == Enum.KeyCode.W then
- local s = 'w'
- direction = s
- move()
- elseif key == Enum.KeyCode.S then
- local s = 's'
- direction = s
- move()
- end
- end
- end)
- function add_num()
- local rng = math.random(1,#cubes)
- local cube = cubes[rng]
- if not nums[rng] then
- table.insert(nums,rng,cube)
- if math.random(1,2) == 1 then
- cube['point'].Value = 4
- else
- cube['point'].Value = 2
- end
- update_cube(cube,rng)
- else
- local total = 0
- for i,v in pairs(nums) do
- if v then
- total = total + 1
- end
- end
- if total >= m^2 then
- return lose()
- else
- add_num()
- end
- end
- end
- function update_cube(v,i,c)
- if (i and nums[i]) or c or table.find(nums,v) then
- local c = Color3.fromRGB(25,25,25)
- if colors[v['point'].Value] then
- c = colors[v['point'].Value]
- end
- v.BackgroundColor3 = c
- v['pui'].Text = tostring(v['point'].Value)
- print(v['pui'].Text)
- else
- v.BackgroundColor3 = Color3.new(1,1,1)
- v['pui'].Text = ' '
- warn(v['pui'].Text)
- end
- end
- function move()
- local x2,y2 = 0,0
- if direction == 'a' then
- x2 = -1
- y2 = 1
- elseif direction == 'd' then
- x2 = 1
- y2 = 1
- elseif direction == 'w' then
- x2 = 1
- y2 = -1
- elseif direction == 's' then
- x2 = 1
- y2 = 1
- end
- if direction == 's' then -- down
- for Y = m,1,-y2 do
- for X = 1,m,x2 do
- local n = (Y*m-m)+X
- if nums[n] then
- local cube = cubes[n]
- local next_cube = cube
- local hit_cube = nil
- local n2 = n
- local n4 = 0
- for i = Y,m,y2 do
- local n3 = (i*m-m)+X
- --print('i: ' .. i .. ' ' .. 'n:' .. n3)
- --print('x: ' .. X .. ' ' .. 'y: ' .. i)
- if cubes[n3] ~= cube then
- if not nums[n3] then
- n2 = n3
- next_cube = cubes[n3]
- else
- n4 = n3
- hit_cube = cubes[n3]
- break
- end
- end
- end
- --print('n2: ' .. n2)
- if n2 > 0 and (n2 ~= n or hit_cube) then
- local c = false
- if hit_cube and cube['point'].Value == hit_cube['point'].Value then
- hit_cube['point'].Value = hit_cube['point'].Value*2
- score = score + hit_cube['point'].Value
- update_cube(hit_cube,n4,true)
- c = true
- elseif next_cube and not nums[n2] then
- table.insert(nums,n2,next_cube)
- next_cube['point'].Value = cube['point'].Value
- update_cube(next_cube,n2,true)
- c = true
- end
- if c then
- nums[n] = nil
- cube['point'].Value = 0
- update_cube(cube,n,false)
- end
- end
- end
- end
- end
- elseif direction == 'w' then -- up
- for Y = 1,m,-y2 do
- for X = 1,m,x2 do
- local n = (Y*m-m)+X
- if nums[n] then
- local cube = cubes[n]
- local next_cube = cube
- local hit_cube = nil
- local n2 = n
- local n4 = 0
- for i = Y,1,y2 do
- local n3 = (i*m-m)+X
- --print('i: ' .. i .. ' ' .. 'n:' .. n3)
- --print('x: ' .. X .. ' ' .. 'y: ' .. i)
- if cubes[n3] ~= cube then
- if not nums[n3] then
- n2 = n3
- next_cube = cubes[n3]
- else
- n4 = n3
- hit_cube = cubes[n3]
- break
- end
- end
- end
- --print('n2: ' .. n2)
- if n2 > 0 and (n2 ~= n or hit_cube) then
- local c = false
- if hit_cube and cube['point'].Value == hit_cube['point'].Value then
- hit_cube['point'].Value = hit_cube['point'].Value*2
- score = score + hit_cube['point'].Value
- update_cube(hit_cube,n4,true)
- c = true
- elseif next_cube and not nums[n2] then
- table.insert(nums,n2,next_cube)
- next_cube['point'].Value = cube['point'].Value
- update_cube(next_cube,n2,true)
- c = true
- end
- if c then
- nums[n] = nil
- cube['point'].Value = 0
- update_cube(cube,n,false)
- end
- end
- end
- end
- end
- elseif direction == 'a' then -- left
- for X = 1,m,-x2 do
- for Y = 1,m,y2 do
- local n = (Y*m-m)+X
- if nums[n] then
- local cube = cubes[n]
- local next_cube = cube
- local hit_cube = nil
- local n2 = n
- local n4 = 0
- for i = X,1,x2 do
- local n3 = (Y*m-m)+i
- --print('i: ' .. i .. ' ' .. 'n:' .. n3)
- --print('x: ' .. i .. ' ' .. 'y: ' .. Y)
- if cubes[n3] ~= cube then
- if not nums[n3] then
- n2 = n3
- next_cube = cubes[n3]
- else
- n4 = n3
- hit_cube = cubes[n3]
- break
- end
- end
- end
- --print('n2: ' .. n2)
- if n2 > 0 and (n2 ~= n or hit_cube) then
- local c = false
- if hit_cube and cube['point'].Value == hit_cube['point'].Value then
- hit_cube['point'].Value = hit_cube['point'].Value*2
- score = score + hit_cube['point'].Value
- update_cube(hit_cube,n4,true)
- c = true
- elseif next_cube and not nums[n2] then
- table.insert(nums,n2,next_cube)
- next_cube['point'].Value = cube['point'].Value
- update_cube(next_cube,n2,true)
- c = true
- end
- if c then
- nums[n] = nil
- cube['point'].Value = 0
- update_cube(cube,n,false)
- end
- end
- end
- end
- end
- elseif direction == 'd' then -- right
- for X = m,1,-x2 do
- for Y = 1,m,y2 do
- local n = (Y*m-m)+X
- if nums[n] then
- local cube = cubes[n]
- local next_cube = cube
- local hit_cube = nil
- local n2 = n
- local n4 = 0
- for i = X,m,x2 do
- local n3 = (Y*m-m)+i
- --print('i: ' .. i .. ' ' .. 'n:' .. n3)
- --print('x: ' .. i .. ' ' .. 'y: ' .. Y)
- if cubes[n3] ~= cube then
- if not nums[n3] then
- n2 = n3
- next_cube = cubes[n3]
- else
- n4 = n3
- hit_cube = cubes[n3]
- break
- end
- end
- end
- --print('n2: ' .. n2)
- if n2 > 0 and (n2 ~= n or hit_cube) then
- local c = false
- if hit_cube and cube['point'].Value == hit_cube['point'].Value then
- hit_cube['point'].Value = hit_cube['point'].Value*2
- score = score + hit_cube['point'].Value
- update_cube(hit_cube,n4,true)
- c = true
- elseif next_cube and not nums[n2] then
- table.insert(nums,n2,next_cube)
- next_cube['point'].Value = cube['point'].Value
- update_cube(next_cube,n2,true)
- c = true
- end
- if c then
- nums[n] = nil
- cube['point'].Value = 0
- update_cube(cube,n,false)
- end
- end
- end
- end
- end
- end
- update_score()
- local total = 0
- for i,v in pairs(nums) do
- if v then
- total = total + 1
- end
- end
- if total >= m^2 then
- return lose()
- else
- add_num()
- end
- end
- function set()
- map:ClearAllChildren()
- nums = {}
- cubes = {}
- --direction = 'a'
- score = 0
- --title.Text = 'Score: ' .. score
- --playing = false
- --paused = false
- for Y = 1,m do
- for X = 1,m do
- local cu = cube_ui:Clone()
- local cs = Instance.new("NumberValue")
- cs.Name = 'point'
- cs.Value = 0
- cs.Parent = cu
- local pui = Instance.new("TextLabel")
- pui.Name = 'pui'
- pui.Text = ''
- pui.TextScaled = true
- pui.BackgroundTransparency = 1
- pui.BorderSizePixel = 0
- pui.TextColor3 = Color3.new(1,1,1)
- pui.TextStrokeTransparency = 0
- pui.Size = UDim2.new(1,0,1,0)
- pui.Parent = cu
- local s = 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*m-m)+X,cu)
- end
- wait(0)
- end
- add_num()
- add_num()
- end
- function lose()
- can_press = false
- playing = false
- 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()
- wait(1)
- 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()
- can_press = true
- end
- function update_score()
- title.Text = 'Score: ' .. tostring(score)
- end
- function start()
- if not playing and not paused then else return end
- can_press = false
- 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
- can_press = true
- start_button.Text = 'Pause'
- update_score()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement