Re: I want to lirn pithon but pithon doesn't want me to do so

@142
Probably not at your level of programming experience, but if objects are only 1 tile you can put them all in an array, then do myarray.sort(key = lambda o: o.position).  Then for each index in the array the next object to the left is

myarray[i-1]

and the next to the right is

myarray[i+1]

.  Obviously make sure to check that the indices don't go negative or past the end.

Then you write some relatively tricky loops over it to find out what might be close to something else.  But what exactly you need here depends on what you want to do, and optimizing collision in general becomes a whole thread itself.

The right answer is to go find a library for spatial hashes and use it, though.  That or any of various kinds of tree.

In general I advise you to avoid optimizing collision until you're not learning basics, unless you're already at a point where this is a problem for you.



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ty via Audiogames-reflector

Reply via email to