c tutorials | Learn C Games Programming Blog (2024)

Tutorials

These are various game related tutorials in C, C++ and C#.

C Programming Tutorials

(Originally published on the now defunct on cplus.About.com)

This is a very rough guide to a learning C syllabus. It’s tailored to be practical and details steps, many of which correspond to C tutorials. I’ve also linked to the relevant tutorials and this provides a guide. If you are going to follow this you should work your way through the tutorials in order. As more tutorials are added, I’ll add the links in to the relevant bits which are shown in bold as place holders.

  • A quick overview. A look at computers, machine code, assembly language, editing, compilers, compiling and debugging.
  • How to install VS Code and Clang on Ubuntu and Raspberry Pi. Note you can also install VS Code on Windows. Many examples use the ideoone.com website. This is an online C compiler so you can use that to run code instead of compiling it.
  • Introduction to Hello World. The shortest easiest program of them all. Explains the different parts of a C program.
  • Introduction to variables. Explains how to hold data in memory. Mostly numbers but can also include text strings. It also explains how to declare variables. The different data types (int, float, char).
  • A look at enum variables. These are int variables where each value 0,1, etc represents something say like a colour.
  • A look at array variables. This is a collection of variables of the same type that are accessed by an index.
  • A look at struct variables. How to group different types of variables together. Variables can be different types but can also include arrays. You can have struct which includes arrays of structs as well as other types up to the limits of the compiler.
  • A look at functions. Functions are blocks of code that can be called. You can pass values in and get values back. They are an important part of C.
  • Simple control flow. (Not due till 23rd Dec) Use {} to build blocks of code and if or switch statements to control what happens.
  • Looping in C. C offers four ways to loops in this order of importance: For loops, while loops, do-while loops and the Goto statement,
  • All about operators in C. You can manipulate data in C using a variety of operators and control program flow.

At this point you have the simple fundamentals of C programming but still have to learn pointers, text strings and of course SDL.

  • A look at pointers. This is actually a simple concept once you get it. A pointer variable just holds the address of something. The complexity is understanding that the compiler needs to know how big that something is. People who have done assembly language programming usually have an easier time of it.
  • Pointers and c-strings. A string in C is actually a pointer to a block of characters terminated by a 0. There are a few gotchas though.
  • Pointers and linked lists. Other programming languages tend to have a bunch of advanced data structures like Queues and stacks. In C you often have to roll your own using pointers. A linked list is a structure made using pointers and usually structs.
  • Working with strings. Although I looked at them in the pointers and c-strings tutorial, this is a more in-depth look at working with them.
  • Allocating memory dynamically. Use of malloc/free.
  • What are function pointers? As well as pointers to data, you can have pointers to code, in particular pointers to functions. But the syntax is probably the most horrible part of C.
  • What are C compiler directives? Like #define and #include as well as others. Learn all about them.
  • How do I structure my C program? While you can have your program in one file, it often makes sense and shorter compile times to split it into multiple files. This needs careful attention as some bits can be included while others need to be declared as extern.

That’s mostly the C bit done but now comes the SDL library code. This is a media library that lets you use graphics and audio files in your program as well as exotic devices like joysticks and game pads. Most importantly it lets you write programs that can run at 60 frames per second or higher which is perfect for games.

  • How do I install SDL on Linux? It’s different between Windows and other platforms.
  • How to install SDL2 in Visual Studio.This of course is on Windows.
  • Getting started with SDL. Here’s a typical Hello World but in graphics. It explains some simple concepts like double buffering which is how your graphics are kept flicker free and smooth looking.
  • All about blitting. So you have a nice set of graphics? How do you get them in to your program and “blit” them quickly onto the screen.
  • How I play sound with SDL? How do you load audio files in and what are the different formats it can play?
  • How do I read keys or handle mouse moves in SDL? It’s not that difficult.

The last bit is about games development.

How do I structure a game in C with SDL? This explains the concept of a game loop and making things to do to make a game that runs smoothly at 60 frames per second.

Simple Game Tutorials

Atoms

c tutorials | Learn C Games Programming Blog (1)

  • Atoms aka Chain Reaction. A simple console game to introduce you to C programming.
  • Atoms. Tutorial one. Displaying the board, accepting player input.
  • Atoms Tutorial two. Doing computer moves
  • Atoms Tutorials three. Finishing off.

Onslaught (aka Slay for Linux) Tutorials

  • Tutorial one. How to implement Slay for Linux. Aka Onslaught.
  • Tutorial two. How to draw Map hexagons. Plus code to draw a bunch of hexagons on Linux.
  • Tutorial Three. Devise and code up a map generator.
  • Tutorial Four, Adding forts, trees and wild hexes.

c tutorials | Learn C Games Programming Blog (2)

(Visited 10,042 times, 1 visits today)

c tutorials | Learn C Games Programming Blog (2024)
Top Articles
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 5836

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.