[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] exact collisions
gen2n wrote:
I would need to check collision between a moving box and static
polygon (not surrounding rectangle). I thing I got two chances and
both I do not know ho to handle.
1/ somehow to use collisions-like function with respect on alfa channel
2/ polygon could be of the same color, so I could check ech pixel
color under (or nearby) my flying box.
Could you give me a kick how do do each of them and which could be
better?
Pavel
Hi Pavel,
as far as i remember, (i did a little CAD - App once) polygon collision
is no easy general case, it depends on the size of your poly and what
exactly you need the collision for (eg. is it enough if the the
collision occurs once at the edge and the ball bounces / player dies or
st like that) or should the objects drift through each other and you
need the overlapping piece?
In general you should first check if the moving box (i'll call it sprite
from now on) is near enough to the poly to collide. You could do it as
simply as checking if the box is inside the poly's bounding box
(calculate the smallest x and y and the largest x and y of your poly's
edges).
If it's inside the poly's box, i guess using a special surface for
collision detection is a good idea.
Maybe try an extra Surface of the size of the polygon's bounding box.
You could check numeric for access of the Surface.
Sorry, i have to go now, i'd like to finish, but i have a job interview
in two hours and have to go to prepare for it now. Wish me luck :) .
I'll paste the rest i'd already written but not finished below, maybe it
gives you a few hints anyways:
---------------
Make a Surface of the size of your poly.
After you blitted the polygon in one colour you know, you could check
the shape of the sprite at (x - polyleft, y - polytop) with numeric
( or do some bitmask voodoo, i'm sure it's easy enough with numeric )
some details depend on what you need the collision for.
that's it for now,
Daniel Out