Skip to content
Snippets Groups Projects
Commit de630eed authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Added view restriction with a black polygon.

parent de52447e
No related branches found
No related tags found
1 merge request!42Resolve "FOV of the players, fog-of-war like vision"
Pipeline #45612 passed
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment