Website for David Bolton, software developer in Lincolnshire, England

Learn C Games Programming for Beginners on Windows

Learn C - book cover

50 Chapters

This is an ebook, I've been working on for some time. It's approximately 200 pages (55,000 words) with lots of diagrams, pictures and short source code listing. All source code from the book is on Github and I'll post the link when the book is complete, around December 2018.

The first 20 chapters introduce you to programming in C with 30 example programs. This includes showing you how to install Visual Studio and compile and run programs.

Subjects taught include a large chunk of C including variables, loops, structs, arrays, chars, functions and pointers. You'll learn about typedef and pick up a few tips on programming and debugging along the way. And there's lots more.

Chapters 21-50 - Programming an arcade game

This is about developing a full blown asteroids game, with asteroids, player ships, bullets etc. usingthe SDL2 library to get 60 frames per second action using what you learned in the first 20 chapters.

It builds up with new code added in each of 13 chapters, culminating in a full game around 2,200 lines of C. This includes a fast pixel-perfect collision detection algorithm. Along the way you'll learn how to display graphics at 60 frames per second, play sounds, handle the keyboard, display and update a high-score table and lots more.

It's currently being polished and should be ready for launch on Amazon in December 2018.

When the book is ready, I'll post a link here.

Here's the table of Contents of the Book

Chapter 1. Introduction to C programming

The Game – Asteroids

Chapter 2. Computers and Operating Systems

  • Computers run programs all the time
  • Switching on a Computer
  • Operating Systems
  • Disk Drives
  • Windows 7/8/10 etc.
  • Computer Programs

Chapter 3. Running Programs

  • Files and Extensions
  • File Explorer

Chapter 4. Bytes and Bobs and some Maths

  • A Little bit of Math(s)
  • Octal
  • Files are bytes too!
  • More about Bytes
  • What’s a signed number in hexadecimal?
  • Multiple Byte numbers

Chapter 5. Hello World

  • Listing of Hello World
  • Command Line Window?

Chapter 6. Installing Visual Studio Community Edition

  • Downloading Files
  • Projects
  • Game Source Code

Chapter 7. Our first project

  • Some notes on this Chapter
  • Printing on Multiple Lines

Chapter 8. Variables in C

  • What is a Variable?
  • Numeric types for variables
  • How big are variables of a specified type?
  • Snippets
  • Unsigned types
  • Floating Point variables

Chapter 9. Another type: char

  • C Strings
  • What is a Pointer variable?

Chapter 10. A little Bit of C code

  • More Code
  • Programming Mistakes in C
  • Testing for equality but using = instead of ==.
  • TIP

Chapter 11. A Quick Overview of Visual Studio

  • Jumping backwards and forwards.
  • Adding or Removing files from a Solution

Chapter 12. Array variables

  • Working with arrays
  • Accessing and using arrays
  • Counting from 0
  • Multiple dimension arrays
  • Text case in C
  • Comments

Chapter 13. Loop the loops

  • For Loop
  • The loop variable
  • A shortcut way of incrementing
  • Before or after ++?
  • Back to the for-loop
  • Empty and infinite loops
  • What it does

Chapter 14. More loops

  • The Bool type
  • The Do Loop
  • The Goto statement
  • Nested loops

Chapter 15. About operators

  • Numeric Operators
  • Comparison operators
  • The ternary operator ?:
  • Logical and Binary Ands
  • Logical And / Or
  • Binary-and, Binary-Or and Exclusive-Or

Chapter 16 - Structs

  • Type names
  • Explaining struct declarations
  • Structs and arrays
  • typedefs

Chapter 17. Functions

  • Function Layout
  • What is a void function?
  • Function Declarations
  • A few notes on functions.

Chapter 18. More about functions

  • Stack memory
  • Heap Memory
  • Why not 64-bit?
  • Function parameters
  • The return type
  • The return statement.
  • Return in void/non-void functions
  • You don’t need a return in a void function.

Chapter 19. Pointers

  • Arrays and Pointers
  • Viewing memory during debug in Visual Studio
  • Hiding the Memory view Window

Chapter 20. Text Strings

  • Safe and Unsafe C string functions
  • What is a buffer?

Chapter 21. The Asteroids Game

  • Spaceship controls
  • Special keys
  • The Source Code

Chapter 22. Architecture of C Programs

  • Header and Lib files
  • External Libraries

Chapter 23. Graphics

  • SDL2 Library
  • Game Resources

Chapter 24. Installing SDL2

  • 32-Bit or 64-Bit?
  • Checklist
  • dll folder files
  • lib folder files
  • Include folder files
  • Setting up an empty C project
  • Configuring your project
  • Adding Libraries to a C or C++ project

Chapter 25. An SDL Demo program

  • (A short chapter!)

Chapter 26. The Game Loop

  • Flipping the screen
  • What does that mean? Double buffered?
  • Flipping What?
  • Faster, much faster!

Chapter 27. High Precision Timing

  • The hr_time library
  • Files for this Chapter How does timing work?

Chapter 28. Drawing Text

  • Images
  • A Bit About Compiling Visual Studio Solutions
  • What is an Escape Char?
  • Printing numbers on screen
  • The function printch
  • Visual Studio lets you view and edit image files
  • How It Works
  • How long is a frame in time?
  • Files for this chapter

Chapter 29. More Game Elements

  • The player’s ship.
  • The Switch statement
  • Key Handling
  • GameLoop and ProcessEvents
  • Ship Movements
  • Rotating the Ship
  • Velocity in two dimensions
  • The ApplyThrust function
  • The MoveplayerShip function
  • Files for this chapter

Chapter 30. Adding in asteroids

  • Asteroid Graphics
  • Files for this Chapter

Chapter 31. Adding in bullets

  • Why countdown and ttl?
  • Files for this Chapter

Chapter 32. A bit of C99

  • Comments in C

Chapter 33. Editing with Visual Studio

  • Navigate by function
  • Bookmarks
  • Refactoring.

Chapter 34. Restructuring

  • About Header files
  • Examples of pre-processor directives
  • Include Guards
  • The lib.h file
  • Files for this chapter

Chapter 35 Show the Score

  • Showing Lives
  • What is a Version Control System (VCS)?
  • Adding lives etc.
  • InitSetup Change
  • Pause Key and Hyperspace Jump
  • Files for this Chapter

Chapter 36. Explosions

  • Determining Asteroid Velocities
  • Show me the explosions!
  • Files for this chapter

Chapter 37. Sounds

  • SDL_Mixer
  • Using SDL_mixer
  • The sound code
  • Files for this Chapter

Chapter 38. Detecting Collisions Part 1

  • How do the masks work?
  • Generating the Masks
  • Testing the Mask generation
  • The mask output
  • C multi-dimensional arrays and row ordering
  • Resource Manager
  • Files for this Chapter

Chapter 39. Detecting Collisions Part 2

  • Checking for Collisions
  • Intersecting rectangles with SDL
  • Reducing Collision Checks
  • Objects and cells
  • Why do we add an object to cells?
  • Adding an object to a cell?
  • Processing Cells
  • Checking Each Cell
  • Objects in a Cell
  • Adding a pointer into a list of pointers in a cell.
  • How many cells does an object cover?
  • Pointers and arrows
  • Back to the Cells
  • Timing ClearCellList

Chapter 40. Detecting Collisions Part 3

  • (A short chapter!)

Chapter 41. Passing Parameters into functions

  • Using ++ with pointers
  • Why are pointers so important?
  • When to use & and when not to

Chapter 42. Detecting Collisions Part 4

  • The Overlap function
  • Explanation of Overlap
  • Destroying Objects
  • How much processing time does it take?
  • Viewing the overlap pixels
  • Files for this Chapter

Chapter 43. Ever Wondered about if (!value)

  • (A short chapter!)

Chapter 44. Some Debugging Tips

  • More Logging
  • Show me the cells
  • Files for this Chapter

Chapter 45. Improving the game

  • Scores
  • A really stupid bug
  • A bug fixing Strategy
  • Files for this Chapter

Chapter 46. Adding Level Structure

  • Making Life Easier for yourself
  • Adding Lives
  • Aliens?
  • Changes to Text Sprites
  • Game play problem
  • Yet another Bug!
  • Files for this Chapter

Chapter 47. Alien Ships!

  • Alien Artificial intelligence
  • When is a function not a function?
  • Flashing Alien
  • Adding a Shield control
  • Drawing the Shield

Chapter 48. The High Score

  • Displaying the high scores
  • Entering the High Score
  • Files for this Chapter

Chapter 49. Finishing off

  • (A short chapter!)

Chapter 50. Obtaining Source code and Resources

  • Running asteroids outside of Visual Studio

A big thank you to limaker for helping with a tedious task!