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

Re: [pygame] Working with maps



Hi Kenny,

I'd do this by making each country a sprite with a transparent
background (colour-key transparency would work), then whenever the user
clicks doing a collision detection between the position of the mouse
cursor (first use rect-collision to build a small number of tiles which
match, then do pixel-perfect collision based on alpha - i.e. using the
sprite's mask). Easiest way to do this IMO is to draw an "invisible"
(e.g. position the sprite, but don't actually draw it to the screen)
1x1px sprite at the position of the mouse cursor, then collide that
against the group containing all the country sprites.

This technique means the countries can be any colour you want, or the
colour can change without messing things up. I used this method for my
isometric game engine to allow selection of tiles and other objects and
found it to be quite fast.

Thanks,

Timothy


On 18/05/2010 05:09, Kenny Meyer wrote:
> Hey,
> 
> I'd like to work with irregular formed geometric shapes like those in of
> country maps in pygame.
> 
> I want to do the following:
> "Divide" a country map into its states and provinces and make each of them
> "click-able", where the map could be an image (*.png) or maybe a vector graphic
> (*.svg).
> 
> The result should be:
> A game where to guess and click the name of the state and province on a map.
> 
> Observations:
> It would be quite difficult to assign each state/province fixed coordinates as
> those are irregular geometric shapes.
> 
> Any ideas, pointers to other projects or suggestions?
>