Tuesday, July 19, 2011

some updates


Thanks to my friend James for doing some vector art for the tile icons. We will be working together to get some unit icons as well later on to replace the squares.


I have been getting the base systems working one at a time. Right now I have the population system working. My goal is to incorporate culture into population mechanics by having city population made up of varying demographics of populations that have migrated from other civs. These expats will have benefits and problems associated with them. They are fast population for the receiving nations, but they will be unhappier and will provide certain benefits to their home nation.


Also done is unit creation in cities. Currently what happens is you click on the train combat unit button and it reads the list of military technologies currently available to you and displays your options. Then when you click on the unit it stores the unit in a training queue. At the end of each turn every city will put a point of training into the next few units in the queue depending on the number of barracks in the city, with more barracks allowing you to train more units at the same time.

Sunday, April 24, 2011

Selections

Thought I would talk about my selection system this time. My main concern when I made the selection system was that I knew a lot of classes were going to need to access the selected object so I could either maintain a pointer to a selectable object inside the main class of the game or I could have the selectable class maintain static methods. The advantage of the former being that I would be able to run multiple games at the same time, and the latter would give me better code compartmentalization. Since this is a game, I am not expecting users to want to run concurrent games, so I went with the latter.

The selectable class itself is an abstract class from which everything that can be selected extends. The class maintains a static pointer to what is selected and has static methods for getting what is selected and changing it.

In order to interact with the GUI, each selectable has a method to alter the functionality of the ability JPanel on the left of the GUI. Right now there are 8 JButtons that set themselves to invisible every time something is selected and the object takes the JButtons it needs and changes the action handler on them and sets them back to visible. This creates the illusion of new ability boards, without having to create entirely new JButtons every time you click on something.

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.