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:
|
||||
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,11 +181,12 @@ 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)
|
||||
|
||||
lines = []
|
||||
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue