2D game development basics

I would like to write some simple marie-like game from scratch using the C language. But to be honest, I have no idea how to do this, and I cannot find a good tutorial for this, which is provided for free.

But for this question, I only wrote WinAPI programs so far, so all event processing and user input were performed by the OS with minimal work. But for developing a game, for example, a menu with non-rectangular buttons, animation, and so, I think, in WinAPI there is no such thing that could help me with this, and not just in some basic functions of the mouse pointer and keystrokes.

So, is this the right way to write your game, to write the whole part of the game engine ’draw by manipulating objects for the player, enemies and even the background yourself, and not just use directdraw to display on the screen?

EDIT: I really want to learn how to write games from scratch, because it must be a great programming experience, and if you are considering games like Commander Keen on DOS, created without a framework or libraries, but still so wonderful.

+4
source share
10 answers

A good approach to this would be to take a look at the SDL library. I'm not saying that this is the best library for 2D games, but it's easy to get started with, and online tutorials and examples have been flooded for simple 2D home-brewed games written using SDL.

+9
source

I also recommend SDL, but you definitely need to take a look at lazyfoo , which is just great.

+4
source

I also used SDL, but try to look at HGE . It requires at least DirectX 8.0, so your applications will only work on Windows, but on their forum you will find many topics on how to port it to OpenGL. In my opinion, HGE will be easier to learn than SDL, because SDL is a low-level library, and you will have to learn how to deal with many things yourself. HGE is more ready to run just out of the box.

+2
source

When I started programming, I started doing it with Allegro, back in the good old days of DOS. This was the first useful library that worked with SVGA libraries and had good sprite support. Then version 3 appeared, and they added support for windows (using GDI and Directy X, you can choose at runtime which engine to use). Linux port came to life, and everything is fine.

This is a very simple 2D library, and it will teach you the basics of graphics and animation. Now it even contains sound support, which is a very necessary addition (well, I still remember V 2.9X ...). They are in beta for version 5, and I think this is an interesting project for you.

http://www.talula.demon.co.uk/allegro/

+2
source

What are you guys talking about, WinAPI has low-level drawing procedures.

Although using an installed library such as SDL is probably the best idea, you could easily create your own abstractions for WinAPI drawing routines.

Then it is just a matter of creating a while loop that has all the drawing instructions and interprets the input. For 2D games, this is not too difficult.

+1
source

In short, yes - there is nothing in WinAPI that will help you a lot. However, there are dozens of game engines that you could build in your game, and that would require a huge amount of effort to create the game itself. A little bit about googling will help you.

(Personal recommendations: although this is technically a 3D engine, something like Unity is a great engine that includes tutorials for creating 2D games. Unity is not C, but it makes your life a lot easier ...)

0
source

EDIT: I really want to learn how to write games from scratch, because it must be a great programming experience, and if you are considering games like Commander Keen on DOS, created without a framework or libraries, but still so wonderful.

This is not entirely correct. Commander Keen (and any DOS games) use libraries: those provided by DOS, BIOS, etc. Without libraries of one form or another, you cannot use anything with C. For game programming, you really do want to leave all the low-level details to someone else.

I would recommend Allegro as an initial game programming library.

0
source

Give It Up Starter Game

They have a really large resource related to game programming and many newcomers. SDL is good, but you should consider learning basic game techniques before you start coding and even before you think about the api / libs you are using.

Make it clear how much “intelligence” you need (Ki), think about loading / saving early time ... there are so many things you should keep in mind if you want to complete your project. Do you need a game editor? (Also..work) How about sound / graphics? Writing all this material at your own discretion will take a lot of time (if you have no experience). Content creation is another important issue that can be time consuming if you do so at all.

Perhaps this will help you take a look at some of the little girls, because it will give you an idea of ​​how their engine works. Like this (outdated) Dev kid

0
source

I just started a similar project a few days ago, you can check it out on GitHub .
He should give you some ideas on how the game works. Like some details of a scrolling 2D map with a collision (which turns out to be quite complicated if you want to get a 100% error). Oh, and he uses SDL, as many of them have already suggested.

As for me, this is my first C project. But I have to admit that I used to do similar things in Java and Python, so it was a good way to quickly learn C. And since it is learning, not some productive material, I use a simple C99, which makes the task even “funnier”.

But back to the game, you really need to think about your design before you start coding, write it on a piece of paper or, if you look like me, and you are not a tree in which you can write it in pseudocode.

Think about as many possible game states as possible, nothing worse than reinstalling the entire player / card / everything from scratch, just because you had not thought about the XYZ function before.

Design is very important if you do not have a goal to start, your project will reach the point where it fails, like my Tuff , it also failed due to the lack of music and someone who would develop enemies, etc.

Speaking of graphics, etc., keep in mind that a game will consist of much more than just simple code. If you are not good at graphics, then consider this when designing. Because you quickly lose your motivation when the only things on the screen are colored rectangles.

0
source

The Action Arcade Adventure Set (originally published as a book) is probably one of the most comprehensive guides to writing a 2D scrolling game. Although an older link, many of the basics for developing a 2D scroller have not changed.

Examples of complete source code and some tools for developing a side scroller are provided as downloads . For processing graphic primitives, only one external library is used. Since this is an older DOS program, you may have to use a DOS emulator like DOSBox or change the examples for more modern environments.

I suggest you go to chapters 1 through 9 and focus on chapters 10 through 17.

0
source

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


All Articles