![]() |
| ||
| just for fun I'm re-creating the classic PacMan for the fun of it and needed a way to translate back and forth between directions and dx, dy for a sprite. Here was a fun solution that avoided cumbersome if...elif...elif...elif... chains. Any thoughts on readability, efficiency? Specifically, if this gets called by 4 monsters and 1 pacman every clock-tick = 1/60 sec, am I likely to run into trouble? Jeff def get_direction(dx,dy): |
| ||
| Re: just for fun Hi! Well, at least it's an interesting way to do it :) Because Python is an OO language, I would probably have a class Monster and an instance-variable self.current_direction. I think this would be cleaner. Regards, mawe |
| ||
| Re: just for fun I think you're right. The problem I was having was a disconnect between the direction and the dx, dy. The better solution is, IMO,
Jeff |
| All times are GMT -4. The time now is 9:18 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC