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

Re: [pygame] Re: Collision bounds smaller than sprite image



I'm pretty new to Pygame, so I don't know anything about that. I use my own 
rect class, rather than the Pygame one, because I prefer to not be bound to 
Pygame, when possible. (I would probably use the pygame.rect for drawing, 
however, but I am using PyOpenGL instead.)

Implementations of most other geometry (esp. vectors) can be found in a lot of 
game programming books (in the appendix), or on gamasutra.com. They are 
almost always in C/C++, but it doesn't take much to rewrite them in Python.

I've never seen a class for polygons, however, but I have implemented one 
based on this paper: 
http://www.gamasutra.com/resource_guide/20030121/jacobson_01.shtml

So, I have arbitrary polygons, but they aren't completely rigid. They depend 
on a system of particles(vertices) and constraints. My entire physics engine 
is based on this system.

I've also implemented collision detection for polygons based on material in 
this book: 
http://books.elsevier.com/us/mk/us/subindex.asp?isbn=1558605940&country=United+States&community=mk&ref=&mscssid=9FR3BWV7KRJ18NHEAUFJDRTD9G80EASB
This works with any polygons, not just the particle-constraint type that I am 
using.

I have not, however, created a collision response algorithm for these polygons 
that I am happy with. I can separate them, but w/o angular effects. So, a 
book dropped on the end of a table will 'stick' instead of correctly rolling 
over the edge.


On Friday 31 December 2004 08:02 pm, andrew baker wrote:
> Yeah, that's cool.  It'd be even cooler if you had an easy-to-use
> library & API for all of that fun :D
>
> Also, d'you know if anyone has extended the Pygame Rect class to
> include other shapes (ie, circles, arbitrary polygons, vectors)?
>
> On Fri, 31 Dec 2004 14:50:16 +0000, Austin Haas <pygame@xxxxxxxxxxxxxxxx> 
wrote:
> > Also, I know it's common to have more than one collision rect. That way
> > you can have one for where an object can attack from, and a separate one
> > for where an object is vulnerable (or for any other purpose).
> >
> > So, for example, a ninja performing a flying jump kick might have an
> > "attack" rect over their feet, but a "vulnerable" rect over the rest of
> > their body. That way if another ninja kicks them from behind, in the back
> > of the head, they will take damage. But, if two ninjas kick their feet
> > into each other, you can make them bounce apart with no damage to either
> > one. I made a game once where these rects had weights associated with
> > them, so that a stronger character would prevail if two of these "attack"
> > rects came in contact.
> >
> > Also, in another game, I had the collision rect shrink when the character
> > ducked. The flexability was really nice because I could make the game
> > more forgiving than what was actually shown by the graphics. Likewise,
> > with multiple rects, you can activate and deactivate them as needed. So,
> > for example, you only have an active attack rect when you swing your
> > sword.
> >
> > On Friday 31 December 2004 02:32 pm, Austin Haas wrote:
> > > I've heard that in shooters, they always make the collision rect for
> > > your ship smaller than the graphic, and the rect for your enemies
> > > larger. Otherwise, players tend to feel like they are being cheated
> > > when a bullet barely touches them and kills them.
> > >
> > > On Friday 31 December 2004 07:15 pm, Lee Harr 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/