[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Firing bullets
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Firing bullets
- From: "andrew baker" <failrate@xxxxxxxxx>
- Date: Sun, 1 Apr 2007 15:51:28 -0700
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sun, 01 Apr 2007 18:51:40 -0400
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=IhlIvBmFN+OnHZyXEPo0mFs2s+oo2qRLOAn3tv35aCQ5zh7hfXW9OHnw3LRyIt8b1udfKujz5xjn+9ZrtHGQH8+uLY6oAryGZl+SbzrtDatutvXvipkZ+88s3VncYG6LLpfrdr+wroUNop4pRN/B8RH6EemvxY2PMTX3nDEp0jQ=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=FX3ekvAL4Hy6c9vvdoVxHRQJI24vX6gZEJHycRulbUxOBWkfcWsz590vxhK+HJ9hFTGxx/2X2B5zcLYFP998+X72frHrRH2DmJnCWuMvb6QqGBPlB2kH/gl9SZIrQSUGZPs2p+8dw9Os59ZUxAfzroUPRlJBlWjyW0sVZ+78PCg=
- In-reply-to: <20070401204602.6d057c39@compaq>
- References: <8c46c7370703260637j138b213eg7c18e476e98c20cc@mail.gmail.com> <Pine.BSO.4.64.0703291218420.10698@fuyu.mindrot.org> <383b6d6f0703282327r7a6fac06s8304e852766a5ecf@mail.gmail.com> <20070401204602.6d057c39@compaq>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Well, I start by making a container, which will be just a simple list
bullets = []
This is assuming the simple case, where all of the bullets are the same type.
Then, create a bunch of bullets
for i in range(0, totalBullets):
bullets.append(myBulletClass())
When you need a bullet,
firedBullet = bullets.pop()
When that bullet "dies",
bullets.append(firedBullet)
You might want to make the bullets list into a whole class if you
start adding features, but for most cases, this is all the firepower
you'll need.
As for patterns, I would do macros, personally.
Declare different functions that do small patterns
def starBurst(qty):
angleSlice = 360/qty
for i in range(0, qty-1):
current = bullets.pop()
current.movingX = math.cos(angleSlice*i)*current.maxSpeed
current.movingY = math.sin(angleSlice*i)*current.maxSpeed
Then, assign and object's fire function to the value of the function
myBadGuy.attack = starBurst
Now, when you call myBadGuy.attack(), your starBurst function will be called.