View difference between Paste ID: NCftunVs and 5qui6fx3
SHOW: | | - or go back to the newest paste.
1
os.loadAPI("ocs/apis/sensor")
2
rednet.open("left")
3
local prox = sensor.wrap("right")
4
5
local ghostnames = 
6
{
7-
local player = {}
7+
[6] = "Blinky",
8-
player.X = 14
8+
[11] = "Pinky",
9-
player.Y = 24
9+
[12] = "Inky",
10-
player.dX = -1
10+
[13] = "Clyde"
11-
player.dY = 0
11+
}
12-
player.energize = false
12+
13
local ghosts =
14-
local gold = 0
14+
{
15-
local diamonds = 0
15+
	["Blinky"] = {},
16
	["Pinky"]= {},
17
	["Inky"] = {},
18
	["Clyde"] = {}
19
}
20
21
ghosts["Blinky"].state = "scatter"
22
ghosts["Blinky"].X = 14
23
ghosts["Blinky"].Y = 12
24
ghosts["Pinky"].state = "scatter"
25
ghosts["Pinky"].X = 14
26
ghosts["Pinky"].Y = 12
27
ghosts["Inky"].state = "scatter"
28
ghosts["Inky"].X = 14
29
ghosts["Inky"].Y = 12
30
ghosts["Clyde"].state = "scatter"
31
ghosts["Clyde"].X = 14
32-
local updatePlayerPos = function(p)
32+
ghosts["Clyde"].Y = 12
33
34
local playername = "mattivapa"
35
 
36
local data = {}
37
data.X = 14
38
data.Y = 24
39-
    p.X = pos[1]
39+
data.dX = -1
40-
    p.Y = pos[2]
40+
data.dY = 0
41-
    p.dX = facing[1]
41+
data.gold = 0
42-
    p.dY = facing[2]
42+
data.diamonds = 0
43
44
local score = 0
45
 
46
local offset = {}
47
offset.X = 20
48
offset.Z = 14
49
 
50
local facings = {{-1,0},{0,1},{1,0},{0,-1}}
51
 
52-
    if g > gold then 
52+
53-
      gold = g
53+
54-
      print("Score: "..tostring(10*gold+50*diamonds))
54+
55
end
56-
    if d > diamonds then
56+
 
57-
      diamonds = d
57+
58-
      print("Score: "..tostring(10*gold+50*diamonds))
58+
59-
      player.energize = true
59+
60
 
61
local updateData = function()
62
--  print(1)
63
  local details = prox.getTargetDetails(playername)
64
--  print(2)
65
  if details ~= nil then
66-
  updatePlayerPos(player)
66+
67-
--print("Sending:")
67+
68-
--print(textutils.serialize(player))
68+
    data.X = pos[1]
69-
  rednet.broadcast(textutils.serialize(player))
69+
    data.Y = pos[2]
70-
  if player.energize == true then
70+
    data.dX = facing[1]
71-
    player.energize = false
71+
    data.dY = facing[2]
72-
    rednet.broadcast(textutils.serialize(player))
72+
73-
    rednet.broadcast(textutils.serialize(player))
73+
74
    for k,v in pairs(details.Inventory) do
75-
  sleep(0.1)
75+
76
        d = d+v["Size"]
77
      elseif v["Name"] == "Gold Ore" then
78
        g = g+v["Size"]
79
      end
80
    end
81
    if g > data.gold then
82
      data.gold = g
83
      score = score + 10
84
      print("Score: "..tostring(score))
85
    end
86
    if d > data.diamonds then
87
      data.diamonds = d
88
      score = score + 50
89
      print("Score: "..tostring(score))
90
    end
91
  end
92
end
93
 
94
 
95
while true do
96
  updateData()
97
  local id, message, dist = rednet.receive(0.2)
98
  local ghost = ghostnames[id]
99
  if ghost ~= nil then
100
  	message = textutils.unserialize(message)
101
  	ghosts[ghost].X = message.X
102
  	ghosts[ghost].Y = message.Y
103
  	if message.state == "dead" and ghosts[ghost].state ~= "dead" then
104
  		score = score + 400
105
  	end
106
  	ghosts[ghost].state = message.state
107
  	rednet.send(id,textutils.serialize(data))
108
  end
109
end