adjusted loop fpr shadow-casting
This commit is contained in:
parent
9e8d2ac1dc
commit
0fac3bbe8c
@ -2,6 +2,7 @@ import sys
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
from itertools import product
|
||||||
import pygame
|
import pygame
|
||||||
from typing import NamedTuple, Any
|
from typing import NamedTuple, Any
|
||||||
import time
|
import time
|
||||||
@ -76,16 +77,16 @@ class Renderer:
|
|||||||
|
|
||||||
def visibility_rects(self, bp, view):
|
def visibility_rects(self, bp, view):
|
||||||
rects = []
|
rects = []
|
||||||
for i in range(-self.view_radius, self.view_radius+1):
|
for i, j in product(range(-self.view_radius, self.view_radius+1),
|
||||||
for j in range(-self.view_radius, self.view_radius+1):
|
range(-self.view_radius, self.view_radius+1)):
|
||||||
if bool(view[self.view_radius+j, self.view_radius+i]):
|
if bool(view[self.view_radius+j, self.view_radius+i]):
|
||||||
visibility_rect = bp['dest'].copy()
|
visibility_rect = bp['dest'].copy()
|
||||||
visibility_rect.centerx += i*self.cell_size
|
visibility_rect.centerx += i*self.cell_size
|
||||||
visibility_rect.centery += j*self.cell_size
|
visibility_rect.centery += j*self.cell_size
|
||||||
shape_surf = pygame.Surface(visibility_rect.size, pygame.SRCALPHA)
|
shape_surf = pygame.Surface(visibility_rect.size, pygame.SRCALPHA)
|
||||||
pygame.draw.rect(shape_surf, self.AGENT_VIEW_COLOR, shape_surf.get_rect())
|
pygame.draw.rect(shape_surf, self.AGENT_VIEW_COLOR, shape_surf.get_rect())
|
||||||
shape_surf.set_alpha(64)
|
shape_surf.set_alpha(64)
|
||||||
rects.append(dict(source=shape_surf, dest=visibility_rect))
|
rects.append(dict(source=shape_surf, dest=visibility_rect))
|
||||||
return rects
|
return rects
|
||||||
|
|
||||||
def render(self, entities):
|
def render(self, entities):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user