Tuesday, April 19, 2011

First post

This is going to be my blog where I keep track of my Civilization type game that I am making. My reasons for making this game are:
- expand my coding skills
- make a portfolio to hopefully get a job
- I thought Civ5 sucked and figured why not make a ridiculously complicated game by myself

Incase you are wondering about the Java, I am using it because I am learning Java and C++ at the same time right now and Java is 10x easier to code than C++ and I really don't have time to learn a 3rd language at the same time.

So, I have already been working on this for 3 months in between class and homework. It has just reached a point where I can interact with the game through the GUI. I can make settlers settle cities and any unit can move around. I guess I will talk a bit about one of the most important things, how the underlying hexagonal tile system works.

There are two parts to it, the HexTile class and the MapPanel class, where one is the underlying array of Tiles, and the other is a JPanel that displays the map and converts MouseEvents into positions that the rest of the code can understand. The MapPanel is just a simple simulated camera with zoom and movement functionality, so I will just talk about HexTile.

The HexTile class stores a matrix of Tiles, and matrices are obviously not hexagonal. So what you can do is a horizontal 'shift' of 0.5 Tiles per row by having all incoming gets and sets converted from the hexagonal grid to their appropriate place in the matrix. HexTile also handles row and column wrapping by converting any out of bounds  get or set to its appropriate Tile. By containing all of this inside the HexTile class it becomes much easier to think about what you are doing in other areas of the code.

I also have the hexagonal distance finding method in there which is kind of cool since for a while I had been doing the distance finding by going from tile to tile until I had worked with it enough that I figured out a way to do it with just algebra. It was surprisingly complex due to the whole row shifting thing.

No comments:

Post a Comment