xXm0dzXx

Untitled

May 30th, 2012
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 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.  
  10. local currentX = x/2
  11. local currentY = 2
  12. local direction = ">"
  13.  
  14.  
  15. function drawCursor()
  16. term.clear() --Clears the screen
  17.  
  18. for i = 1,x do
  19. for v = 1,y do
  20. if v>3 then
  21. term.setCursorPos(i,v)
  22. write("X")
  23. end
  24. end
  25. end
  26.  
  27. term.setCursorPos(4,2)
  28. write("Y")
  29.  
  30. for i = 1,lives do
  31. term.setCursorPos(i,y)
  32. write(">")
  33. end
  34.  
  35.  
  36. term.setCursorPos(x-string.len("RND: " ..round),y)
  37. write("RND: " ..round)
  38.  
  39. for i = 1,#mined do
  40. if mined[i] then
  41. mined[i] = tostring(mined[i])
  42. minedX = string.sub(mined[i], 1, string.find(mined[i], "/")-1)
  43. minedY = string.sub(mined[i], string.find(mined[i], "/")+1, string.len(mined[i]))
  44. term.setCursorPos(minedX,minedY)
  45. write(" ")
  46. --if currentX == minedX and currentY == minedY-1 then
  47. -- currentY = minedY
  48. --end
  49. end
  50. end
  51. term.setCursorPos(x-1,1)
  52. write("@")
  53. if currentY == 1 then currentY = 2 end
  54. if currentX == x then
  55. currentX = x-1
  56. elseif currentX == 0 then
  57. currentX = 1
  58. end
  59.  
  60. if Mult then
  61. for i = 1,#Players do
  62. Players[i] = tostring(Players[i])
  63. minedX = string.sub(Players[i], 1, string.find(Players[i], "/")-1)
  64. minedY = string.sub(Players[i], string.find(Players[i], "/")+1, string.len(Players[i]))
  65. term.setCursorPos(minedX,minedY)
  66. write("M")
  67. end
  68. end
  69. term.setCursorPos(currentX, currentY)
  70. write(direction)
  71. end
  72.  
  73. function begin()
  74. while true do
  75. drawCursor()
  76. local e,key,message = os.pullEvent()
  77. if e == "key" then
  78. if key == 17 or key == 200 then --up
  79. mined[#mined+1] = currentX.. "/" ..currentY
  80. currentY = currentY -1
  81. direction = "^"
  82. elseif key == 31 or key == 208 then --down
  83. if currentY < y-1 then
  84. mined[#mined+1] = currentX.. "/" ..currentY
  85. currentY = currentY +1
  86. end
  87. direction = "v"
  88. elseif key == 203 or key == 30 then --left
  89. mined[#mined+1] = currentX.. "/" ..currentY
  90. currentX = currentX -1
  91. direction = "<"
  92. elseif key == 205 or key == 32 then --right
  93. mined[#mined+1] = currentX.. "/" ..currentY
  94. currentX = currentX +1
  95. direction = ">"
  96. end
  97.  
  98. if Mult then
  99. rednet.broadcast("[MM] ["..channel.."] " ..currentX.. "/" ..currentY)
  100. end
  101. elseif Mult and e == "rednet_message" then
  102. if string.sub(message, 1, string.len("[MM] [" ..channel.."] ")) == "[MM] [" ..channel.."] " then
  103. Players[#Players] = string.sub(message, string.len("[MM] [" ..channel.."] *"), string.len(message))
  104. end
  105. end
  106. end
  107. end
  108.  
  109. print("MineMined\n")
  110. print("1; Singleplayer")
  111. print("2; Multiplayer (BETA)\n")
  112. write("Selection: ")
  113. input = read()
  114. if input == "1" then
  115. begin()
  116. elseif input == "2" then
  117. write("\nChannel: ")
  118. channel = read()
  119. Mult = true
  120. rednet.open("top")
  121. begin()
  122. end
Advertisement
Add Comment
Please, Sign In to add comment