import colors from vector import * class drawable(list): """ Abstract superclass for all objects drawable on canvas. A drawable is a list of points ('Vector') with a 'color' attribute. """ def __init__(self, *points, color=colors.BLACK): """ Overrides '__init__' method of 'list' class. Will only accept point-like objects and adds 'color' attribute. """ list.__init__(self) for point in points: drawable.append(self, point) self.color = color def append(self, item): """ Overrides 'append' method of 'list' class. Will only accept point-like objects. """ try: list.append(self, Vector(*item)) except: raise TypeError(f"Expected vector/point, but got {item.__class__.__name__}") def __str__(self): """ Override '__str__' method of 'list' class. Return string with classname, points in 'self' and additional attributes. """ return f"{self.__class__.__name__}({list.__repr__(self)[1:-1]}) with {self.__dict__.__repr__()[1:-1].replace(':', ' =').replace(' ', '')}" def __repr__(self): """ Override '__repr__' method of 'list' class. Return string with classname, points in 'self' and additional attributes. """ return f"{self.__class__.__name__}({list.__repr__(self)[1:-1]}, {self.__dict__.__repr__()[1:-1].replace(':', ' =').replace(' ', '')})" def draw(self, screen, offset): """Abstract method to draw 'self' on 'screen'.""" raise NotImplementedError def draw_shadow(self, screen, offset, source, color=(31,31,31)): """Abstract method to draw a shadow of 'self' on 'screen'.""" raise NotImplementedError def dist_to(self, source): """Abstract method to calculate the distance to the player ('source').""" raise NotImplementedError def cut(self, source, portal): """Abstract method to cut 'self' to fit in the portal view.""" raise NotImplementedError