[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Firing bullets
Charles Christie wrote:
Now my questions are:
A. If this is really all I have to do, how do I get the bullets to
register with my screen redrawing class? I use that dirty rect update
method where you have to specify the class with the sprite class.
If you want the bullet objects to have a reference back to the object
running the game (if any), you can give them that reference. Say:
class Game:
...
def MakeBullet(self):
self.bullets.append(self, Bullet() )
class Bullet:
def __init__(self,game_object):
self.game_object = game_object
If you do that, the bullets can then call functions of the game object.
I do that for the ships in my game so they can say, "Hey, I got
destroyed," but not for bullets. Also I've got separate lists for player
and enemy bullets to simplify collision detection.
I can probably figure out how to make the bullets come out of the boss
as they are fired. I can definitely do that...
Just set their starting location to be the same as the enemy's, or for
extra coolness use a relative location lined up with a visible turret.
But that assumes the bullets can't collide with the enemy itself!
The next thing is: for a kill function, can I make the bullets have a
little animation when they die? as in, shrink until they're tiny and
disappear? This obviously isn't very important at all and not useful
until the bullets actually appear on screen (which they haven't yet) but
I think it would be better than disappearing bullets. ;)
A really simple way to do it would be to load the bullet image as a
strip of images, say 256*64 if the bullet is 64*64. Then use the first
one for the bullet while it's alive. When it's destroyed, set a timer
over three frames and use frame 1, then 2, then 3, then delete the bullet.
Kris