diff --git a/mapping/main.py b/mapping/main.py index 3a3c98c7142f058e7c1b5430f809f66693941cbc..d758913902231c442d3255415d9af430848aa676 100644 --- a/mapping/main.py +++ b/mapping/main.py @@ -10,23 +10,16 @@ def send_passthrough(msg, x, y): x = int(x) y = int(y) - newx = x - newy = y - if x > id[0]: - d = O - newx += 1 - elif x < id[0]: d = E - newx -= 1 + elif x < id[0]: + d = O elif y > id[1]: - d = S - newy += 1 - else: d = N - newy -= 1 + else: + d = S - envoyer_msg(d, "PT;{},{};{}".format(newx, newy, msg)) + envoyer_msg(d, "PT;{},{};{}".format(x, y, msg)) def send_xy(x, y, msg): send_passthrough(msg, x, y) @@ -57,9 +50,7 @@ def update_id(new_id): display_id() - def handle_receive(msg, d): - msg = msg_to_str(msg) if msg.startswith("SET_ID"): tmp_id = msg[7:].split(",") @@ -77,16 +68,29 @@ def handle_receive(msg, d): m = msgs[2] x, y = msgs[1].split(",") + x = int(x) + y = int(y) + if x == id[0] and y == id[1]: handle_receive(m, d) return - send_passthrough(m, int(x), int(y)) + send_passthrough(m, x, y) + + + +# Main + + afficher_texte("Ready", VERT, speed=0.01) - + while True: for d in [N, S, E, O]: msg = recevoir_msg(d) + + if msg == b"": continue + + msg = msg_to_str(msg) handle_receive(msg, d)