📜 ⬆️ ⬇️

How to start writing games

Original: Starting out on Game Programming

The path to the gaming industry is not close. This article is designed to help you understand where to start this journey.

You have just completed your first C ++ course and want to start making games. Someone pointed you to this site and you may have experimented a bit with the manual . You studied several concise examples, but you did not find a guide on how to make the whole game. And for good reason.
')
Manuals are good for learning something step by step, such as how to move a point image around the screen. In order to put the game together, you need the skills of solving problems that arise, acquired only with experience. This is not something that can be learned from manuals. The best way to learn how to make games is to start making them.



Project selection


So where do you start? It is easier to answer where to start, namely from large projects, such as a full-fledged 3D FPS, MMO, or even a long 16-bit platformer. The most common mistake of novice developers is to start with a big project based on Cool Idea or take a project that seems simple and end up with a half-finished bunch of spaghetti code. At first, you should create small projects.

In early projects, your main goal is to learn, not to implement Cool Ideas. By keeping the project small, you can focus on learning new techniques, and not spend a lot of time managing code and refactoring. Despite the fact that your cool idea can be awesome awesome, the reality of the development industry is such that the larger the project, the more likely to make a mistake in architecture. And the larger the project, the more expensive this error. Remember the story of Daedalus and his son Icarus? Daedalus created wings of wax and feathers for his son. He warned Icarus not to fly too close to the sun. But Ikar ignored the warning and the wings melted, and that was when gravity overtook him.

So remember: do not fly too close to the sun on your new programmer wings.

Taking into account all the above written, here are a couple of tips to get you started.


Graphics and Event Processing


If you have never programmed anything related to graphics or GUI, you should start with something small to “wet your feet”. My first project was tic-tac-toe, so even I had a modest start. A couple of ideas for the first project:


The goal of your first project is to move from console development to development of event graphics applications. He will also teach you the fundamentals of game logic and architecture. I recommend something step by step, because motion games are a completely different beast.

Try to keep the project simple so that you can complete it and not lose interest halfway through without ever ending the game. It is important to bring the game to the end, because you do not learn the development process if you have several unfinished games on your hard disk.

There is one point that I want to indicate to those who will do tic-tac-toe or four in a row. Do not worry much now about artificial intelligence. Make the game only for two players or for playing with a computer that makes random moves is enough to start.

If you have dealt with graphics and event processing before and feel comfortable in this area, you can proceed directly to the next step.


Synchronization, movement, collisions, animation


Now that you have played enough with graphics, it's time to do something in real time. Here are a couple of suggestions:


Here you will learn about the movement, time, animation, collision detection, game cycle, calculating points, wins and losses and other important basic concepts used in each game.

Duck Hunt and Pong are good projects for those who already have experience in programming graphics and events. They have a simple collision detection and all the important basics of games in real time.

Space Invaders and Galaga is a good choice for a second / third project. They have levels, so you will need to find out how to move from level to level, using the state machine. You can read about the state machines here (English) . Games in the style of "shoot them all" also require you to create simple behavioral patterns for enemies, which is a step towards artificial intelligence.

Tetris is good for the second / third project. It has quite a bit of logic needed to create a puzzle game. This is a decent-sized game, so you will have to learn how to split your program into several source files, which you can read more about here . Do not underestimate Tetris. I underestimated and just look at this terrible mess in the code Lazy Blocks.


Reengineering


A typical beginner's mistake is an attempt to make the Best Game of All Times, ending with a reengineering. That is, when he tries to write the best game / engine and this all ends with the use of only a small part of what has been written.

When I was a beginner, I reengineered AI for daggers and crosses. I wanted to make a game with an unbeatable AI. I managed to achieve this by programming the computer to know all the possible pitfalls. Sounds cool doesn't it? It took almost 40,000 thousand lines of mostly copied code and a month of my free time.
Later, I learned data structures and learned about the Minimax algorithm, which, with a smaller code size, not only did the right thing, but also did it better.

So learn from my mistakes and don't be overly ambitious. Concentrate on learning how to make games, not just doing them.


Planning, collision analysis, physics, levels, artificial intelligence






Now that you have two or three small games behind you, it's time to make your first big project.

Until now, you’ve probably programmed as necessary. This will end at this stage. In the real world, most development processes are completed before the first line of code is written. Nothing can be worse than the realization that in order to add to your game what you want, you will have to throw out all the written code, because you have not planned everything in advance. Now that you have experience creating games, you know what the development process is. Now you can plan games before you start them.

Now about your next game. Break Out and Puzzle Bobble are good for the third project, because they include advanced collision recognition and physics. Physics is important because it gives the game a realistic feel. Even in Super Mario Brothers, there is a sense of gravity and inertia. Billiards is an excellent project for those who want to strain gyrus with physics.

In games such as billiards, you need not only to detect collisions, but also to process them in a certain order. Collision handling is very different from their detection. Although creating a billiard or 2D platformer may seem simple, collision analysis in the correct order is a confusing process and should not be underestimated.

Break out and Puzzle Bobble also include level design and require download and release of their resources. A good experience would be to create a level editor for the game. Editors allow you to easily create levels and do not force them into the app. I have an article (eng.) About creating a level editor.

You may also want to practice writing artificial intelligence (AI). One of the options is to return to the noughts or four in a row and write an invincible AI. Now you should already know the data structures and be able to use tree knowledge to use the Minimax algorithm. With this algorithm, you can calculate all possible outcomes of daggers and create an invincible AI. It's funny to upset your friends with them. You may also want to make different levels of difficulty. The game does not bring joy, if it can not be won.

Pac Man is a great way to practice writing AI. You will need to know the structures of the trees / graphs and the search algorithms, such as A *, in order for ghosts to get through the maze. You will also need to make the ghosts work as a team. All this is useful when you make games with complex AI, such as real-time strategies. You can read about the basics of AI here .


Platforms, Action / Adventure, RPG, RTS, engines






Now that you have gained the experience of creating a well-planned game, you are ready to create an Action / Adventure / Platformer. It will be the culmination of graphics, motion, animation, collision analysis / detection, physics, AI, software architecture, and everything else that you’ll learn by now. Those who are more ambitious, you can offer to make a real-time strategy (RTS) or role-playing game (RPG). Be careful because RPG and RTS are really huge projects.

RPGs have a complex architecture and require a lot of planning. You will need to plan each weapon, armor, accessory, attack, item, spell, summon, enemy, map, boss, dungeon, etc. to the smallest details. This all should work smoothly, and, to put it mildly, this is not an easy task. So if your design project looks like a script or comic, you will need to do a lot more work.

RTS is also complex architecturally, and also requires a lot of AI. You will need to do a search for the path for the units, they receive teams, different behavior depending on the commands received. If you have never done AI before, it would be better to start with Pac Man's clone for a start.

Probably for the first time you will have to make an engine for your game. What should be avoided is the creation of a universal engine. Creating the engine do not try to make it suitable for any game. If your game requires x, y and z, make an engine that can x, y and z. The engines are created on the basis of what is needed for a particular game, and not from the fact that any game can potentially be needed.

Another common mistake among newbies is an attempt to create an engine as a first project. And usually this is a universal engine. You don't need a fantastic graphics engine to create Pong or Space Invaders. When programming, it’s easy to dig into details. Concentrate on the big picture and complete your games.


Network


Everyone seems to want to do the next big MMO. Creating online games is not something you can quickly grasp. I realized this when I tried to do online poker immediately after completing the tic-tac-toe.

Adding a network greatly complicates the game. When one player does something, you must send information about it to everyone else. It’s like if your right hand didn’t know what the left hand was doing. You also have to choose between loading the server and what it can control. The more server-side does, the less opportunities to cheat at the client, but it also means a greater load on the server. For action and other high-speed gameplay games, you will have to worry about network latency and packet loss.

You should complete at least one well-planned game before attempting to make an online game. As the first network project, try to do something that is not critical to speed. For example, a simple chat server / client would be good practice. You can also go back to the four-line / four-in-a-row crosses and add to them the ability to play online. As an option, try to make a network card or board game.

After your first network project is ready, try doing something in real time. In your first network application, you probably used TCP to make sure that the data you are receiving arrive in the order in which you sent it. For games where there is a lot of action, TCP delays are likely to be too great, so you have to use UDP. UDP does not guarantee the order of delivery as the delivery itself. Since UDP does not do additional integrity checks it is faster. You will have to sacrifice the ease of using TCP, in exchange for UDP speed and the need for self-checking of data integrity when creating a game.


3D games


Before you make 3D games, you should make at least one well-planned game and have a good understanding of three-dimensional vector mathematics, linear and Newtonian physics. Here you have to deal with vertices, textures, lighting, shadows, the definition of interaction with objects in three-dimensional space, loading models and other difficult-sounding things.

The good news is that if you’ve already done 4 or 5 games, you already know the basics for creating a game. You are already familiar with the development process and know your capabilities as a programmer. No matter the three-dimensional shooter or two-dimensional, it is still a shooter. 2D RPG or 3D RPG is still RPG.

Do not consider this an excuse to skip 2D and go straight to 3D. Before you learn to run, you need to learn how to walk.


Quick way


Say that you learn faster if you immediately get down to business and just write your 3D MMOFPSRTSRPG and learn what you need as needed? Well, here are a couple of tips to help you:
  1. Go to the local market
  2. Buy a whole fish. I recommend taking salmon or cod, although catfish will also work. Trout, by the way, is also quite effective.
  3. Go home and turn on the computer
  4. Launch your favorite IDE
  5. Now take the purchased fish and wipe yourself on the head
  6. Repeat point 5 until the thought of a fast way leaves you.

You will not learn algebra solving computational problems. You learn the basics and rely on them. The same with programming. If you are looking for a quick way, I'm here to tell you that it is not there. Do not rush yourself. Once again: learn the basics and rely on them. Otherwise you will face a fiasco.


The journey begins


Now that you have a general understanding of what to do, it's time to start playing igrodelom. I do not expect you to follow this guide word for word. Everyone learns in different ways and at different speeds. If you had to get something out of this article, there are three things:
  1. Choose your pace
  2. Finish the game to the end
  3. Focus on learning, not just creating

Good luck on your game development path!

Source: https://habr.com/ru/post/160547/


All Articles