Breakout Tutorial 1

This tutorial will show you how to build a clone of Breakout in Pascal using the SwinGame SDK. Breakout is the successor to Pong, making it one of the first few computer games. It took Steve Wozniak four days to build the first prototype of Breakout, however in SwinGame you can make it in a couple of hours. By the end of this tutorial you will have a fully functional Breakout game, with different levels, sound effects, and completely addictive gameplay.

WARNING: This tutorial is not finished yet.

Things You Need

 * A copy of Free Pascal set up and working on your computer
 * A text editor: on Windows I prefer Notepad++ because it has a tabbed interface, it does Pascal syntax highlighting, can run from a USB drive, and is free. However Crimson Editor, EditPad Lite, or even just the regular Notepad are all okay.
 * You should be familiar with Pascal syntax… If you haven’t at least compiled a Hello World program in Pascal, go and do that first.

Starting The Project
You will need to obtain the latest version of the SwinGame SDK for FreePascal. For this tutorial I’m using the Windows version, however the code will run equally well on Linux or Mac OS X. See Getting Started for more information.

Compiling The Game
To compile the game, it is easiest to use the build script provided with SwinGame. On Windows this is the winbuild.cmd file. Open the command line to your game's folder, type winbuild.cmd breakout.exe to build the game. If the process is successful, it will place a Breakout.exe file in the Bin folder. Run this executable to play your game. For more detailed instructions, see the Wiki pages for compiling on Windows, Mac OS X and Linux.

Game Resources
All of the image files used in this project are available for download. The link is coming soon.

Structuring the game
Before starting to write the game, you should think about how the game is going to work. The way Breakout works is that there is a set of bricks at the top of the screen, and a paddle which the player controls. The ball bounces off the paddle and hits a brick. The brick disappears and the player’s score increases. When there are no more bricks, the player goes to the next level.

I’m going to represent the player in memory with a record called playerType, which looks like this:

PlayerType
 * Lives – integer containing how many lives the player has. If this is <0, the player loses.
 * Level – integer containing what level the player is on. This changes the speed of the ball and the paddle.
 * Score – integer containing the player’s score
 * PlayerSprite – The sprite object which represents the player’s paddle
 * BricksRemaining – integer containing the number of bricks the player has to hit before advancing to the next level

The bricks are going to be represented in memory by an array of brick records, as defined below:

Brick
 * BrickColor – integer containing a number which says which row the brick is in. When the brick is initialized (see the Bricks section later), the actual image will be loaded from ‘brickX.png’, where X is this number. This also changes how much the brick is worth when it is hit (the bricks closest to the player are worth 50 points, the next row is worth 100 points, and the next is worth 150 points)
 * BrickSprite – The sprite object which represents this brick
 * Hit – Boolean containing whether or not the brick has been hit by the ball yet

As well as these two types, there will be a set of constants which will control most of the game’s parameters (ie. Number of lives, screen size etc). We will keep adding to this list of constants as the game builds functionality.

Summary
So far we have decided on the structure of the game’s data in memory. In the next tutorial, we will start writing some code, and get the ball bouncing around the screen.