I'm working on a 2D game engine using pygame. Right now I have drawing/sprites, collision detection/setting, and moving in the GameObject class (base class for all other objects). Is this bad practice? I've read some articles that discourage this, but I don't understand why such things should be separated if they all deal with the GameObject class.
class GameObject(pygame.Rect):
def __init__(self, location, size,
tag, current_sprite=None, sprites=None):
super().__init__(location, size)
self.tag = tag
self.current_sprite = current_sprite
self.sprites = sprites
self.collisions = {}
def draw(self, surface):
surface.blit(self.current_sprite, self)
def move(self, x_distance, y_distance):
self.x += x_distance
self.y += y_distance
def set_all_collisions(self, keys, *groups):
"""Map each key to a list of Rects who collided
with the GameObject.
"""
for key, group in zip(keys, groups):
indexes = self.collidelistall(group)
if indexes:
self.collisions[key] = [group[index] for index in indexes]
else:
self.collisions[key] = [GameObject((1000, 1000), (32, 32), 'dummy')]