[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] shapes other than rects?



Just thinking about the transparent collision thing...
could you do this, or is there a better way: 
(sorry for bad formatting)

rect1 = surface1.get_rect
rect2 = surface2.get_rect
array1 = surface1.array2d
array2 = surface2.array2d

loc_surface1 = array((x1,y1)) #where you blit surf1 to
loc_surface2 = array((x2,y2)) #same for surf2

overlap_rect =
(rect1.move(loc_surface1)).clip(rect2.move(loc_surface_2))

if overlap_rect:
    mini_rect1 = overlap_rect.move(-loc_surface1)
    mini_rect2 = overlap_rect.move(-loc_surface2)
    # (if transparent color is black:) 
    mini_array1 =
array1[mini_rect1.left:mini_rect1.right+1,mini_rect1.top:mini_rect2.bottom+1]
 
    mini_array2 =
array2[mini_rect2.left:mini_rect2.right+1,mini_rect2.top:mini_rect2.bottom+1]
    if mini_array1 and mini_array2:
        print "collision"
    else:
        print "rects overlap, but no collision"



--- Chris Armstrong <carmstro@dynup.net> wrote:
> I'd like to be able to have shapes other than
> rectangles in my game,
> preferrably with the same functionality as rects
> (collision detection, etc).
> Does anyone have any advice for me for creating such
> things? I realize
> creating a base rect-like object would be quite
> processor intensive for
> lots of calculations... I'm open to ideas. Thanks.
> 
> -- 
> Chris Armstrong        http://www.dynup.net:8010/   
>    carmstro@dynup.net
> There is a 90% chance that this message was written
> when the author's been
> awake longer than he should have. Please disregard
> any senseless drivel.
> ____________________________________
> pygame mailing list
> pygame-users@seul.org
> http://pygame.seul.org


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices. 
http://auctions.yahoo.com/
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org