Pythonic way to handle coordinates
pdorange at pas-de-pub-merci.mac.com
Sat Jan 17 09:48:12 CET 2009
I'm used python for 3 months now to develop small arcade games (with
I just got a question about coordinates handling.
My games are in 2D so i deal with x,y coordinates for sprites (but woudl
be the same u-issue in 3D).
At the beginning i simply use x and y to pass to my methods
ie : sprite.move(x,y)
after looking closely to pygame code, i noticed that pygame implement a
Rect class but no Point class, and instead require tuple for
ie : pygame.draw.line(surface,color,start,end)
where start and end are tuple, like (x,y).
I found this nice and rewrote my API to use tuples instead of 2
so i got could do :
sprite.move(loc) or sprite.move((x,y))
Nice, but i got a problem when my methodes return tuple, as it's
unmutable i could not modify them and i got to used tempory variables to
do that, not very clean :
loc+=10 < ERROR
i could also do :
The second method could not be used when i'm instead one of my method, i
need to used the first one.
What is the elegant way to handle coordinates ?
Do i need to continue using tuples or do i need to write a Point class.
I feel a point class would be nice, because i could implement operators
with it ? But i think Point class must exist allready ?
Ce message est sous licence Creative Commons "by-nc-sa-2.0"
More information about the Python-list