From de630eedb6f2eecaea990c3557f66ce2c44f095c Mon Sep 17 00:00:00 2001 From: fheinrich <fheinrich@techfak.uni-bielefeld.de> Date: Wed, 7 Feb 2024 10:42:00 +0100 Subject: [PATCH] Added view restriction with a black polygon. --- overcooked_simulator/gui_2d_vis/drawing.py | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/overcooked_simulator/gui_2d_vis/drawing.py b/overcooked_simulator/gui_2d_vis/drawing.py index ab6f7060..c907874b 100644 --- a/overcooked_simulator/gui_2d_vis/drawing.py +++ b/overcooked_simulator/gui_2d_vis/drawing.py @@ -92,13 +92,36 @@ class Visualizer: ) if "view_restriction" in state and state["view_restriction"]: - direction = np.array(state["view_restriction"][0]) - pos = np.array(state["view_restriction"][1]) - angel = state["view_restriction"][2] - # rotate direction vector in both direction with the angel # draw 2 large rect which are rotated so that one edge is the viewing border + direction = pygame.math.Vector2(state["view_restriction"][0]) + pos = pygame.math.Vector2(state["view_restriction"][1]) + angle = state["view_restriction"][2] + + pos = pos * grid_size + pygame.math.Vector2([grid_size / 2, grid_size / 2]) + + rect_scale = max(width, height) + + left_beam = pos + (direction.rotate(angle) * rect_scale * 2) + right_beam = pos + (direction.rotate(-angle) * rect_scale * 2) + + pygame.draw.polygon( + screen, + colors["black"], + ( + pos - (direction * grid_size * 0.8), + left_beam, + pos + - (direction * rect_scale * 2) + + (direction.rotate(90) * rect_scale), + pos + - (direction * rect_scale * 2) + + (direction.rotate(-90) * rect_scale), + right_beam, + ), + ) + def draw_background(self, surface, width, height, grid_size): """Visualizes a game background.""" block_size = grid_size // 2 # Set the size of the grid block -- GitLab