Jump to content
  • Advertisement
Sign in to follow this  
DarkMortar

[java] Trouble with Hex Map

This topic is 4306 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Tryin to draw my temp hex tiles, but i am having problems getting them to 'stick' horizontially, ive read tuts. but my problem is that i dont know how to find the length of each side on the hexagon, i need that for the other problems to work, but ive gone this far with just dividing the rectangular hexagon image. code: // even row if (i%2==0) { hexGraphic[j].draw(g, (int)xPos+i*HEX_SIZE, (int)yPos+j*HEX_SIZE); } // odd row else { hexGraphic[j].draw(g, (int)xPos+i*HEX_SIZE, (int)yPos+j*HEX_SIZE+HEX_SIZE/2); } picture: http://img295.imageshack.us/img295/8981/hexhelpni9.png

Share this post


Link to post
Share on other sites
Advertisement
Don't think of them as hexes. Think of them as 6 equalateral triangles joined.

So if you draw a line between the center points of 2 hexes, you are actually bisecting a triangle in each. And since all your hexes/triangles are the same size, you can figure out the length of one to find the distance between the 2. Just us basic geometry.

d = b / 2
e2 = b2 - d2

So if b is 6 then
e = sqrt(62 - 32)
e = sqrt(27)
e = 5.2

Hope that helps.

ps. I tried to draw a picture, but the forum won't let me draw preformatted text anymore. Check out this link instead and the pics there should help. The second picture shows the 6 triangles and the text helps explain a bit of what I am talking about.

http://mathforum.org/pow/solutio90.html

Share this post


Link to post
Share on other sites
I was looking at some other tutorials and replaced the code with this: i use 0.75 to represent the overlapping part:

// even row
if (i%2==0) {
hexGraphic[j].draw(g,
(int)xPos+i*(int)(HEX_SIZE*0.75),
(int)yPos+j*HEX_SIZE);
}
// odd row
else {
hexGraphic[j].draw(g,
(int)xPos+i*(int)(HEX_SIZE*0.75),
(int)yPos+j*HEX_SIZE+HEX_SIZE/2);
}
}

is there anything wrong with this? it seems to work fine, i just hope it doesnt mess up other calculations for placing objects on certain hex coords.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!