How to Develop an RTS Game – Quick Guide

Website design By BotEap.comRed Alert 2 (Westwood Studios) and Age of Empires 2 (Microsoft) were two games that defined the computer age by getting used to the GUI (mid/late 90’s).

Website design By BotEap.comOriginally designed for DOS, Red Alert was developed by Westwood Studios, a pioneer of RTS through titles including Dune. The game was a breakthrough due to its real-time nature.

Website design By BotEap.comAdd to that a killer story, jaw-dropping graphics, and almost mythical gameplay mechanics and you have a winner. As a software developer, it’s easy to be amazed by games like this… but it’s another thing to know how they work. This tutorial is a brief introduction to what I know about it.

Website design By BotEap.comOOP (Object Oriented Programming)

Website design By BotEap.comThe most important thing to appreciate with any game is that they are programmed using OOP principles. OOP stands for object-oriented programming, and basically the opposite of stream-based programming:

  • Website design By BotEap.comStream-based programs work with the flow of an application They will focus on user input and manage their system based on forms, typically updating the UI whenever input is provided.
  • Website design By BotEap.comObject-oriented programs work by loading a base application and using it to load a series of variables (objects). These variables are kept in memory and can be interacted with on the screen in real time.
Website design By BotEap.comThe core of OOP is the ability to “call” classes. Classes are a type of variable that allow you to store “attributes” and use those attributes in “public” (class) and “private” (instance) methods.

Website design By BotEap.comThe way almost all games work is to invoke a number of data objects in memory, fill them in with the appropriate attributes (hit points, etc.) and then proceed to call the various instance/class methods on them to as the user interacts with them in the game. .

Website design By BotEap.comData + Processor

Website design By BotEap.comIn addition to a core OOP architecture, RTS games are powered by two elements: a data backend and a “renderer” front-end. Understanding how they work together is at the core of whether you’ll understand how to make an RTS game work from a programmatic perspective.

Website design By BotEap.comImagine an RTS as a simple application. Ignore graphics and illustrations etc. Focus on how you would make the objects move on the screen.

Website design By BotEap.comIt works like this: the application is loaded. This gives you the ability to manage your credentials (load previous games, change your details, etc.). The application’s job (in an RTS) is then to create new “games”. These games exist between two or more players and act like a giant chessboard where you can add new buildings, units, etc.

Website design By BotEap.comEach “game” loads two sets of data (your information and that of the other player). The game’s job is to help you manipulate this data to defeat your enemy.

Website design By BotEap.comData (Buildings / Units / etc.)

Website design By BotEap.comWhen a new “game” is loaded, data for you and your enemies is loaded into memory. For example, you might have a dataset that looks like this:

Website design By BotEap.comEach number above corresponds to an ID for a data object. In relational databases, the ID will act as a foreign key.

Website design By BotEap.comThe way you manage these objects is to have a central data store (for example, a relational database) that stores the buildings as specific objects on their own.

Website design By BotEap.comThis way, when you create a new building, what you are doing is creating a new reference in the database. For Rails, you would have the following setup:

Website design By BotEap.comThe way you would set up the game is as follows:

Website design By BotEap.comThe way this would work is to load a “blank” dataset when the game loads.

Website design By BotEap.comFrom here the user can build various lower level buildings/units with the resources they can gather. Every time the user “creates” a new building, he is creating a new data object that is added to his set of buildings/units.

Website design By BotEap.comPlease note that this dataset has nothing to do with how the game looks.

Website design By BotEap.comPart of what makes RTS games so compelling is the perfect bridge between data and renderer. Imagine the data as a pure list of numbers etc. There is NOTHING visual about it.

Website design By BotEap.comIn fact, if you were to run a “console” view of the game, you would basically see two sets of data, the attributes of which (hit points, position, etc.) would be constantly changed by the game engine.

Website design By BotEap.comrenderer

Website design By BotEap.comThis is where the magic happens, and of course it’s the trickiest aspect of the game itself. I don’t have anywhere near the level of experience with this that I have with raw data.

Website design By BotEap.comThe renderer is typically what throws most potential developers.

Website design By BotEap.comThe way it works is very simple.

Website design By BotEap.comFirst, when a new “game” is loaded, a “chessboard” is created on which the data objects are placed. This chessboard is obviously the map.

Website design By BotEap.comThe map has constraints (dimensions) that give the app the ability to “draw” a grid. This grid allows you to use a series of coordinates to “position” new buildings (objects).

Website design By BotEap.comWhile the dataset doesn’t care about the positions, the renderer does. This means that if you wanted to build a new building on a place that is already occupied by someone else, you won’t be able to do so.

Website design By BotEap.comThe way I would handle this is to send the coordinates in a new build request to the server. The coordinates will allow the server to manage if the user can build a new building. If the answer is positive, the engine will show the construction of the building. If not, it will not allow the building to be built.

Website design By BotEap.comThe biggest factor with the renderer lies in the “AI”.

Website design By BotEap.comThis is the real magic of the game. When you move a unit from position A to position B, how does it interact with other game elements, for example?

Website design By BotEap.comProgramming Languages ​​/ Architecture

Website design By BotEap.comHow you design an RTS depends entirely on the medium in which it will be delivered. In the past, you only had to create a desktop application.

Website design By BotEap.comToday, you have to consider the web, mobile and desktop. As such, the overall gaming landscape has changed to be a more inclusive experience.

Website design By BotEap.comMore importantly, we’ve seen the game mechanics move to the server. This means that whether you play a game in your browser, on your desktop, or via mobile, all you are doing is sending requests to the server and the server will respond with updates to the renderer.

Website design By BotEap.comNo part of the physics, game data, or building mechanics are kept in the client-side application.

Leave a Reply

Your email address will not be published. Required fields are marked *