26 lines
926 B
Python
26 lines
926 B
Python
from typing import Tuple
|
|
import pygame
|
|
|
|
class Entity:
|
|
def __init__(self, points: Tuple, color: str, border_color: str = None):
|
|
self.points = points
|
|
self.color = color
|
|
self.border_color = border_color
|
|
|
|
def update(self) -> None:
|
|
pass
|
|
|
|
def draw(self, surface: pygame.Surface, tile_size) -> None:
|
|
for square in self.points:
|
|
pygame.draw.polygon(surface, pygame.Color(self.color), square, 0)
|
|
if self.border_color:
|
|
pygame.draw.polygon(surface, pygame.Color(self.border_color), square, max(tile_size // 6, 1))
|
|
|
|
def collide(self, entity) -> bool:
|
|
for square_one in self.points:
|
|
for square_two in entity.points:
|
|
for i in range(4): # 4 vertices
|
|
if square_one[i][0] == square_two[i][0] and square_one[i][1] == square_two[i][1]:
|
|
return True
|
|
return False
|