[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Re: Collision bounds smaller than sprite image
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Re: Collision bounds smaller than sprite image
- From: andrew baker <failrate@xxxxxxxxx>
- Date: Fri, 31 Dec 2004 11:34:51 -0800
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Fri, 31 Dec 2004 14:35:21 -0500
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=n37v3MoEEL1fZXQSKElecfq4p2ZJL7Ekizh2uksr+oJdcDwPr+l+CHCpGaJiUDpTCrBXm/ukh4AUYsOYkxO5GbIphof2Mc+l7gVZZeanyuysos7+2Ebbc5WlSgRFiP6ZpQ3KAK6rhtPeJ8wgP4wzUWDHhGBTJuF2gTjBE/opGEk=
- In-reply-to: <BAY2-F403BE4B0504AAC20954875B19D0@phx.gbl>
- References: <BAY2-F403BE4B0504AAC20954875B19D0@phx.gbl>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Yeah, I'm on http://sourceforge.net/projects/smpltn (or something like
that), but I can't remember off-hand if that has my routine, so I'll
just repeat it here.
import random
import string
import sys
import os, os.path
import pygame
from pygame.locals import *
try:
import Numeric as N
import pygame.surfarray as surfarray
except ImportError:
raise ImportError, "Numeric and Surfarray are required."
...some other defs here...
def loadStrip(filename, width):
print "loadStrip: ",filename
#strip_source, asdf = load_image(filename, -1)
fullname = os.path.join('data', filename)
try:
strip_source = pygame.image.load(fullname)
except pygame.error, message:
print 'Cannot load image:', fullname
raise SystemExit, message
#image = image.convert()
colorkey = strip_source.get_at((0,0))
strip = surfarray.pixels3d(strip_source)
print 'len(strip)',len(strip)
celcount=len(strip)/width
celstrip = [[]] * celcount
print 'celcount:',celcount
for cels in range(0,celcount):
print 'cels',cels
print 'celrange: s: %s e: %s' % (cels*width,(cels+1)*width)
temp = strip[cels*width:(cels+1)*width]
celstrip[cels] = surfarray.make_surface(temp)
celstrip[cels] = celstrip[cels].convert()
celstrip[cels].set_colorkey(colorkey, RLEACCEL)
return celstrip, celstrip[0].get_rect()
It's a bit ugly, but it works. BTW, I tried creating the
collision_rect in my engine, and it worked like a charm.
On Fri, 31 Dec 2004 23:45:25 +0430, Lee Harr <missive@xxxxxxxxxxx> wrote:
> >Yeah, the more I think about it, the more I think that creating a
> >second rect and storing it as an attribute is the way to go. All of
> >the graphical adjustments and movements will be performed with the
> >normal rect attribute, and the actual collision and bounds tests will
> >be done with the collision_rect.
>
>
> That is how I did it in pygsear:
> http://www.nongnu.org/pygsear/
>
> (except I called it spriteobj.crect :o)
>
>
> > I guess it's not really that hard,
> >but I was really exhausted after writing a strip -> cel routine :D
>
> Interesting ... I have been thinking about writing such a beastie
> for pygsear for the last few weeks... are you releasing your code?
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today it's FREE!
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
>
--
Andrew Ulysses Baker
"failrate"