Board like strategy map
I want to make a strategy game like Risk. I want to use C# for the mechanics and Unity for the graphics. My problem is that I don't know how to create the map itself and integrate it with C#. I don't want a tile map but instead I want to create a customized world map, with different provinces defined by me. The map would be something like Imperial Glory, where you see it top down and then move your generals like chess pieces. I'm not implementing any real time battles at this point, it's just something really simple, like a board game. Could anyone please help me? I'll try to explain it a bit better: I need to create a map of the Mediterranean basin that would cover all the land occupied by the Romans at the height of their empire. Next, I'll divide the map into 20 provinces (Italy, Gaul, Germania, etc), each one producing a set ammount of resources and population. I also want them to have their own wheather and buildings (for example, you can only train soldiers in provinces that have a barracks). I guess I'll need a text box popup that appears when you click on a province to display it's information. I'll also need some buttons to open dropdown menus or perhaps whole windows, for other purposes such as diplomacy, statistics, tech trees, etc. I wanted the map to be in 3d because I think it would be much more interesting to look at it in perspective instead of flatten 2d. I'm fairly new into Unity so I really admit that I have no idea where to start. Please, have patience with my ignorance. Thank you very much for all your help. If there are any doubts about my question, please let me know and I'll try to explain it better. PS: I think I'll make it a turn based game since I think this would make it simpler to code and faster to run.
For your map, you could create a world comprised of continents and provinces. Reddit’s Worldbuilding subreddit (filtered to Maps) has some great examples, tips and tricks on creating worlds.
I moved these apart in Photoshop, making it easier to create a texture atlas, disabled the background, saved it as a
.png file, and imported it into Unity as a
Sprite Mode set to
Multiple. Finally, I created an empty
GameObject called World, containing each of the continents, and a cube object behind them which fills the camera’s view, acting as a surrogate ocean.
2D / 3D view of the result:
As you can see in the 3D perspective, the map is separated by four continents. My experience with Unity is limited, but this could be a good place to start, or give you an idea of what to do. I also suggest checking out Unity’s official tutorials, their online forum and their answers site, if you want to learn more about the platform and how to use it.
Just as it has been said in the comments, it is not clear if you are asking both how to design/create the assets that will represent the provinces, or just how to connect the assets representing provinces within your C# code. My guess is that you are looking for the later.
So, first of all, you don’t need to have one rectangle for the map and then subdivide it into the countries and then provinces. You could have a separate GameObject asset for each province. Then, a simple approach would be to give a proper name for each asset of each province, then to create in C# a custom class with a Dictionary that holds data for each province (the same can be achieved with a List if you prefer it over Dictionaries).
Then, each entry in such Dictionary would be a province with the Key being province name, and when you reference any given one (e.g. using the name of the province object that was hit by a mouse click), you could access its other info stored at that Dictionary entry. For example, for each enter in the Dictionary you could have a field for the number of units garrisoned there, another for the resources, another for weather, another with the color name of the owner, or even a sub-list within the Dictionary, containing the names of the neighbor-provinces of that province.
I was working on a very similar (but more complicated) project. The basic idea is to create a colormap and a 2D sprite and perform a per-province palette-swap in the sprite’s fragment shader based on the province’s RGB value.
Conceptually, you’d keep two textures, a colormap texture, and a lookup texture. The colormap could be whatever size you want, but the lookup texture has to be of size 4096*4096. The details are contained in the accepted answer to my earlier question on the topic.
This is a very graphically cheap way to do this, though it can be pretty computationally expensive to repeatedly update a large texture.
This also allows you the option of easily projecting your texture over a 3D terrain if you ever want to go that route (for example, if you ever want a map like the one in Risk 2, Europa Universalis, or Crusader Kings 2).
Another way to do it is to read through a colormap like the one in my linked question, and create 1 2D sprite per province. This approach was taken by the (now-defunct) Of Bears and Eagles project (which is coded in Java), but it is worth noting that a heavily-mutated private fork of the project is being run by Reddit user Kalelovil, and is pseudo-regularly updated here (the project on Reddit hasn’t been very active, most of us who contribute do so over the project’s Slack group). The project was recoded in C# once Kalelovil took over (in order to work with Unity), so if you want further details on how to write the map parser, I’d suggest seeking out Kalelovil on Reddit (he is active on Slack, so I imagine he is also active on Reddit, but I haven’t checked).
I’d share my own code, but I use several classes and several files to generate my (now-obsolete) 2D maps, and honestly it would be extremely cumbersome to paste and format all that code (several hundred lines). This is pretty memory intensive, and it can be graphically intensive depending on the number of provinces you want to display, but it would be perfect for a game with only 20 or so provinces. You can use shaders to decrease granularity.
A third option would be to fork this Github project and use it to generate a 2D mesh for each province from a vector graphics file from path’s. The linked file only handles the MoveTo and LineTo commands, but it can be easily modified to support Horizontal and Vertical commands. Other, more complex commands (Bezier curves and arcs) are going to be harder to implement, but are still within the realm of possibility.
Finally, as a last resort, if you don’t mind paying large sums of money, the Unity Asset developer, Kronnect, has an entire string of (admittedly expensive, but extremely well-maintained and well-supported) assets that would definitely cover any and all map needs you might have. I personally own a copy of their World Political Map 2D Edition and their World Map Strategy Kit, and they both run like a charm. All the bottlenecks I have encountered (aside from the occasional bug which is usually fixed in a Beta within hours to a day of my report) have been in my code.
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport