ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pygame-users
pygame-users
Re: [pygame] Fastest (x,y) distance calculation
by Rene Dudfield other posts by this author
Sep 13 2003 5:49PM messages near this date
[pygame] Fastest (x,y) distance calculation | Re: [pygame] Fastest (x,y) distance calculation
Zak Arntson wrote:
... cut stuff about distance calculation.


This is pretty cool.
http://www.ifm.liu.se/~ulfek/projects/SCAM-current/doc/SCAM.html

ODE through pyode also supports collision detection.


Here's a couple of functions which you can quickly cut the number of 
entities to check against in two.

def get_unique_pairs(vals):
    """ finds unique combinations from a given list of values.
         Which doesn't include combinations with itself.
    """
    vals_cpy = vals
    pairs = []
    pairs_extend = pairs.extend

    while vals_cpy:
       
        vals_head = vals_cpy[0]
        vals_cpy = vals_cpy[1:]

        new_ones = map(lambda x:(vals_head,x), vals_cpy)
        pairs_extend(new_ones)

    return pairs


def get_to_collide(vals):
    """ Returns a dict keyed by one of the vals, valued by a
         list of the vals which to check collisions against.
    """
    vals_cpy = vals
    tocollide = {}

    while vals_cpy:
        vals_head = vals_cpy[0]
        vals_cpy = vals_cpy[1:]

        if vals_cpy:
            tocollide[vals_head] = vals_cpy

    return tocollide


Have fun!
Thread:
Zak Arntson
Rene Dudfield
Niki Spahiev
Magnus Lie Hetland
Pete Shinners
Bob Ippolito
Zak Arntson
Magnus Lie Hetland
Nicola Larosa

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved