[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Working with maps



On May 17, 2010, at 9:47 PM, Miguel Bejar wrote:
I have the same problem as the OP, I need to find a way to have a map with irregular shapes and have the exhibit different behaviors depending on user input. I don't know what the term for that is so I haven't been able to start doing any research as to how to go about it.

In general, the problem is to decide WHICH graphical region (the outlines of the various countries) encloses a point (the cursor). This is sometimes called "Point in Region (Polygon)" testing, but the more common term is "hit testing."

This looks long and somewhat promising: http://stackoverflow.com/questions/217578/point-in-polygon-aka-hit-test

PyGame has a Sprite system, as others have mentioned. There's a tutorial document here: http://www.pygame.org/docs/tut/SpriteIntro.html

Hint: Do not optimize until
1) You have something that actually works, and
2) It definitely is not fast enough.

I suggest this because:
1) It is very easy to get distracted by optimizing
2) Hit testing is one of the more fascinating places to reinvent optimizations
3) Optimizations often introduce subtle bugs
4) PyGame sprites have many of these optimizations already
5) http://en.wikipedia.org/wiki/The_Elements_of_Programming_Style