Edward1221

Untitled

May 26th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. if script.Parent.className~="HopperBin" then
  2. local h=Instance.new("HopperBin")
  3. h.Parent=game.Players["RenderSettings"].Backpack
  4. h.Name="Snake"
  5. script.Parent=h
  6. end
  7.  
  8.  
  9. script.Parent.Selected:connect(function(mouse)
  10. pcall(function() game.LocalBackpack:children()[1]:remove() end)
  11. Name=script.Parent.Parent.Parent.Name
  12. pcall(function() game.Players[Name].PlayerGui.Snake:remove() end)
  13. local workspace=workspace
  14. local game=game
  15. Gui=Instance.new("GuiMain")
  16. Gui.Name="Snake"
  17. Gui.Parent=game.Players[Name].PlayerGui
  18. Screen=Gui
  19. function XY(x,y)
  20. if type(x)=="number" and type(y)=="number" then
  21. return UDim2.new(x,0,y,0)
  22. else
  23. error("Invalide argument for XY")
  24. end
  25. end
  26. Size=1/20
  27. Frame=Instance.new("Frame")
  28. Frame.Size=XY(0,0)
  29. Frame.Position=XY(0-Size,0)
  30. Frame.Parent=Screen
  31. Frame.BackgroundColor=BrickColor:Black()
  32. for i=0,1+Size,0.01 do
  33. Frame.Size=XY(i,0.05)
  34. wait()
  35. end
  36. for i=0.05,1,0.01 do
  37. Frame.Size=XY(1+Size,i)
  38. wait()
  39. end
  40. Score=Instance.new("TextLabel",Screen)
  41. Score.Size=XY(0.1,0.05)
  42. Score.Position=XY(0,0)
  43. Score.BackgroundColor=BrickColor.new("White")
  44. Score.Text="Score:0"
  45. B=Instance.new("ImageLabel")
  46. B.Size=XY(Size,Size)
  47. B.Position=XY(-2,-2)
  48. B.BorderSizePixel=0
  49. for i=0,19,1 do
  50. for ii=0,19,1 do
  51. local Block=B:Clone()
  52. Block.Parent=Frame
  53. Block.BackgroundColor=BrickColor:Black()
  54. Block.Position=XY(i*Size,ii*Size)
  55. Block.Name=i.." : "..ii
  56. end
  57. end
  58. function Parse(str)
  59. local st,er=string.find(str," : ")
  60. return tostring(str:sub(1,st-1)),tostring(str:sub(er,#str))
  61. end
  62. Start=Frame["10 : 10"]
  63. Start.BackgroundColor=BrickColor:Red()
  64. Pos="10 : 10"
  65. Direct="1 : 0"
  66. Snake={Start}
  67. function ChooseFood()
  68. local lx=math.random(1,18)
  69. local ly=math.random(1,18)
  70. Food=Frame[lx.." : "..ly]
  71. if Food.BackgroundColor==BrickColor.new("Black") then
  72. Food.BackgroundColor=BrickColor:Green()
  73. else
  74. ChooseFood()
  75. end
  76. end
  77. ChooseFood()
  78. function Move(Dir)
  79. local Old=Pos
  80. local CurX,CurY=Parse(Pos)
  81. local NextX,NextY=Parse(Direct)
  82. local New=CurX+NextX.." : "..CurY+NextY
  83. if Frame:findFirstChild(New) and Frame[New].BackgroundColor~=BrickColor.new("Light blue") then
  84. Pos=New
  85. Start=Frame[Pos]
  86. if Start.BackgroundColor==BrickColor:Green() then
  87. table.insert(Snake,Snake[1])
  88. Score.Text="Score:"..tostring(#Snake-2)
  89. ChooseFood()
  90. end
  91. Start.BackgroundColor=BrickColor:Red()
  92. local Back=Snake[1]
  93. Back.BackgroundColor=BrickColor:Black()
  94. table.remove(Snake,1)
  95. Frame[Old].BackgroundColor=BrickColor.new("Light blue")
  96. table.insert(Snake,Frame[Old])
  97. else
  98. coroutine.yield(Thread)
  99. print("Dead.")
  100. for _,v in pairs(Snake) do
  101. v.BackgroundColor=BrickColor:Black()
  102. end
  103. for i=1,20,0.25 do
  104. Score.Size=Score.Size+XY(0.025/2,0.025/2)
  105. wait()
  106. end
  107. wait(1)
  108. Score.Text="Game over."
  109. wait(math.huge)
  110. end
  111. end
  112. mouse.KeyDown:connect(function(p)
  113. local X,Y=Parse(Direct)
  114. local Old=Direct
  115. if p=="f" then -- 1,0 -1,0
  116. Direct="-1 : 0"
  117. elseif p=="t" then
  118. Direct="0 : -1"
  119. elseif p=="h" then
  120. Direct="1 : 0"
  121. elseif p=="g" then
  122. Direct="0 : 1"
  123. end
  124. local Nex,Ney=Parse(Direct)
  125. if X==Nex*-1 or Y==Ney*-1 then
  126. Direct=Old
  127. end
  128. end)
  129. local Thread=coroutine.create(function()
  130. while true do
  131. wait(0.25)
  132. Move(Direct)
  133. end
  134. end)
  135. coroutine.resume(Thread)
  136. end)
Advertisement
Add Comment
Please, Sign In to add comment