From e7a05f3cd31afab2927916da9d33f1a8a6bdf523 Mon Sep 17 00:00:00 2001 From: Kislenko Maksim Date: Thu, 25 Jul 2019 11:41:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D1=82=D1=8B=D0=BA=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BE=20=D1=88?= =?UTF-8?q?=D0=BB=D0=B5=D0=B9=D1=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paperio/local_runner/game_objects/player.py | 35 ++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/paperio/local_runner/game_objects/player.py b/paperio/local_runner/game_objects/player.py index 7561d19..7f99153 100644 --- a/paperio/local_runner/game_objects/player.py +++ b/paperio/local_runner/game_objects/player.py @@ -8,6 +8,7 @@ class Player: speed = SPEED direction = None + prev_direction = None def __init__(self, id, x, y, name, color, client): self.id = id @@ -27,6 +28,8 @@ def __init__(self, id, x, y, name, color, client): self.is_disconnected = False def change_direction(self, command): + self.prev_direction = self.direction + if command == UP and self.direction != DOWN: self.direction = UP @@ -157,8 +160,38 @@ def get_direction_line(self): if self.direction == RIGHT: return self._get_line(WIDTH, 0) + def diff_position(self, direction, x, y, val): + if direction == UP: + return x, y - val + + if direction == DOWN: + return x, y + val + + if direction == LEFT: + return x + val, y + + if direction == RIGHT: + return x - val, y + + def get_position(self): + if self.direction is None: + return self.x, self.y + + x, y = self.x, self.y + while not ((x - round(WIDTH / 2)) % WIDTH == 0 and (y - round(WIDTH / 2)) % WIDTH == 0): + x, y = self.diff_position(self.direction, x, y, self.speed) + + return (x, y), (x, y) != (self.x, self.y) + + def get_prev_position(self): + if self.prev_direction is None: + return self.x, self.y + return self.diff_position(self.prev_direction, self.x, self.y, WIDTH) + def is_ate(self, players_to_captured): for p, captured in players_to_captured.items(): - if self != p and (self.x, self.y) in captured: + position, is_move = self.get_position() + if self != p and position in captured and \ + (is_move or self.get_prev_position() in captured): return True return False