Q: I’ve been wanting to do a military strategy game. I learned C++ in high school. I made a few text-based games, but nothing major. Any starter tips?
A: If we were to make a demo or proof-of-concept version of the military strategy game that you have in mind – i.e. pretty much the bare minimum of functionality and assets to demonstrate what it does and how it goes it – what would be involved? For starters, that should be the target, rather than a full game. If the core functionality of a “demo” works (1 level, a couple of enemy types, basic winning and losing), then you can use that as a foundation to build the rest of the game; if that proves out of reach, then you’ll figure that out far sooner, and be able to adjust plans or switch projects before getting in too deep.
As one possible starting outline, in whichever language/API/environment you choose to do it in (Unity for cross platform, C++ with Allegro or SDL for high performance downloadable, AS3 for web, etc.)…
- Get the mouse showing up, either as a default cursor or by drawing a small circle where the mouse coordinates are. Create two numbers, x and y, to store a soldier’s position, and draw a colored rectangle on screen at that coordinate representing the soldier. Before moving on, set it up so that clicking close enough to the soldier kills him – this can be as simple as a distance check between mouse cursor and the army man each time the mouse clicks, setting a “dead” boolean flag to true which draws him a different color. The distance check to the solider should be written as a separate function that uses pythagorean theorem to return a distance for numbers/coordinates given as parameters. (If going the Unity route some translation may be appropriate, ex. rectangular prisms instead of squares, and checking raycast collision against a bounding box a bit larger than the unit rather than doing distance checks to detect click proximity.)
- Create a game loop so that action can happen 20-60 times per second, rather than only when the mouse clicks. If programming in a local native application or prototyping environment this can be done by making a bool “gameRunning” set to true, and wrapping the core of the game (drawing, input handling) in a while(gameRunning) loop. If the user either presses a key (Escape perhaps) or clicks in the top-right corner of the screen (coordinate comparisons), set gameRunning to false to quit the program. If in a newer environment this is often done instead of using a loop by setting up a timer to call a main logic and rendering function 20-60 times per second, which is where your game code can live. In Unity this is set up automatically in the form of the Update() tick functions built in to the scripting.
- Have the soldier keep track of a target destination by creating two new numbers, tx and ty (standing for target x and target y). Update the…
… (continued in ebook)
*This entry is now in the Videogame Developer’s Strategy Guide, free with Gamkedo Weekly Check-In.
Learn and practice team game development with Gamkedo Club.
Membership worldwide. Professional support. Proven process.
Subscribe by e-mail to receive weekly updates with Gamkedo.Community interviews and YouTube training videos for game developers!