First steps towards a cocos2d hex-tile engine

On March 28, 2010, in Design, by Steffen Itterheim

I decided i should start with the first steps towards my own game. I already know that it needs to be tile-based because that makes a lot of things a whole lot less complicated. I also know that rectangular tiles just don’t cut it and hexagons are the way to go. Not only that, they’re a natural fit for what i intend to build – but no, it’s not going to be a wargame and you’re not going to move around entities across the grid either. For now i’ll leave it up to your imagination what the heck i might be doing. It’ll become clearer over time. ;)

I already know about the scaling issues of tiled engines, this cocos2d forum post being a good example. So i’m wary of mathematically correct hexagons (correct as in fractional vertex coordinates) and instead tried to come up with a simple hexagon shape whose vertices all lie on fixed point coordinates. In the image below it’s the top row. And as you can see in comparison to the perfectly shaped hexagons below (implemented according to this 8-year old Gamedev.net article) they are a bit compressed along the Y-axis. But that is actually ok since i would prefer a look not straight from above but at a slight angle, so that any objects can be drawn as seen from a 60° or even 45° angle. On the other hand each object now needs 5 images for each of the 6 directions, with the horizontal direction mirrored. And hex tiles can’t just be rotated to any angle, only flipped along the x axis. So there’s a lot of gfx to be done (and paid for) but i’ll worry about this later on.

In fact, i fully intend to work on this game off of my mind, step by step. No big plans, just one step at a time, and see where it leads me to. I have some grand ideas of course but i see them more as a guiding light than a plan that needs to be implemented. If i learned anything from the process of creating Black Hole is that it’s never a singularity you’re working towards. The game shifts and drifts as opinions clash and fun evolves. I don’t even want to imagine how crappy the game was when we started but it can be a painful process, the idea that seemed so cool seemed to fail so utterly at one point and just didn’t provide the necessary fun for quite some time. But as you move along things start to come together in different ways, as you try out different ideas. And that’s how i’m planning this game. At the moment all i know is that i need a hex engine for cocos2d.

But doesn’t cocos2d support TMX maps which support hex maps? Well yes, and no. It doesn’t support hex maps with the edges pointing up and down but i need the straight connections to be in the horizontal direction. The other thing is: i don’t want to design maps, i want to generate them. And change them during gameplay. That seems like it’s not possible with TMX hex maps. I also want complete freedom, and taking a little time to come up with a hex tilemap engine is time well spent. I’m not building an engine from the ground up, just what is needed to draw a hex map and selecting fields based on coordinates.

About the look of the game, i browsed the web to find good examples of hex tiles that would fit perfectly to the game. But that was harder than i thought. There’s only one set of hex tiles i particularly liked, they were made by David Baumgart and posted on his Gamedev.net journal:

I especially like the blending effect seen in the zoom-in part of the image. As much as possible i would like to hide the fact that the game map is based on hexagons and create a much smoother, visual look. But that is still a long way out and i don’t even know if that’s possible on the iPad. I’ll definetely dig into that though.

Tagged with: