The purpose of this tutorial is to teach 2D game programming and C-language through examples.
The author used to program games in the mids and was a game designer at MicroProse for a year in the 90s. Although much of that is not relevant to the programming of today's big 3D games, for small casual games it will serve as a useful introduction. Games like snake where objects are moving over a 2D field can resume designs free the game objects either in a 2D grid or as a single dimension array of objects.
Press Esc to quit the game, f to toggle frame rate this isn't synchronized to the display so can be fasttab key to toggle debug info and p to pause it.
When it's paused the caption changes and the snake flashes. In snake the main game objects are.
For purposes of gameplay, an array of ints will hold every game object or part for the snake. This can also help when rendering the objects into the screen buffer.
I've designed the graphics for the game as follows:. As there are only locations in the grid I've chosen to store it in a single dimension array. Each coordinate on the 16 x16 grid is an integer We've used ints so you could make the grid bigger. This has benefits in game speed as using two indexes is always slower than one but it means instead of adding or subtracting 1 from the snake's Y coordinates to move vertically, you subtract WIDTH.
A Simple 2D Game- Where do I Start?
Add 1 to move right. However being sneaky we've also defined a macro l x,y which converts the x and y coordinates at compile time. The first row is indexthe 2nd etc.
There are three blocks int arrays used in the game. At the game start, the snake is two segments long with a head and a tail.]