söndag 15 december 2019

Castle Defence Game - Part 1

I have been considering developing a new game. In order to speed things up I plan on using C# and Unity. The game would be created for normal consumer grade computers.  The game will be a 2D single-player since multiplayer requires a steady user-base and fitting business model to go around. In one of my other games that I created, called Half-Robot, I made everything from scratch. This ended up taking a lot of time. I realize now that it is probably wiser to take shortcuts in order to get something done. At the same time, I also feel that quality will be essential to get something that has a chance of being successful. In short, I will need to find a balance between taking shortcuts and coming up with a cool game. This is pretty much the stage where I am at now. That, and coming up with a well-defined idea for the game I want to develop.

I do not have a clear vision yet for exactly what the game will contain. I do however have some vague hints for some fundamental baselines from which I can add new ideas to. By adding more and more ideas in a structured manner, I hope to get a clearer picture in my head about what I want to create.

For starters, I think it will be okay to have a very simple main menu. The only buttons it will contain is "New Game", "Load Game", "Help" and "Exit". "Load Game" will let the user choose between 3 different slots, also used for saving a game. Now that I think about it there should also be an "automatic save" slot, in case the computer crashes. Thus, in total 4 loadable slots and 3 savable slots. Each slot with data could contain the time it was saved as well as some short description of progress, I suppose.

When clicking on "New Game" I think certain base functionalities makes sense to have. First, there are a lot of noobs who find games difficult out in the world. Therefore, I will want to add one "easy" and one "hard" difficulty setting. Maybe this could be achieved with emoji-buttons instead of plain easy/hard text. The emojis would be like one pro-gamer image and some other which could resemble a noob. The reason for having more images and less text makes the game feel like it has more content, than if there was just plain text everywhere. Having images instead of text everywhere could easily get out of hand however and make things harder to understand or navigate.

Next, I would also want to have a rectangle shaped area by which a fantasy game map can be overviewed. This game map would consist of procedurally generated imaginary countries, which together fill up the area of an island. This may sound difficult, but if done sloppily, it really isn't. All you need to do is to start out with an arbitrary "simple polygon" making up the island, perhaps the entire rectangle for simplicity. Each polygon is defined by a set of 2D points, ordered clockwise or anti-clockwise. A random set of lines are then computed which intersect the island. These lines will then split the island into different regions by collecting all the points in which the lines intersect with one another, as well as with the island. Now that I think about it, it may be better to define all polygons with one level of abstraction; as a set of segments, where one segment is made up by two points, instead of a set of pure points. Thus, for each randomly generated new line, all existing segments are checked for intersection with the line. If an intersection is detected, then that existing segment is split into two new segments. As a final step maybe the newly added segment can be split up into new segments as well by saving all intersection points in a list. As a special case, all segments of length 0, or close to 0 would be deleted to account for special cases. Then I would lastly end up with a bunch of segments, so how do I find which segments belongs to the same country? Well, what I end up with, or should end up with is a graph of edges and points. Thus, for each point not associated with a country (because all points will need to be part of at least 1 country), I will need to find the "shortest path" starting from that unassigned point, where the path also ends at the same point. A path-finding algorithm could be used, such as Dijkstra's algorithms if I let all edges have a weight of 1. This way I could easily find all countries in linear time.

The world map would be previewed in the menu and randomized when clicking on a dice-button. The games purpose could be, to make things simple, to take control of all the countries. The player would start out by selecting one country for placing his or her castle. That country would automatically become controlled. All controlled countries can be colored green, reachable countries colored yellow and unreachable countries colored gray. This would be all that is needed for the menu system before starting a new game.