[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Working with maps
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Working with maps
- From: Thiago Chaves <shundread@xxxxxxxxx>
- Date: Tue, 18 May 2010 16:07:59 +0300
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Tue, 18 May 2010 09:08:48 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=HRzHzgJsf3OTxlQsqh8lzFo4+H97NPedLaJQ/H0FXN8=; b=lSTVXwDhUVrCZCnyFHnE484CLIpQbQdW7/JtKn7JKyJ6AFfmB+u4I5bjyiSojSsjlg hV5f16qJyoAN7wBaIsiR0glR4xZwg3T5F9kOORmuUVyh2muHl+H2DMA1JImmbZOKqxwP khKRxHhnIzvvZG43CTQ6307KPBiGs7tegDRz0=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=RHoGs6KnNVEprmn1473rIhegF43eVdZwtCMZZ7G0KL5OFeuFD7ax6n9GJL46JWcz+P 0fxLMGfjLNZ9BakAFC3Lno7DE3vjEwhDE1TZfaNk/wqz01eJWvIcUjgmmJgR2hPJKTnT 3DrDMJqt/GKnuqdAtYfVxgMFqQJnO1ApDHQ54=
- In-reply-to: <4BF249A9.7070807@xxxxxxxxxxxxx>
- References: <20100518040912.GA2428@5732Z> <4BF249A9.7070807@xxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Computational geometry alternative:
You can do it with geometric shapes. Make the states/countries
polygons. Triangularize the polygons and then it is a matter of
finding out whether the (x,y) coordinate is inside one of the
polygon's triangles.
See here: http://en.wikipedia.org/wiki/Polygon_triangulation
-Thiago
On Tue, May 18, 2010 at 11:02 AM, Timothy Baldock <tb@xxxxxxxxxxxxx> wrote:
> 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?
>>
>