feat: add collision logic between entities

This commit is contained in:
2021-06-08 14:02:23 -04:00
parent 673c4774f2
commit 776170fb9b
5 changed files with 45 additions and 42 deletions

View File

@@ -11,27 +11,13 @@ from util.ConfigurationManager import ConfigurationManager
'''
class Piece(Entity):
def __init__(self, shape: Tuple, position: Tuple, color: str):
super().__init__()
self.color = color
self.points = self.__get_points(shape, position)
def __init__(self, shape: Tuple, position: Tuple, color: str, border_color: str):
super().__init__(self.__get_points(shape, position), color, border_color)
self.center = self.__get_center(shape, position)
self.previous_points = None
self.previous_center = None
def draw(self, surface: pygame.Surface) -> None:
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
hex_color = ConfigurationManager.configuration["color"]["border"] # TODO should abstract out color call?
base_color = pygame.Color(self.color)
border_color = pygame.Color(hex_color)
for sub_points in self.points:
pygame.draw.polygon(surface, base_color, sub_points, 0)
pygame.draw.polygon(surface, border_color, sub_points, max(tile_size // 6, 1))
def move(self, vector: Tuple) -> None:
self.previous_points = copy.deepcopy(self.points)
self.previous_center = copy.deepcopy(self.center)
@@ -52,13 +38,16 @@ class Piece(Entity):
self.previous_points = copy.deepcopy(self.points)
self.previous_center = copy.deepcopy(self.center)
for sub_points in self.points:
for point in sub_points:
h = point[0] - self.center[0]
k = point[1] - self.center[1]
new_points = []
for square in self.points:
for vertex in square:
h = vertex[0] - self.center[0]
k = vertex[1] - self.center[1]
point[0] = (k * -1) + self.center[0]
point[1] = h + self.center[1]
vertex[0] = (k * -1) + self.center[0]
vertex[1] = h + self.center[1]
new_points.append([square[-1]] + square[0:-1])
self.points = new_points
def revert(self) -> None:
if self.previous_points and self.previous_center: