Skip to content Skip to sidebar Skip to footer

how to draw a 3d hex map

HexagonalTileMap

Author'due south Notes:
This article is written for experienced developers using the C# language and the Monogame Framework. Monogame is in active evolution with a new release just published recently. This slice is highly technical and requires that developers be proficient in their chosen linguistic communication of pick. Therefore there is no information that will enable new programmers to work with the sample code easily.
The title prefix, "Part I", indicates an expectation that as this project progresses into a war game I hope to develop over fourth dimension that simulates a major conflict of the 18th century, it is hoped that as new lawmaking is developed additional articles will be published with the intent of guiding developers in such a difficult form of game evolution.
Because this piece is published on both Microsoft and Coffee Community sites, there is data in this piece that should go far easier for Java developers to develop similar code for their ain projects.  Yet, the Java information is express since such a piece cannot provide lawmaking and explanations for both languages every bit the libraries used are completely different from each other
It should also be noted that there is code in the provided project that is no longer currently used but was left every bit reminders for farther development every bit the project progresses.  Such code is noted in this piece.
Due to the length of this slice, a downloadable Word document is available at the post-obit link…
https://1drv.ms/w/southward!AnW5gyh0E3V-g12SlguqkHrRVyq8
 The complete project for this newspaper tin be downloaded from the following link…
https://1drv.ms/u/s!AnW5gyh0E3V-g1uRrePYv0XEquRq
 To submit questions to the writer regarding the provided information, delight email the author at…
support@blackfalconsoftware.com

Overview

One of the most hard aspects of developing a game is one in which the genre yous would like to develop for is such a niche surface area of development that standardized tools accept still to be created for it.  With the popularity of 3D graphic art and gaming the 2D attribute of this creative endeavor hasn't kept pace with electric current technologies to the aforementioned degree.  For 3D game development there are several popular genres that have a broad caste of support; starting time-person-shooters, simulations (ie: racing, flying), adventure games, and strategic simulations, which are in many cases merely war games on steroids without the thought provoking challenges that a plow-based game of the same genre can provide.  For such evolution there are first-class tools freely available, the almost popular being "Unity", which also has a wide array of threerd political party back up in the form of add together-ons that provide tools for all the mentioned game types.

With second development, scrolling games accept been developed to the point that there are many excellent articles describing how to implement one with quite a bit of sample code along with a few very good toolsets to help a developer in his or efforts.

The one genre in 2D evolution that has gotten very little or rather uneven exposure in the development area is that of the original turn-based, hexagonal map, war game.  And beside the original fashion of gamble gaming whereby the "maze similar" foundations were quite thought provoking, war gaming itself has been considered the superlative of all such mental challenges and at once was even promoted for the "over educated".

Notwithstanding, with a lack of some level of standardized tools for such development, this realm of gaming has probably go one of the nearly difficult areas in creative activity within the game evolution field.  In that location are several reasons for this that has been described in a number of texts on the field of study.

For starters, the computer AI in such games is at a terrible disadvantage compared to the Human opponent since the Homo opponent can have as long as he or she likes to develop tactics and strategies that if done carefully over fourth dimension will non just defeat the figurer AI only yield weak spots in it that can aid the player in increasing their battlefield wins somewhat consistently.

In an article describing such a situation within the "Culture" series of games it was found in i case that players were able to defeat the AI in 1 significant area of lumber yields by repeating the creation of forests in a single hex, deforesting the hex through lumber production, so seeding a new woods to first the bike over again.  The AI in the game could not do this giving the Human player a meaning reward in such production, which in turn allowed the Human player to build wooden-based entities more chop-chop than the AI could.

Though Firaxis Games has openly admitted that their "Civilization" AI cheats (and pretty unfairly equally well), when they realized this weakness (chosen "lumberjacking") in their AI, they issued a patch placing the AI and the Human being opponent on equal footing in this part of the game, making "lumberjacking" no longer possible by the Human player.

The result of this drawback in turn-based war games is that the AI implemented in such games has to be quite good in order to brand the game not only enjoyable just repeatable besides.  Thus, turn-based state of war games require higher up average AI implementations that are more than than just what any pre-made tools can offer.

In addition, the AI implementation has to be suited for the level of state of war game being developed.  In such games in that location are 3 principal types of AI that can be used, strategic (big unit of measurement formations such as divisions), tactical (medium sized unit formations such as regiments), and squad based where each unit represents a single slice of equipment or a soldier.  And in each case the AI implementation, as mentioned, has to be done quite well.

This is not the same equally with RTS games (real time strategy) where the Human role player is at a disadvantage being that he or she must stay on their toes to exercise battle with an aggressive AI whereby studying the battlefield for any length of fourth dimension is not an option.  The result is that most such games are not very realistic in terms of technique since in reality, equally fast every bit information technology may occur, war would never be as fast as a computer emulation would propose unless it was designed to be such as with in-depth military training emulations.  The lightning fast movements for case in the "Battlefield" franchise could never occur since Humans cannot react at such speeds commonly.

The next area of difficulty in the evolution of turn-based war games are the graphics employed.  With the exception of some tile mapping tools that provide the ability to create maps using hexagonal tiles, the developer nonetheless has to use original programming to control the map and the units portrayed on information technology once it is loaded.  And since such maps can accept a diversity of sizes, no one code base of operations offered will necessarily be able to provide the mathematical calculations for the chosen sizes for any individual developer.  That being said, one of the near popular mapping tools is "Tiled" (http://www.mapeditor.org/), which will permit a developer to create large hexagonal maps through a visual interface.

"Tiled" creates maps using the "TMX" format, which is actually lawmaking that describes a map to a graphics arrangement.  Both "Monogame (with the Monogame.Extended plugin)" (http://world wide web.monogame.net/) for C# and VB.NET developers and "libGDX" (http://libgdx.badlogicgames.com) for Java developers support this file type allowing a developer to display his or her maps somewhat easier than if one were to exercise it on using merely the graphics engine and their tiled images.

This article then will depict one mode that a hexagonal map tin can be created and displayed at the lowest level; using the "Monogame" graphics engine only with individual tiled images.

For Java Developers But…

Being from the Microsoft side of the debate, I develop in either VB.NET or C# as I am fluent in both.  For such a discussion, this does the Coffee Customs little expert to but have my sample lawmaking as a base of operations-line for their ain efforts.  As a result, I accept done a bit of research for Java developers who want to use their linguistic communication for game development. Equally mentioned in my previous commodity, Java is not very high on the listing for apply in game development merely it is getting more tools to work with.

And so for starters, Java Developers who desire to endeavor their easily at war game development would desire to first become a concord of the Java graphics engine, "libGDX", which tin exist freely obtained at the link provided above.  You will also observe some very good books that can exist purchased either from the "libGDX" site or from Amazon.  And unlike on the "Monogame" side of things, Coffee developers have an reward in that that these books appear to be recent publications.  We "Monogame" developers still have to rely on XNA documentation but this will alter in time as "Monogame" continues to move away from this discontinued platform and becomes it'due south own standard as it has started to with information technology's latest release, which no longer relies on whatever XNA framework technologies simply is now providing straight support for "DirectX" and "OpenGL".

Now that yous have a good game engine y'all volition too demand to understand the differences between my C# code and what yous would exercise with Java.  An excellent article on the Microsoft'south Community spider web site, "The Code Project", provides a rather extensive side-by-side example of Coffee and C# code, which includes the gaming lawmaking as well.  It may non exist totally consummate just from the looks of this piece, it should provide you with a adept grounding to sympathize what I have done.  The article tin exist plant at the following link… http://world wide web.codeproject.com/Articles/754354/Port-a-D-libgdx-game-to-MonoGame

There is also a rather extensive ready of tutorials for using "libGDX" with Coffee at the "Games From Scratch" spider web site, which can be establish at this link…  http://world wide web.gamefromscratch.com/page/LibGDX-Tutorial-serial.aspx

C# and Java Developers… Let'southward begin

Please note that Monogame even so uses the Microsoft XNA namespaces for compatibility purposes with prior releases of this engine.  This is expected to change in a hereafter release.

When working at the lowest levels in game blueprint such as with the "libGDX" or "Monogame" engines or directly with either "DirectX" or "OpenGL", such infrastructures often provide for pre-divers "game loop" events and methods that you have no control over.  Thus to piece of work with these constructs successfully you accept to empathize them to curve them to your will.  Since the "game loop" processing runs in a continuous bicycle you accept to ensure that all of your own code falls in line properly with such requirements or cipher in your game project volition run correctly.  Note that the "libGDX" engine does not provide explicit "game loop" internals as "Monogame" does, though it provides for the same set of "game loop" events through an "Awarding Listener".  However, there are implied internals that a Java developer tin can take advantage of through his or her own coding.

To begin with then, after you take installed either "libGDX" or "Monogame" you first must create a new project.  With "libGDX", every bit far as I tin tell, y'all will be offered a dialog box with a number of options for you to initiate your project with.  Not existence a Java programmer I am taking this information from the "libGDX" site documentation, which demonstrates the use of a "libGDX" platform addition to exercise this called "Gradle".  See the "Gradle" interface below…

libgdx_project_setup

"Gradle" allows you to set up your projection for the platform you would like to build your game for.  In our case, we would want to select "Desktop".  By the way, "Gradle" will interface with the following popular Java development IDEs…

  • Eclipse
  • Intellij Idea and Android studio
  • NetBeans
  • Commandline

With "Monogame", nosotros just select the type of projection we want by selecting from the installed list of "Monogame" templates in Visual Studio every bit shown below.  As a note, those who are Visual Studio developers should ensure that they are using Visual Studio 2013/2015 on a 64bit machine…  The 64bit machine requirement will be explained later in this piece.

Monogame_VisualStudioTemplateSelections

In our case we would want to select the "Monogame Windows Project"…

One time yous initiate the creation of your projection, two things will be defined for you.  The get-go is the link to your framework's internal "game loop".  The "game loop" cycles through repetitively listening for actions that fire 1 of the events that are now defined in your primary game module.  It should be noted that "libGDX" does not have an explicit "game loop" since it is a purely event driven game engine.  Yet, it does have unsaid "game loop" mechanisms, which Java developers tin can take reward of.  This data is cited in the commodity at the link previously provided.

So in the case of Java and the "libGDX" engine, yous volition accept the post-obit events defined in your primary module…

Method Signature

Clarification
create()

Method called in one case when the awarding is created

resize() This method is chosen every time the game screen is re-sized and the game is not in the paused state; information technology is also called once just after the create() method
render() Method called past the game loop from the awarding every time rendering should be performed; game logic updates are usually besides performed in this method
pause() On Android this method is chosen when the Domicile push button is pressed or an incoming call is received; on desktop this is called just earlier dispose() when exiting the application; a good place to save the game land
resume() This method is only called on Android when the application resumes from a paused state
dispose()

Called when the application is destroyed; it is preceded by a call to pause()

For C# nosotros volition take the following similar events defined for us in our "Game.cs" module, a result of the "Monogame" project initialization…

Method Signature Description
Constructor() Initializes a default graphics device managing director instance; sets up the internal pointer for your internal content; you may also add any global initializations in this method you may require
Initialize() Allows the game to perform any initialization it needs to earlier starting to run; this is where information technology tin query for any required services and load any non-graphic related content; calling base.Initialize volition enumerate through any components and initialize them as well
LoadContent() Will exist chosen once per game and is the place to load all of your content from the "pipeline"
UnloadContent() Will exist called one time per game and is the identify to unload game-specific content that is no longer required (this method does not announced to exist used oft)
Update() Allows the game to run logic such as updating the earth, checking for collisions, gathering input, and playing audio
Depict() Called when the game should draw\redraw itself (ie: subsequently user input)

To see the exact correlations betwixt the sets of events\methods between the Coffee and C# languages see the department titled, "Game Loop" in the cited "Code Project" article.

Creating Your Form Level Declarations for the Primary Game Module

Whether I write in VB.Internet or C#, I ever compartmentalize my module code into specific areas in the certificate.  In Visual Studio these are referred to as "Regions", which tin can be expanded or complanate by the developer for legibility.  "Regions" merely provide annotate headers to each expanse and can be nested inside each other likewise.  "Regions" allow for the immediate recognition of the types of code contained in each.  There is no equivalent in Coffee per-se since such a feature is based upon the IDE that a Java developer uses.  Thus the posting at the post-obit link can assist Java developers in incorporating them into their specific IDE if they accept not already done so… http://stackoverflow.com/questions/2344524/java-equivalent-to-region-in-c-abrupt

Equally to my own class level declarations for the principal game module, I accept defined the post-obit assignments…

#region Class Level Declarations      // Microsoft.Xna.Framework.Graphics.GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Tiptop;     // Microsoft.Xna.Framework.Graphics.GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;      private int        ciScreenHeight = 600;     individual int        ciScreenWidth = 800;      private int        ciRowPosition = 0;     individual int        ciColumnPosition = 0;      private string     csScrollDirection = "";  // R,L,U,D      private MGWorkBench_ScrollingHexMap.Classes.TileMap          coTileMap;     private MGWorkBench_ScrollingHexMap.Structures.HexTexture2D  coHexTexture2D;     private Microsoft.Xna.Framework.Input.KeyboardState          coKeyboardState;     private Microsoft.Xna.Framework.Graphics.Texture2D           coTexture2DTile;     individual Microsoft.Xna.Framework.Graphics.SpriteBatch         coSpriteBatch;     private Microsoft.Xna.Framework.Graphics.SpriteFont          coSpriteFont;     private Microsoft.Xna.Framework.GraphicsDeviceManager        coGraphicsDeviceManager;  

Post a Comment for "how to draw a 3d hex map"