From 7ded1e94400a4163f340e78ed1bb04c9b89adde7 Mon Sep 17 00:00:00 2001 From: Kislenko Maksim Date: Thu, 25 Jul 2019 18:33:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D0=B5=D1=82=D0=BA=D0=B0=20+=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=20=D1=81=D0=BC=D0=B5=D1=80=D1=82=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=20=D0=B8=D0=B7=D0=B1=D0=B5=D0=B3=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=BA=D1=80=D0=B0=D1=81=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BD=D1=83=D1=82=D1=80=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paperio/local_runner/game_objects/player.py | 7 ++--- paperio/local_runner/game_objects/scene.py | 34 +++++++++++++++------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/paperio/local_runner/game_objects/player.py b/paperio/local_runner/game_objects/player.py index 7f99153..440216c 100644 --- a/paperio/local_runner/game_objects/player.py +++ b/paperio/local_runner/game_objects/player.py @@ -8,7 +8,6 @@ class Player: speed = SPEED direction = None - prev_direction = None def __init__(self, id, x, y, name, color, client): self.id = id @@ -28,8 +27,6 @@ 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 @@ -184,9 +181,9 @@ def get_position(self): return (x, y), (x, y) != (self.x, self.y) def get_prev_position(self): - if self.prev_direction is None: + if self.direction is None: return self.x, self.y - return self.diff_position(self.prev_direction, self.x, self.y, WIDTH) + return self.diff_position(self.direction, self.x, self.y, WIDTH) def is_ate(self, players_to_captured): for p, captured in players_to_captured.items(): diff --git a/paperio/local_runner/game_objects/scene.py b/paperio/local_runner/game_objects/scene.py index 5f5c24f..a5a1c7a 100644 --- a/paperio/local_runner/game_objects/scene.py +++ b/paperio/local_runner/game_objects/scene.py @@ -4,6 +4,28 @@ from helpers import draw_quadrilateral, draw_line +class Grid: + def __init__(self, color): + self.batch = pyglet.graphics.Batch() + + y = WIDTH + while (y < WINDOW_HEIGHT): + self.batch.add(2, pyglet.gl.GL_LINES, None, + ('v2i', (0, y, WINDOW_WIDTH, y)), + ('c4B', 2 * color)) + y += WIDTH + + x = WIDTH + while (x < WINDOW_WIDTH): + self.batch.add(2, pyglet.gl.GL_LINES, None, + ('v2i', (x, 0, x, WINDOW_HEIGHT)), + ('c4B', 2 * color)) + x += WIDTH + + def draw(self): + self.batch.draw() + + class Scene: background_color = (220 / 255, 240 / 255, 244 / 255, 1) border_color = (144, 163, 174, 255) @@ -31,9 +53,11 @@ def __init__(self, scale): pyglet.gl.glClearColor(*self.background_color) pyglet.gl.glEnable(pyglet.gl.GL_BLEND) pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA, pyglet.gl.GL_ONE_MINUS_SRC_ALPHA) + self.grid = Grid(self.grid_color) def clear(self): self.window.clear() + self.draw_grid() def append_label_to_leaderboard(self, label, color): if len(self.labels_buffer) > self.leaderboard_rows_count: @@ -59,15 +83,7 @@ def show_game_over(self, timeout=False): self.game_over_label.draw() def draw_grid(self): - y = WIDTH - while (y < WINDOW_HEIGHT): - draw_line((0, y), (WINDOW_WIDTH, y), self.grid_color, 2) - y += WIDTH - - x = WIDTH - while (x < WINDOW_WIDTH): - draw_line((x, 0), (x, WINDOW_HEIGHT), self.grid_color, 2) - x += WIDTH + self.grid.draw() def draw_border(self): draw_line((0, 0), (0, WINDOW_HEIGHT), self.border_color, self.border_width)