Programming Q&A

Topics discussed here: Web Applications - In particular: HTML, PHP and MySQL apps Windows GUI - I have over fifteen years experience writing MS Windows Apps in C++. Got a problem? Give me a crack at it. Introduction to Game Programming

Wednesday, December 06, 2006

Gaming Basics

I'd like to propose a little project here for anyone that wants to follow along and/or contribute. The result will be some kind of arcade style game for Microsoft Windows. We will write the project in C++. I have a Microsoft Visual C++ compiler, but any C++ compiler should do as the goal is to use only Win32's rather than relying on MFC or some other non-standard library.

The basic steps any game needs to perform during the game cycle is as follows:

1) Paint the background to an offscreen buffer.

2) Paint the "sprites" to to the same offscreen buffer.

3) Display the offscreen buffer by telling the video hardware to swap buffers OR blit the buffer to video memory all at once.

4) Process and respond to user input.

5) Detect and respond to any collisions.

6) Update statistics such as scores, lives or time left.

7) Possibly update the sound buffer according to the events of this cycle.

8) Repeat the cycle until game end.

If you've read just a little about game programming, you've probably heard the term "sprite". The term is older than my 25 year experience with game programming. A sprite is basically an object that you move around the screen such as ships, people, bullets... You differentiate sprites from the display background because the player typically does not interact with the background, only other sprites. Therefore, when you look for "collisions" (sprites overlapping or hitting other sprites), you ignore the background.

Years ago I wrote a C++ sprite class for some of the games I wrote thereafter. It is an interesting and entertaining exercise. It allows you to abstract the display of the sprite so that you can adapt the sprite class to different target platforms (DOS, Windows, XWindows, Apple whatever...).

I am open to comments. If you would like to write your first game or contribute based on your experience, join in and let's go. I will publish source and you can too. BTW, I am no artist, so any help you can provide I would much appreciate.

0 Comments:

Post a Comment

<< Home