Hi!
I am currently faced with a design problem in my game design, not terrible but it bothers me enough so I want to ask others opinions :-)
I am currently experimenting with pygame, I have developed a little space shooter and now I would like to handle some bonuses.
Right now I have an abstract class Bonus from which derive all the bonuses currently implemented: a "health bonus" which gives back some health to the player, a "death bonus" which drops the player's health to 1.
In my game loop here is what I do (roughly):
def testCollisionBonusBolt():
#bolts are sprites fired by the player that allow him to get the bonuses
collisions = pygame.sprite.groupcollide(bonusesGroup, boltsGroup, True, True)
for col in collisions:
player.bonuses.append(col)
And right after I tell the player to use the bonuses
class Player:
...
def useBonuses(self):
for bonus in self.bonuses:
bonus.use(self)
Until now everything is OK, but I would like to add a "bomb bonus" which when shooted by the player explodes and kills the enemies on his surroundings.
This "bonus" implements the "use(target)" method of my abstract class Bonus as the others to, but I feel kind of bad adding such a bonus to the list of the player's bonuses as there should be no relation between them!
The concept behind a bonus is that this is "something that does something to something", previously the targets where my player class but now it is not as clear... Of course instead of calling player.useBonuses() after detecting which bonuses where shooted I could test the type (using isinstance) for example of the bonuses but after all the discussions I've read about duck-typing and why it's the pythonic way I am wondering how can I manage my bonus problem?
Thanks for reading this far, hope you guys can help me out!
regards