Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- rednet.open("left")
- local prox = sensor.wrap("right")
- local ghostnames =
- {
- [6] = "Blinky",
- [11] = "Pinky",
- [12] = "Inky",
- [13] = "Clyde"
- }
- local ghosts =
- {
- ["Blinky"] = {},
- ["Pinky"]= {},
- ["Inky"] = {},
- ["Clyde"] = {}
- }
- ghosts["Blinky"].state = "scatter"
- ghosts["Blinky"].X = 14
- ghosts["Blinky"].Y = 12
- ghosts["Pinky"].state = "scatter"
- ghosts["Pinky"].X = 14
- ghosts["Pinky"].Y = 12
- ghosts["Inky"].state = "scatter"
- ghosts["Inky"].X = 14
- ghosts["Inky"].Y = 12
- ghosts["Clyde"].state = "scatter"
- ghosts["Clyde"].X = 14
- ghosts["Clyde"].Y = 12
- local playername = "mattivapa"
- local data = {}
- data.X = 14
- data.Y = 24
- data.dX = -1
- data.dY = 0
- data.gold = 0
- data.diamonds = 0
- local score = 0
- local offset = {}
- offset.X = 20
- offset.Z = 14
- local facings = {{-1,0},{0,1},{1,0},{0,-1}}
- local yawToFacing = function(yaw)
- local ind = math.floor(math.fmod(math.abs(yaw)+45,360)/90)
- return facings[ind+1]
- end
- local worldToGame = function(X,Z)
- return {offset.Z+Z,offset.X-X}
- end
- local updateData = function()
- -- print(1)
- local details = prox.getTargetDetails(playername)
- -- print(2)
- if details ~= nil then
- local pos = worldToGame(details.Position.X,details.Position.Z)
- local facing = yawToFacing(details.Yaw)
- data.X = pos[1]
- data.Y = pos[2]
- data.dX = facing[1]
- data.dY = facing[2]
- local g = 0
- local d = 0
- for k,v in pairs(details.Inventory) do
- if v["Name"] == "Diamond" then
- d = d+v["Size"]
- elseif v["Name"] == "Gold Ore" then
- g = g+v["Size"]
- end
- end
- if g > data.gold then
- data.gold = g
- score = score + 10
- print("Score: "..tostring(score))
- end
- if d > data.diamonds then
- data.diamonds = d
- score = score + 50
- print("Score: "..tostring(score))
- end
- end
- end
- while true do
- updateData()
- local id, message, dist = rednet.receive(0.2)
- local ghost = ghostnames[id]
- if ghost ~= nil then
- message = textutils.unserialize(message)
- ghosts[ghost].X = message.X
- ghosts[ghost].Y = message.Y
- if message.state == "dead" and ghosts[ghost].state ~= "dead" then
- score = score + 400
- end
- ghosts[ghost].state = message.state
- rednet.send(id,textutils.serialize(data))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement