[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Firing bullets



Darn... I'm confusing myself so bad with this... I hope I can get focused on this again before school's out... have one of those days where I code half of the program spontaneously, you know?

Urgh. This is nearly infuriating. It seemed so simple in my head but when I go to code it the logic escapes me. I feel kinda dumb right now...

Here is all I've got right now:
----------------------------------------
##Bullet Code
##In the VERY VERY VERY EXTREMELY far future, I would like BulletML for bullet code
##But I don't know how to use it ;_;

#Bullet Container
bullets=[]

#Total amount of bullets
totalBullets = 50

#create bullets
for i in range(0, totalBullets):
   bullets.append(Bullet())
  
class Bullet:
    def __init__(self, x, y, angle=0):
        self.x = x
        self.y = y
        self.angle = angle
        self.position = (self.x, self.y)
        self.speed = 50
        self.born = pygame.time.get_ticks()
        self.ttd = 5
    def update(self):
        self.x += math.cos(self.angle) * self.speed * interval / 100
        self.y += math.sin(self.angle) * self.speed * interval / 100
----------------------------------------

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.

I can probably figure out how to make the bullets come out of the boss as they are fired. I can definitely do that...

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. ;)

On 4/8/07, Greg Ewing <greg.ewing@xxxxxxxxxxxxxxxx> wrote:
Charles Joseph Christie II wrote:

> I know that it is faster, but I'm not sure how much faster, or how much
> more efficiently it will work, and if it is easier or harder to code it
> that way, although the kill and recreate way sounds a bit easier to
> code.

Just code it the easiest way that will work to
begin with. Chances are it will be perfectly okay.
Later, *if* it turns out to be to slow, you can
experiment with optimisations.

--
Greg