A design I just thought of, which is probably better than what I thought of before, for objects.
Objects do not necessarily have properties. However, some have x and y, for instance.
A plain GameObject doesn't actually do anything. It can be extended to provide movement and drawing however. But as the base GameObject doesn't have any default behaviour, it means objects that are invisible don't unnecessarily waste space.
An object can register itself for the draw event so it is drawn, and provide a method to be called. It provides a z-index for sorting.
Similarly, an object can register for the begin step, step and end step events (similarly to game maker).
So, something like this:
class GameObject:
"""
Class all game objects inherit from.
"""
def __init__(self, environment):
self.environment = environment
class MyFancyObject(GameObject):
"""
A fancy game object!
"""
def __init__(self, environment, x=0, y=0):
GameObject.__init__(self, environment)
self.x, self.y = x, y
self.sprite = load_sprite("lol.png")
self.environment.register_event("draw", self.draw, zindex=20)
self.environment.register_event("step", self.step)
def step(self):
self.x += 2
self.y += 3
def draw(self, canvas):
canvas.draw(self.sprite, self.x-self.enviroment.viewport[0], self.y-self.enviroment.viewport[1])
This isn't that different from the game maker coding style, which would make porting easier.