Advertisement
hbar

Untitled

Jun 21st, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("ocs/apis/sensor")
  2. rednet.open("left")
  3. local prox = sensor.wrap("right")
  4.  
  5. local maze =
  6. {
  7. "############################",
  8. "#............##............#",
  9. "#.####.#####.##.#####.####.#",
  10. "#.####.#####.##.#####.####.#",
  11. "#.####.#####.##.#####.####.#",
  12. "#..........................#",
  13. "#.####.##.########.##.####.#",
  14. "#.####.##.########.##.####.#",
  15. "#......##....##....##......#",
  16. "######.#####.##.#####.######",
  17. "######.#####+##+#####.######",
  18. "######.##..........##.######",
  19. "######.##.###--###.##.######",
  20. "######.##.#......#.##.######",
  21. "######....#......#....######",
  22. "######.##.#......#.##.######",
  23. "######.##.########.##.######",
  24. "######.##..........##.######",
  25. "######.##.########.##.######",
  26. "######.##.########.##.######",
  27. "#............##............#",
  28. "#.####.#####.##.#####.####.#",
  29. "#.####.#####+##+#####.####.#",
  30. "#...##................##...#",
  31. "###.##.##.########.##.##.###",
  32. "###.##.##.########.##.##.###",
  33. "#......##....##....##......#",
  34. "#.##########.##.##########.#",
  35. "#.##########.##.##########.#",
  36. "#..........................#",
  37. "############################"
  38. }
  39.  
  40. local ghostnames =
  41. {
  42. [6] = "Blinky",
  43. [11] = "Pinky",
  44. [12] = "Inky",
  45. [13] = "Clyde"
  46. }
  47.  
  48. local ghosts =
  49. {
  50.     ["Blinky"] = {},
  51.     ["Pinky"]= {},
  52.     ["Inky"] = {},
  53.     ["Clyde"] = {}
  54. }
  55.  
  56. ghosts["Blinky"].state = "scatter"
  57. ghosts["Blinky"].X = 14
  58. ghosts["Blinky"].Y = 12
  59. ghosts["Pinky"].state = "scatter"
  60. ghosts["Pinky"].X = 14
  61. ghosts["Pinky"].Y = 12
  62. ghosts["Inky"].state = "scatter"
  63. ghosts["Inky"].X = 14
  64. ghosts["Inky"].Y = 12
  65. ghosts["Clyde"].state = "scatter"
  66. ghosts["Clyde"].X = 14
  67. ghosts["Clyde"].Y = 12
  68.  
  69. local playername = "mattivapa"
  70.  
  71. local data = {}
  72. data.X = 14
  73. data.Y = 24
  74. data.dX = -1
  75. data.dY = 0
  76. data.gold = 0
  77. data.diamonds = 0
  78.  
  79. local score = 0
  80.  
  81. local offset = {}
  82. offset.X = 20
  83. offset.Z = 14
  84.  
  85. local facings = {{-1,0},{0,1},{1,0},{0,-1}}
  86.  
  87. local yawToFacing = function(yaw)
  88.   local ind = math.floor(math.fmod(math.abs(yaw)+45,360)/90)
  89.   return facings[ind+1]
  90. end
  91.  
  92. local worldToGame = function(X,Z)
  93.   return {offset.Z+Z,offset.X-X}  
  94. end
  95.  
  96. local updateData = function()
  97. --  print(1)
  98.   local details = prox.getTargetDetails(playername)
  99. --  print(2)
  100.   if details ~= nil then
  101.     local pos = worldToGame(details.Position.X,details.Position.Z)
  102.     local facing = yawToFacing(details.Yaw)
  103.     data.X = pos[1]
  104.     data.Y = pos[2]
  105.     data.dX = facing[1]
  106.     data.dY = facing[2]
  107.     local g = 0
  108.     local d = 0
  109.     for k,v in pairs(details.Inventory) do
  110.       if v["Name"] == "Diamond" then
  111.         d = d+v["Size"]
  112.       elseif v["Name"] == "Gold Ore" then
  113.         g = g+v["Size"]
  114.       end
  115.     end
  116.     if g > data.gold then
  117.       data.gold = g
  118.       score = score + 10*g
  119.       print("Score: "..tostring(score))
  120.     end
  121.     if d > data.diamonds then
  122.       data.diamonds = d
  123.       score = score + 50*d
  124.       print("Score: "..tostring(score))
  125.     end
  126.   end
  127. end
  128.  
  129. print("Game starting, get to the starting position")
  130. sleep(5)
  131. print("Sending start message...")
  132. rednet.broadcast("Begin!")
  133.  
  134. while true do
  135.   updateData()
  136.   local id, message, dist = rednet.receive(0.2)
  137.   local ghost = ghostnames[id]
  138.   if ghost ~= nil then
  139.     message = textutils.unserialize(message)
  140.     ghosts[ghost].X = message.X
  141.     ghosts[ghost].Y = message.Y
  142.     if message.state == "dead" and ghosts[ghost].state ~= "dead" then
  143.         score = score + 400
  144.     end
  145.     ghosts[ghost].state = message.state
  146.     rednet.send(id,textutils.serialize(data))
  147.   end
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement