xXm0dzXx

Untitled

Jun 2nd, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. --Dig Dug--
  2. local mined = {}
  3. local x,y = term.getSize()
  4. local round = 1
  5. local lives = 3
  6. local channel = "SinglePlayer"
  7. local Mult = false
  8. local Players = {}
  9. local noLagg = ""
  10. local PvP = {}
  11.  
  12. local currentX = x/2
  13. local currentY = 2
  14. local direction = ">"
  15.  
  16. for i = 1,x do
  17. noLagg = noLagg.. "X"
  18. end
  19.  
  20. local function cPrint(text)
  21. local x,y = term.getSize()
  22. x2,y2 = term.getCursorPos()
  23. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  24. write(text)
  25. end
  26.  
  27.  
  28. function drawCursor()
  29. term.clear() --Clears the screen
  30. if lives < 0 then
  31. term.setCursorPos(1,3)
  32. cPrint("GAME OVER")
  33. sleep(2)
  34. error()
  35. else
  36. for v = 2,y-2 do
  37. term.setCursorPos(1,v)
  38. write(noLagg)
  39. end
  40.  
  41. term.setCursorPos(4,2)
  42. write("Y")
  43.  
  44. for i = 1,lives do
  45. term.setCursorPos(i,y)
  46. write(">")
  47. end
  48.  
  49.  
  50. term.setCursorPos(x-string.len("RND: " ..round),y)
  51. write("RND: " ..round)
  52.  
  53. for i = 1,#mined do
  54. if mined[i] then
  55. mined[i] = tostring(mined[i])
  56. minedX, minedY = string.match(mined[i], "(%-?%d+)/(%-?%d+)")
  57. term.setCursorPos(tonumber(minedX),tonumber(minedY))
  58. write(" ")
  59. --if currentX == minedX and currentY == minedY-1 then
  60. -- currentY = minedY
  61. --end
  62. end
  63. end
  64. term.setCursorPos(x-1,1)
  65. write("@")
  66. if currentY == 1 then currentY = 2 end
  67. if currentX == x then
  68. currentX = x-1
  69. elseif currentX == 0 then
  70. currentX = 1
  71. end
  72.  
  73. if Mult then
  74.  
  75. for i,kik in pairs(Players) do
  76. v = tostring(kik)
  77. if v then
  78. minedX, minedY = string.match(v, "(%-?%d+)/(%-?%d+)")
  79. if tonumber(minedX) then
  80. term.setCursorPos(tonumber(minedX),tonumber(minedY))
  81. write("I")
  82. mined[#mined+1] = kik
  83. end
  84. end
  85. end
  86. end
  87.  
  88. if Mult then
  89. term.setCursorPos(4,2)
  90. write("Y")
  91. end
  92.  
  93. for i = 1,#PvP do
  94. if PvP[i] then
  95. PvP[i] = tostring(PvP[i])
  96. minedX, minedY = string.match(PvP[i], "(%-?%d+)/(%-?%d+)")
  97. term.setCursorPos(tonumber(minedX),tonumber(minedY))
  98. write("O")
  99. if minedX == currentX and minedY == currentY then
  100. term.setCursorPos(1,1)
  101. write("You just got blackhole'd!")
  102. sleep(1)
  103. lives = lives-1
  104. end
  105. end
  106. end
  107.  
  108. term.setCursorPos(currentX, currentY)
  109. write(direction)
  110. end
  111. end
  112.  
  113. function begin()
  114. while true do
  115. drawCursor()
  116. local e,key,message = os.pullEvent()
  117. if e == "char" and key == "u" and Mult then
  118. PvP[#PvP+1] = currentX+1.. "/" ..currentY
  119. rednet.broadcast("[MM] ["..channel.."] [Bomb] " ..currentX+1.. "/" ..currentY)
  120. elseif e == "key" then
  121. if key == 17 or key == 200 then --up
  122. mined[#mined+1] = currentX.. "/" ..currentY
  123. currentY = currentY -1
  124. direction = "^"
  125. elseif key == 31 or key == 208 then --down
  126. if currentY < y-1 then
  127. mined[#mined+1] = currentX.. "/" ..currentY
  128. currentY = currentY +1
  129. end
  130. direction = "v"
  131. elseif key == 203 or key == 30 then --left
  132. mined[#mined+1] = currentX.. "/" ..currentY
  133. currentX = currentX -1
  134. direction = "<"
  135. elseif key == 205 or key == 32 then --right
  136. mined[#mined+1] = currentX.. "/" ..currentY
  137. currentX = currentX +1
  138. direction = ">"
  139. end
  140.  
  141. if Mult then
  142. rednet.broadcast("[MM] ["..channel.."] " ..currentX.. "/" ..currentY)
  143. end
  144.  
  145. if currentX == 4 and currentY == 2 then
  146. if Mult then
  147. term.setCursorPos(1,1)
  148. write("The flower ate you.")
  149. sleep(1)
  150. lives = lives-100000
  151. end
  152. end
  153. elseif Mult and e == "rednet_message" then
  154. if string.sub(message, 1, string.len("[MM] [" ..channel.."] [Bomb] ")) == "[MM] [" ..channel.."] [Bomb] " then
  155. PvP[#PvP+1] = string.sub(message, string.len("[MM] [" ..channel.."] [Bomb] *"), string.len(message))
  156. elseif string.sub(message, 1, string.len("[MM] [" ..channel.."] ")) == "[MM] [" ..channel.."] " then
  157. Players[key] = string.sub(message, string.len("[MM] [" ..channel.."] *"), string.len(message))
  158. end
  159. end
  160. end
  161. end
  162.  
  163. print("MineMined 1.5\n")
  164. print("1; Singleplayer")
  165. print("2; Multiplayer (BETA)\n")
  166. write("Selection: ")
  167. input = read()
  168. if input == "1" then
  169. begin()
  170. elseif input == "2" then
  171. write("\nChannel: ")
  172. channel = read()
  173. Mult = true
  174. rednet.open("top")
  175. begin()
  176. end
Advertisement
Add Comment
Please, Sign In to add comment