[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: "Charles Christie" <sonicbhoc@xxxxxxxxx>
- Date: Mon, 2 Apr 2007 11:50:03 -0400
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Mon, 02 Apr 2007 11:50:15 -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:references; b=Wz98/eKb4fn/BwKrVNbe36R5zfFZcfXCgB1asy0nj+G6BJxKG43SDbNpzdBH7vjIHGCl96hVzcPU9D08MjPbLH/mcUEv2bte5vSM5+tVsN5ApWZQ+4gkF01UdENqZ+sV61IdyylWP/ktibRqMVXefb7aozzWzpzD3dYK+v/CJJg=
- 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:references; b=fJ+ukj+K6OiAjH9OCdQHiU5fNTskVDLmsPYITYykNIhXLjca3GbTaJMu+VHiozA7qXoNA5cZTOBlAX44lw8/7sxVfPhBji9//1keE53koiwreByrQvm98YvhC34prfNiUP6kRR005Hhu6F9TrlSEipMrYKIC/t9NdgP2Ty7LHV0=
- In-reply-to: <383b6d6f0704011551w71d11038w27611a3c897594ac@mail.gmail.com>
- References: <8c46c7370703260637j138b213eg7c18e476e98c20cc@mail.gmail.com> <Pine.BSO.4.64.0703291218420.10698@fuyu.mindrot.org> <383b6d6f0703282327r7a6fac06s8304e852766a5ecf@mail.gmail.com> <20070401204602.6d057c39@compaq> <383b6d6f0704011551w71d11038w27611a3c897594ac@mail.gmail.com>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Ha! That makes things much easier to take in. So I was doing it partially right. Thanks for the insight! You're a lifesaver.
The pygame mailing list is really great... I don't know what I'd do without you guys!
On 4/1/07, andrew baker <failrate@xxxxxxxxx> wrote:
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.