[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Drawing Bullets
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Drawing Bullets
- From: Charles Joseph Christie II <sonicbhoc@xxxxxxxxx>
- Date: Sat, 28 Apr 2007 12:18:13 -0400
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sat, 28 Apr 2007 12:18:18 -0400
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:from:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; b=ibLCRCjik2QMy6yGykJEatG3PSqld0QBiRXWP6MAi/QhY+ZjtC0Rjk4hKxzQoY8bk/kLhJSZKriTytjpAyRcs98pdFORo58zV+2bCXSkthTPS3nhsdE8nJSh95drJpQIjFPiUCX/P7BR1+LMAwZERLZsJTxK3IdOVCLbMfdYL1E=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:from:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; b=Ep579VWiGDCzM/VdPxiYUuBnMCLLo389Rq5o5LNwqrZUtCypBucXszDrqHNwhgNZq/V1k1o9binZucVvI1Rc76t7e4/6nSf0k4vzJ8Ip8jBD5wI8r0m9GvVMpVdK/CFHBseUNOPpAwz/7d8g9nAmebydp2w+sFjRHFSjbtydRlU=
- In-reply-to: <46336C0B.4030704@bluewin.ch>
- References: <8c46c7370704270843w58cad593j1a60be6dc0a05180@mail.gmail.com> <200704281134.18299.sonicbhoc@gmail.com> <46336C0B.4030704@bluewin.ch>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: KMail/1.9.6
On Saturday 28 April 2007 11:45:15 am DR0ID wrote:
> Charles Joseph Christie II schrieb:
> > On Saturday 28 April 2007 01:28:38 am Kris Schnee wrote:
> >> Charles Christie wrote:
> >>> Well, bullets just seem to be a sticking point for me...
> >>
> >> Stick with it!
> >>
> >>> 1. bullet cleanup (self.kill, etc.) which isn't important to me right
> >>> now, as the demo won't be running for an extended period, and when it
> >>> does it'll be running on a monstrous beast of a computer that can
> >>> probably handle the crappy coding.
> >>> 2. Drawing bullets (pygame.update.dirtyrects, etc) which is VERY
> >>> important to me right now.
> >>
> >> I don't think you need a kill function. What I did in my shooter game
> >> was to have the bullets stored in two lists, and then every frame:
> >>
> >> self.player_bullets = [bullet for bullet in self.player_bullets if
> >> bullet.ttl > 0]
> >> self.enemy_bullets = [bullet for bullet in self.enemy_bullets if
> >> bullet.ttl > 0]
> >>
> >> This filtering gets rid of the ones whose time-to-live is expired, due
> >> to Python's automatic garbage-collection.
> >>
> >>> So, I tried to load an image for the bullets, and that didn't work
> >>> either. What happened was that it couldn't load the image... probably
> >>> because it doesn't exist. Which it does, though.
> >>>
> >>> It's in the project directory under the folder img/Bullet.png. When I
> >>> put img/Bullet.png into the load_image function it says it can't load
> >>> the image! I tried it with front and back slashes and it didn't work.
> >>
> >> Yeah, Python doesn't automatically handle path names. Try os.path.join,
> >> as in:
> >>
> >> import os
> >> filename = os.path.join("img","Bullet.png")
> >> my_image = pygame.image.load(filename).convert_alpha()
> >>
> >> As I understand it, os.path.join attaches the directory terms (any
> >> number of them) according to whatever format is appropriate for the OS.
> >>
> >>> After I get the image loaded, however, I can't add the bulletlist to my
> >>> list of dirtyrects to update... The dirtyrect doesn't read from lists!
> >>> How do I get pygame.sprite.RenderUpdates to display my bullets on the
> >>> screen?
> >>
> >> I haven't messed with dirty rectangle functions myself, so this one is
> >> beyond me.
> >>
> >> Kris
> >
> > Woohoo! Thanks! I'll try this ASAP. Still need to figure out how to get
> > the dirtyrects thing sorted out though...
>
> Hi
>
> if you use Renderupdates then you have to do the following:
>
> make an instance of the RenderUpdateGroup
> add as many sprites you want to it
>
> then in each frame of you game:
> renderUGroup.clear()
> # update your sprites in here
> dirty_rects = renderUGroup.draw(screen)
> display.update(dirty_rects)
>
> It should be more or less that thing. Try to look at an example like
> "chimp" on the pagame website.
>
> Sorry, about that short and quick instruction, but I have not much time
> at the moment.
>
> ~DR0ID
No problem, any help is appreciated! Does RenderUpdateGroup read from lists,
though?