Skip to content

Instantly share code, notes, and snippets.

@pathunstrom
Created September 7, 2017 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pathunstrom/75a9740d31af10ff2469f7e66760252f to your computer and use it in GitHub Desktop.
Save pathunstrom/75a9740d31af10ff2469f7e66760252f to your computer and use it in GitHub Desktop.
Generalized game object probably the actual thing that needs to be built to do this sort of thing.
class BaseGameObject(DirtySprite):
group = None
image_path = None
image = None
def __init__(self, scene, position=(0, 0)):
cls = self.__class__
if cls.group is None:
cls.group = cls.__name__
super().__init__(scene.groups[cls.group], scene.groups["render"])
self.scene = scene
if cls.image is None and cls.image_path:
cls.image = cls.transform(image.load(path.join(ROOT_DIR, cls.image_path)))
self.rect = None
if cls.image:
self.rect = cls.image.get_rect()
if self.rect is not None:
self.rect.center = position
self.last_position = position
def update(self, time_delta):
self.simulate(time_delta)
if self.rect.center != self.last_position:
self.dirty = True
self.last_position = self.rect.center
def simulate(self, time_delta):
pass
@staticmethod
def transform(image):
return image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment