Separating Sprites from Models with PyGame

So I'm trying to code a game using the Model-View-Controller pattern, and therefore have a need to separate the models for my game objects with their sprite representations. The problem that I'm running into is with PyGame's sprite class. For example, let's take the code below for a Tank object in my game.

class Tank(Projectile):
'''A tank object.'''
MAX_SPEED = 8.0

@property
def MAX_TURN(self):
return 10.0 - 0.75 * abs(self.velocity)

def __init__(self, position=(0, 0), heading=0.0, power=100.0, name=None):

self.gun = Gun(self)

self.power = power
self.name = name

def update(self, dt):
super(Tank, self).update(dt) #Just writing this here for illustrative purposes


Additionally, in a separate views file, I have the code for the basis of a sprite:

class TankSprite(RotatableSprite):
_layer = 0
TankSprite.groups = tank_group, all_group


Now the standard solution might just be to merge these two into one, and then use pygame's pygame.sprite.group.update() method to update and draw everything as desired. But with a MVC pattern, I run into a few problems:

• First, there is no way of knowing when a new object is created. For example, when the Tank fires its Gun, its creates a Bullet object. Since the Bullet is a model, there is no way to detect this creation without some awkward View code in the Models.
• Second, I don't believe I can use pygame's collision methods or Group objects, which isn't the worst, but somewhat awkward.

Really, the bullet problem is killing me more than anything else. Any help would be appreciated.

• And now you know why the MVC pattern doesn't really work for games (and why game development != business software development) – thedaian Aug 10 '11 at 19:56
• @thedaian gets a hole in one. Just because you have a hammer, not everything is a nail. – Patrick Hughes Aug 10 '11 at 20:17

As you've written it, your Tank is both your model and your controller. Normally, you either have a view controller and a model controller that talk to each other and their appropriate other part, or a single controller that mediates between the view and model directly.
• (Filling in anything of consequence in your update function is still going to result in Tank being both a model and controller.) – user744 Aug 10 '11 at 20:42
• And if you want an option to run the game without visulisation, just add an option that skips your rendering code (in many games, there's a single render function, which makes it easy to skip) – thedaian Aug 10 '11 at 21:26