pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
HexagonExample

HexagonExample - 1.0

John Eriksson (wmjoers)

Tags:

Description

Using hexagon based maps is not as easy as using square maps. Mostly because it takes more effort to translate pixel locations (like mouse clicks) to map locations. When I search this issue on the net I found a really nice article explaining a technique to solve this matter with mathematics. But I wanted to have a pixel-perfect pixel-to-map algorithm so I used the article as a base and implemented a way to solve this.

Based on the assumption that if I needed this then probably someone else need it I wrote this little example to show how a pixel-to-hexagon-map can be implemented in python/pygame.

Example Instructions

When you move around the mouse pointer the application will translate the mouse location to a hexagon map location and show this with a yellow hexagon.

Press space to toggle the display of the help grid square. You can use this to get a better understanding of the source code.

Links

Home Page: http://arainyday.se
Source: http://arainyday.se/projects/python/HexagonExample/HexagonExample.tar.gz

Screenshot


click to view original size

Releases

HexagonExample - 1.0 - Apr 27, 2006

Pygame.org account Comments

If you wish to leave a comment with your pygame.org account, please sign in first.

December 11, 2012 6:20pm - Avirup Kundu - nickname: (avirup) - 5/5
Awesome! just what i was looking for!! thanks a lot.
September 7, 2006 3:26am - Theory Teller - nickname: (theory314)
if this works it's what I've wanted for a long time. Excellent.
August 7, 2006 4:08am - Anonymous - nickname: () - 1/5
gay
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Nov 13, 2014

Nov 11, 2014


Nov 10, 2014

Nov 9, 2014

Nov 6, 2014


Nov 4, 2014

Nov 3, 2014

Oct 28, 2014

Oct 21, 2014

Oct 16, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)