[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
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!