remove_objects
This commit is contained in:
parent
57a64d3292
commit
a8009f744d
1 changed files with 12 additions and 8 deletions
20
game.py
20
game.py
|
@ -105,6 +105,14 @@ def send_all(msg):
|
||||||
for oid in players:
|
for oid in players:
|
||||||
sock.send(msg, objects[oid].address)
|
sock.send(msg, objects[oid].address)
|
||||||
|
|
||||||
|
def remove_objects():
|
||||||
|
for oid in removable:
|
||||||
|
if oid in objects:
|
||||||
|
objects.pop(oid)
|
||||||
|
if oid in players:
|
||||||
|
players.pop(oid)
|
||||||
|
removable.clear()
|
||||||
|
|
||||||
sock.send(json.dumps({"type":"join","pos":me.pos,"color":me.color,"port":address[1],"oid":me.oid}), ["192.168.0.255", 33033])
|
sock.send(json.dumps({"type":"join","pos":me.pos,"color":me.color,"port":address[1],"oid":me.oid}), ["192.168.0.255", 33033])
|
||||||
sock.send(json.dumps({"type":"join","pos":me.pos,"color":me.color,"port":address[1],"oid":me.oid}), ["127.0.0.1", 33033])
|
sock.send(json.dumps({"type":"join","pos":me.pos,"color":me.color,"port":address[1],"oid":me.oid}), ["127.0.0.1", 33033])
|
||||||
|
|
||||||
|
@ -173,10 +181,11 @@ while True:
|
||||||
objects[player["oid"]] = Player(player["oid"], address, player["pos"], player["color"])
|
objects[player["oid"]] = Player(player["oid"], address, player["pos"], player["color"])
|
||||||
players[player["oid"]] = objects[player["oid"]]
|
players[player["oid"]] = objects[player["oid"]]
|
||||||
elif r["type"] == "quit":
|
elif r["type"] == "quit":
|
||||||
players.pop(r["oid"])
|
removable.append(r["oid"])
|
||||||
objects.pop(r["oid"])
|
|
||||||
elif r["type"] == "stab":
|
elif r["type"] == "stab":
|
||||||
objects[r["oid"]].stab()
|
objects[r["oid"]].stab()
|
||||||
|
|
||||||
|
remove_objects()
|
||||||
|
|
||||||
screen.fill(black)
|
screen.fill(black)
|
||||||
|
|
||||||
|
@ -187,12 +196,7 @@ while True:
|
||||||
obj.draw(screen)
|
obj.draw(screen)
|
||||||
obj.print_debug(lines)
|
obj.print_debug(lines)
|
||||||
|
|
||||||
for oid in removable:
|
remove_objects()
|
||||||
if oid in objects:
|
|
||||||
objects.pop(oid)
|
|
||||||
if oid in players:
|
|
||||||
players.pop(oid)
|
|
||||||
removable = []
|
|
||||||
|
|
||||||
xlog.display(screen, lines)
|
xlog.display(screen, lines)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue