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)