remove_objects

This commit is contained in:
Pascal Engélibert 2024-02-17 13:37:55 +01:00
parent 57a64d3292
commit a8009f744d

20
game.py
View file

@ -105,6 +105,14 @@ def send_all(msg):
for oid in players:
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}), ["127.0.0.1", 33033])
@ -173,10 +181,11 @@ while True:
objects[player["oid"]] = Player(player["oid"], address, player["pos"], player["color"])
players[player["oid"]] = objects[player["oid"]]
elif r["type"] == "quit":
players.pop(r["oid"])
objects.pop(r["oid"])
removable.append(r["oid"])
elif r["type"] == "stab":
objects[r["oid"]].stab()
remove_objects()
screen.fill(black)
@ -187,12 +196,7 @@ while True:
obj.draw(screen)
obj.print_debug(lines)
for oid in removable:
if oid in objects:
objects.pop(oid)
if oid in players:
players.pop(oid)
removable = []
remove_objects()
xlog.display(screen, lines)