CHoff719

2d roblox

Jun 4th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. --[[
  2. Made by GoogleAnalytics.
  3. --]]
  4.  
  5. local Player = game:GetService("Players").LocalPlayer
  6. repeat wait() until Player.Character
  7. local HumanoidRootPart = Player.Character:WaitForChild("HumanoidRootPart")
  8. local PlayerGui = Player:WaitForChild("PlayerGui")
  9. local ScreenGui = Instance.new("ScreenGui")
  10. ScreenGui.Parent = PlayerGui
  11.  
  12. local floor = math.floor
  13. local selectedColor = Color3.fromRGB(255, 255 ,255)
  14.  
  15. local function colorPicker(_sx, _sy, _x, _y, w, h, detail)
  16. local frameWidth = floor(w/detail)
  17. local frameHeight = floor(h/detail)
  18. for y=1,detail do
  19. for x=1,detail do
  20. local color = Color3.fromHSV(x/detail, y/detail, 1)
  21. local Frame = Instance.new("TextButton")
  22. Frame.Size = UDim2.new(0, frameWidth, 0, frameWidth)
  23. Frame.Position = UDim2.new(_sx, _x + (x - 1)*frameWidth, _sy, _y + (y - 1)*frameHeight)
  24. Frame.BackgroundColor3 = color
  25. Frame.BorderSizePixel = 0
  26. Frame.Text = ""
  27. Frame.Parent = ScreenGui
  28. Frame.MouseButton1Down:connect(function()
  29. selectedColor = color
  30. end)
  31. end
  32. end
  33. end
  34.  
  35. colorPicker(1, 1, -220, -300, 200, 200, 10)
  36.  
  37. local Character = Player.Character
  38.  
  39. local Mouse = Player:GetMouse()
  40.  
  41. local GRID = {}
  42. local WIDTH = 32
  43. local HEIGHT = 32
  44.  
  45. local function init()
  46. for y=1, HEIGHT do
  47. GRID[y] = {}
  48. for x=1, WIDTH do
  49. local Part = Instance.new("Part")
  50. Part.Anchored = true
  51. Part.Size = Vector3.new(1, 1, 1)
  52. Part.CFrame = CFrame.new(Part.Size.X/2, 2, Part.Size.Z/2) * CFrame.new((x - 1), 0, (y - 1))
  53. Part.Color = Color3.fromRGB(0, 0, 0)
  54. Part.TopSurface = Enum.SurfaceType.Smooth
  55. Part.BottomSurface = Enum.SurfaceType.Smooth
  56. Part.Parent = Character
  57. GRID[y][x] = {
  58. Part = Part,
  59. filled = false
  60. }
  61. end
  62. end
  63. end
  64.  
  65. init()
  66.  
  67. local mouse1Down = false
  68. local mouse2Down = false
  69.  
  70.  
  71.  
  72. Mouse.Button1Down:connect(function()
  73. mouse1Down = true
  74. end)
  75.  
  76. Mouse.Button1Up:connect(function()
  77. mouse1Down = false
  78. end)
  79.  
  80. Mouse.Button2Down:connect(function()
  81. mouse2Down = true
  82. end)
  83.  
  84. Mouse.Button2Up:connect(function()
  85. mouse2Down = false
  86. end)
  87.  
  88. local function fill(x, y, color)
  89. GRID[y][x].filled = true
  90. GRID[y][x].Part.Color = color
  91. end
  92.  
  93. local function unfill(x, y, color)
  94. GRID[y][x].filled = false
  95. GRID[y][x].Part.Color = color
  96. end
  97.  
  98. local function check(x, y)
  99. if (x > 0 and y > 0 and x <= WIDTH and y <= HEIGHT) then
  100. return true
  101. end
  102. return false
  103. end
  104.  
  105. local function isEmpty(x, y)
  106. if (check(x, y) and not GRID[y][x].filled) then
  107. return true
  108. end
  109. return false
  110. end
  111.  
  112. local function mouseControl()
  113. if (mouse1Down) then
  114. local x = floor(Mouse.Hit.X) + 1
  115. local y = floor(Mouse.Hit.Z) + 1
  116. if (isEmpty(x, y)) then
  117. fill(x, y, selectedColor)
  118. end
  119. elseif (mouse2Down) then
  120. local x = floor(Mouse.Hit.X) + 1
  121. local y = floor(Mouse.Hit.Z) + 1
  122. if (check(x, y) and not isEmpty(x, y)) then
  123. unfill(x, y, Color3.fromRGB(0, 0, 0))
  124. end
  125. end
  126. end
  127.  
  128. local function update()
  129. for y=#GRID-1,1,-1 do
  130. --local allFilled = true
  131. for x=1,#GRID[y] do
  132. if not (isEmpty(x, y)) then
  133. if (isEmpty(x, y + 1)) then
  134. fill(x, y + 1, GRID[y][x].Part.Color)
  135. unfill(x, y, Color3.fromRGB(0, 0, 0))
  136. elseif (isEmpty(x - 1, y + 1)) then
  137. fill(x - 1, y + 1, GRID[y][x].Part.Color)
  138. unfill(x, y, Color3.fromRGB(0, 0, 0))
  139. elseif (isEmpty(x + 1, y + 1)) then
  140. fill(x + 1, y + 1, GRID[y][x].Part.Color)
  141. unfill(x, y, Color3.fromRGB(0, 0, 0))
  142. end
  143. else
  144. --allFilled = false
  145. end
  146. --[[
  147. if (allFilled) then
  148. table.remove(GRID, y)
  149. end
  150. --]]
  151. end
  152. end
  153. end
  154.  
  155. local function gameLoop(dt)
  156. mouseControl()
  157. if (dt%1 == 0) then
  158. update()
  159. end
  160. end
  161.  
  162. local dt = 0
  163.  
  164. game:GetService("RunService").RenderStepped:connect(function()
  165. dt = dt + 1
  166. gameLoop(dt)
  167. end)
Advertisement
Add Comment
Please, Sign In to add comment