Advertisement
Dark_EccentricYT

Untitled

Oct 12th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. local NodesPerStep = 30
  2.  
  3. plr = game:GetService("Players").LocalPlayer
  4. char = plr.Character
  5. m = plr:GetMouse()
  6. human = char.Humanoid
  7. torso = char.Torso
  8. root = char.HumanoidRootPart
  9. lleg = char["Left Leg"]
  10. rleg = char["Right Leg"]
  11. larm = char["Left Arm"]
  12. rarm = char["Right Arm"]
  13. head = char.Head
  14. lshold = torso["Left Shoulder"]
  15. rshold = torso["Right Shoulder"]
  16. neck = torso.Neck
  17. lhip = torso["Left Hip"]
  18. rhip = torso["Right Hip"]
  19. lscf = lshold.C0
  20. rscf = rshold.C0
  21. ncf = neck.C0
  22. lhcf = lhip.C0
  23. rhcf = rhip.C0
  24. rad = math.rad
  25. random = math.random
  26. sin = math.sin
  27. cos = math.cos
  28. hurt = false
  29.  
  30. local Maze = {}
  31. function Maze:New(xSize, ySize)
  32. local Cells = {}
  33. local IDs = {}
  34. local ID = 1
  35. for x = 0, xSize+1 do
  36. Cells[x] = {}
  37. for y = 0, ySize+1 do
  38. Cells[x][y] = {
  39. ID = ID;
  40. X = x;
  41. Y = y;
  42. Edge = (x == 0 or y == 0 or x==xSize+1 or y == ySize+1)
  43. }
  44. IDs[ID] = Cells[x][y]
  45. ID = ID + 1
  46. end
  47. end
  48. local NewMaze = {
  49. Cells = Cells;
  50. IDs = IDs;
  51. }
  52. setmetatable(NewMaze, {
  53. __index = Maze;
  54. })
  55. return NewMaze
  56. end
  57. function Maze:NewWalls(x, y)
  58. local Walls = {}
  59. if (x == self.Finish.X and y == self.Finish.Y) or
  60. (x == self.Start.X and y == self.Start.Y) then
  61. if x == #self.Cells then
  62. Walls[1] = {self.Cells[x][y].ID, self.Cells[x-1][y].ID}
  63. Walls[2] = {self.Cells[x][y].ID, false}
  64. else
  65. Walls[1] = {self.Cells[x][y].ID, self.Cells[x+1][y].ID}
  66. Walls[2] = {self.Cells[x][y].ID, false}
  67. end
  68. if y == #self.Cells[x] then
  69. Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y-1].ID}
  70. Walls[4] = {self.Cells[x][y].ID, false}
  71. else
  72. Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y+1].ID}
  73. Walls[4] = {self.Cells[x][y].ID, false}
  74. end
  75. else
  76. Walls[1] = {self.Cells[x][y].ID, self.Cells[x-1][y].ID}
  77. Walls[2] = {self.Cells[x][y].ID, self.Cells[x+1][y].ID}
  78. Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y-1].ID}
  79. Walls[4] = {self.Cells[x][y].ID, self.Cells[x][y+1].ID}
  80. end
  81. return Walls
  82. end
  83. function Maze:Generate(start, finish, scale, height)
  84. self.Finish = finish
  85. self.Start = start
  86. self.Scale = scale
  87. self.Height = height
  88. self.Model = Instance.new("Model")
  89. self.Model.Name = "Maze"
  90. local Walls = self:NewWalls(start.X, start.Y)
  91. local PermWalls = {}
  92. local PermCells = {[self.Cells[start.X][start.Y].ID] = true}
  93. local Rand = math.random
  94. local function MainLoop()
  95. while wait() do
  96. for i = 1, NodesPerStep do
  97. if not next(Walls, Key) then
  98. return nil
  99. end
  100. local Key = Rand(1, #Walls)
  101. local w = Walls[Key]
  102. table.remove(Walls,Key)
  103. local Other
  104. local Self
  105. if PermCells[w[1]] then
  106. if PermCells[w[2]] then
  107. PermWalls[#PermWalls+1] = w
  108. else
  109. Other = w[2]
  110. Self = w[1]
  111. end
  112. else
  113. Other = w[1]
  114. Self = w[2]
  115. end
  116. if Other then
  117. PermCells[Other] = true
  118. if self.IDs[Other].Edge then
  119. PermWalls[#PermWalls+1] = w
  120. else
  121. for _, Wall in pairs(self:NewWalls(self.IDs[Other].X, self.IDs[Other].Y)) do
  122. if Wall[2] ~= Self then
  123. Walls[#Walls+1] = Wall
  124. end
  125. end
  126. end
  127. end
  128. end
  129. end
  130. end
  131. MainLoop()
  132. for _, Wall in pairs(PermWalls) do
  133. self:CreateWall(Wall[1], Wall[2])
  134. end
  135. local xMax = ((#self.Cells - 1))*scale
  136. local yMax = ((#self.Cells[1] - 1))*scale
  137. local Floor = Instance.new("Part")
  138. Floor.Anchored = true
  139. Floor.BrickColor = BrickColor.new('Bright green')
  140. Floor.Material = "Grass"
  141. Floor.Name = "MainBase"
  142. Floor.Size = Vector3.new(xMax+2, 1.2, yMax+2)
  143. Floor.Position = Vector3.new(xMax/2+scale/2,-0.4,yMax/2+scale/2)
  144. Floor.Parent = self.Model
  145. end
  146. function Maze:CreateWall(id1, id2)
  147. local Wall = Instance.new "Part"
  148. Wall.Anchored = true
  149. Wall.Name = "Walls"
  150. Wall.Size = Vector3.new(self.Scale, self.Height, 2)
  151. local n1 = self.IDs[id1]
  152. local n2 = self.IDs[id2]
  153. Wall.CFrame = CFrame.new(
  154. Vector3.new(n1.X, self.Height/2, n1.Y),
  155. Vector3.new(n2.X, self.Height/2, n2.Y)
  156. )
  157. Wall.Position = Vector3.new((n1.X + n2.X)*self.Scale/2, self.Height/2, (n1.Y + n2.Y)*self.Scale/2)
  158. Wall.Parent = self.Model
  159. end
  160.  
  161. local m = Maze:New(25,25)
  162. m:Generate(Vector2.new(1,25), Vector2.new(50,50), 20, 25)
  163. m.Model.Parent = workspace
  164. m.Model:MoveTo(workspace:FindFirstChild('Base').Position + Vector3.new(0,65,0))
  165.  
  166. for _,c in pairs(m.Model:GetChildren()) do
  167. if c:IsA('Part') then
  168. if c.Name == "Walls" then
  169. c.Anchored = true
  170. c.CanCollide = false
  171. c.Name ="Walls"
  172. c.Transparency = 1
  173. c.TopSurface = 0
  174. c.BottomSurface = 0
  175. c.BrickColor = BrickColor.new('Daisy orange')
  176. c.Material = "Cobblestone"
  177. end
  178. end
  179. end
  180.  
  181. thing = Instance.new('Part', char.Torso)
  182. thing.Anchored = false
  183. thing.CanCollide = false
  184. thing.Transparency = 1
  185. thing.Name = "Trigger"
  186. thing.Size = Vector3.new(225, 0, 225)
  187.  
  188. thing.Touched:connect(function(hit)
  189. if hit.Name == "Walls" then
  190. hit.CanCollide = true
  191. hit.Transparency = 0
  192. local s = Instance.new("SelectionBox", char)
  193. local lasso = Instance.new("SelectionPartLasso",s)
  194. lasso.Humanoid = char.Humanoid
  195. lasso.Part = hit
  196. end
  197. end)
  198.  
  199. thing.TouchEnded:connect(function(unhit)
  200. if unhit.Name == "Walls" then
  201. unhit.CanCollide = false
  202. unhit.Transparency = 1
  203. for _,c in pairs(char:GetChildren()) do
  204. if c:IsA('SelectionBox') then
  205. c:Destroy()
  206. end
  207. end
  208. end
  209. end)
  210.  
  211. char.Torso.CFrame = CFrame.new(0,125,0)
  212. char.Archivable = true
  213.  
  214. game:GetService("RunService").RenderStepped:connect(function()
  215. thing.CFrame = char.Torso.CFrame
  216. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement