Introduction

This book is the third edition of the best-selling Game Programming All in One. This new third edition is an update of the previous edition, which was itself a complete rewrite of Game Programming All in One. The second edition took the subject into a completely new direction with the Allegro game library, and has since become very popular among aspiring game programmers for its valuable insights and professional approach to writing games. The new goals, new assumptions, and new development tools helped many programmers get their start in C/C++ game programming.

This book does not cover Windows or DirectX at all. Instead, this book focuses on the subject of game programming using a cross-platform game library called Allegro. This library is extremely powerful and versatile. I did not even hesitate to choose Allegro when developing the initial proposal for this book because Allegro opens up a world of possibilities that are ignored when you focus specifically on Windows and DirectX. This edition still uses the standard C language, and the sample programs will compile on multiple platforms. For good measure, a dash of C++ has been introduced in the form of a sprite class, but the book is still largely based on the C language, which means it is easy to understand.

What Is Allegro?

Do you like games, and would you like to learn how to create your own professional-quality games using tools of the trade—used by professional game developers? This book will help you get started in the right direction toward that goal, and you'll have a lot of fun learning along the way! This is a very practical programming book, not rife with theory, so you will find many, many sample programs herein to reinforce each new subject.

The Windows version of Allegro uses DirectX, as a matter of fact, but it is completely abstracted and hidden inside the internals of the Allegro game library. Instead, you are provided with a basic C program that includes the Allegro library and is capable of running in full-screen or windowed mode using any supported resolution and color depth. Allegro provides a uniform interface for sound effects, music, and device input, which are implemented on the Windows platform with DirectSound, DirectMusic, and DirectInput.

Imagine writing a high-speed arcade game using DirectX, and then being able to recompile that program (without changing a single line of code!) under Linux, Mac OS X, Solaris, and other popular operating systems! Allegro is a cross-platform game library that will double or triple the user base for the games you develop with the help of this book. On top of that, it is a very easy library to use, combined with being very useful.

This book will teach you to write complete games that will run on almost any operating system. The example programs were written using both Windows and Linux, with screenshots taken from both operating systems. In all likelihood, you will have the opportunity to use your favorite development tool because Allegro supports many C++ compilers, including Borland C++, Borland C++Builder, Apple Development Tools, Xcode, and several other compilers on various platforms. On the Linux platform, you can use the command-line GCC compiler or you can use any popular IDE such as KDevelop, because GCC is an integral part of Linux systems.

Target Audience

The target audience for this book is beginning to intermediate programmers who already have some experience with C or C++. Also, those who want to learn to develop with a C or C++ compiler can use this book as an entry-level guide. The material is not for someone new to programming—just someone new to game programming. I must assume you have already learned C or C++ because there is too much to cover in the game libraries, interfaces, and so on to focus on the basic syntax of the actual language. It was difficult enough to support several different compilers and integrated development environments without also explaining every line of code.

Intermediate-level experience is assumed, while extreme beginners will definitely struggle. In Appendix D, “Recommended Books and Websites,” I've recommended introductory books for those readers. This book is not extremely advanced—the source code is straightforward, with no difficult libraries to learn per se, but I do not explain every detail. I do cover the entire function library built into Allegro, since that is the focus of this book, but I do not explain any standard C functions. The goal is to get up and running as quickly as possible with some game code! In fact, you will be writing your first graphics programs in Chapter 3 and your first game in Chapter 4.

Someone who has done some programming in Visual C++, Borland C++ Builder, Bloodshed Dev-C++, GNU C++, or even Java or C# will understand the programs in this book. Those with little or no coding experience will benefit from a C primer before delving into these chapters. I recommend several good C primers and C programming books in Appendix D.

The emphasis of this book is on a free cross-platform compiler, a free integrated development environment, and a free game library. You will not need to learn Windows or DirectX programming, and these subjects are not covered. Two free compilers are emphasized the most, but not exclusively:

  • Microsoft Visual C++ 2005 Express Edition

  • Bloodshed Dev-C++ 5.0

The freeware Dev-C++ compiler is included on the CD-ROM.

The game library is called Allegro; it is also freeware, open-source, and included on CD-ROM.

You have all the free tools you need to run the programs in the book, and then some! Using these tools, you can write standard Windows and DirectX programs with or without Allegro, and without the cost of an expensive compiler, such as Visual C++ Professional. This book is highly accessible to all C programmers, regardless of their platform of choice. (You may also use Microsoft's new free compiler, Visual C++ Express.)

This book's source code and sample programs will build and run without modification on all of the following systems:

  • Windows 98/ME

  • Windows 2000

  • Windows XP/2003

  • Mac OS X

  • Linux

  • BeOS

  • Solaris

  • FreeBSD

That is almost every computer system out there. Yet, at the same time, the Windows version supports DirectX. The programs will run in full-screen or windowed mode with full support for the latest video cards.

Massive Compiler Support!

If you have any experience with the C language, then you will be able to make your way through this book. If you are new to the C language, I recommend against reading this book as your first experience with C because it will be confusing due to the extensive use of Allegro. (Very few standard C functions are used.) The example programs use a very simple C syntax with no complicated interfaces or lists of include files. In fact, most of the programs will have a simple format like this:

#include <allegro.h>
int main(void)
{
    allegro_init();
    allegro_message("Welcome To Allegro!");
    allegro_exit();
    return 0;
}
END_OF_MAIN()

This is a very simple program, but it is complete and will run. Allegro provides comprehensive support for all of the video modes supported on your PC, including full-screen and windowed DirectX modes used by most commercial games. On the UNIX side, Allegro supports the X Window system, SVGAlib, and other libraries (as appropriate to the platform), providing a similar output no matter which system it is running on. For instance, the allegro_message function opens a pop-up message box in Windows, but prints a message to a terminal window in Linux.

If you are a Windows user and you don't care about Linux, that won't be a problem. The screenshots presented in this book look exactly the same no matter what operating system you are using, and my choice of Windows or Linux in each particular case is simply for variety. Likewise, if you are a Linux user and are not concerned with Windows, you will not be limited in any way because every program in this book is tested on both Windows and Linux. The CD-ROM that accompanies this book includes the complete source code for the sample programs in this book, with project files for Microsoft Visual C++ 2003 and Bloodshed Dev-C++ 5.0.

Since there are so many operating systems and compilers out there, I have decided against trying to support them all. I have spoken with many Linux programmers, and they prefer to just use the command-line tools with their favorite text editor, and do not use KDevelop (which was featured in the last edition). So, Linux fans, you may simply copy the source files off the CD-ROM and compile them as-is on your system, ignoring the Visual C++ and Dev-C++ project files (.sln and .dev). The code will compile as is without modification on every platform. That is the beautiful thing about Allegro code.

The tools on the CD-ROM include both Windows and Linux versions. If you are using an operating system other than these two, you should have no problem adapting the source code to your compiler of choice. The complete Allegro 4.2 library is provided on the CD-ROM, with complete instructions on how to build the library for your favorite system. For the Windows platform, I have provided pre-compiled versions of the library for all of the following compilers:

  • Visual C++ 6.0

  • Visual C++ 7.0 (2002)

  • Visual C++ 7.1 (2003)

  • Visual C++ 8.0 (2005)

These pre-compiled versions of Allegro were made available by Allegro fans at http://www.allegro.cc and greatly simplify the configuration. You can configure a new Visual C++ project using the Allegro library and compile a test program in just a few minutes! (Contrast that with building the entire Allegro library, as we did in the previous edition of the book!)

System Requirements

The programs in this book will run on many different operating systems, including Windows, Linux, Mac OS X, and almost any UNIX variant that supports the X Window system. All that is really required is a PC with a decent video card and sound card.

Here are the recommended minimum hardware requirements:

  • Pentium II 300 MHz

  • 128 MB memory

  • 200 MB free hard disk space

  • 8 MB video card

  • Sound card

Book Summary

This book is divided into parts:

  • Part I: Cross-Platform Game Programming with the Allegro Game LibraryThis first section provides all the introduction you will need to get started writing cross-platform games with Allegro, with screenshots from both Windows and Linux. By the time you have completed this first set of chapters, you will have a solid grasp of compiling Allegro programs.

  • Part II: Sprite ProgrammingThis section is the meat and potatoes of the book, providing solid tutorials on the most important functions in the Allegro game library, including functions for loading images, manipulating sprites, double-buffering, and other core features of any game. This section also provides the groundwork for the primary game developed in this book.

  • Part III: Scrolling BackgroundsThis section is devoted entirely to the subject of scrolling backgrounds. You'll learn the different techniques employed to create scrolling games, and see many examples of the genre including vertical and horizontal scrolling demos. You will also learn how to create and edit game levels.

  • Part IV: Taking It to the Next LevelThis section is comprised of more advanced chapters covering game design, datafiles, intro movies, basic artificial intelligence, and multi-threading. The example game project (Tank War) is finished during this section of the book.

  • Part V: AppendicesThis section of the book provides answers to the chapter quizzes, a tutorial on numbering systems, an ASCII table, and a list of helpful resources.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.164.141