Windows game programming master skills (version 2) Chapter 1st (I)

Source: Internet
Author: User

Chapter 2 xuehai
"Oh, you want some too ?!? "
-Hudson, Aliens
Windows programming is like a long-standing and ongoing war. Although game programmers once refused to develop for Windows platforms, as the Borg race creature in Star Trek often says: "Resistance is futile ......", I think this statement is appropriate. This chapter will show you how to quickly view all aspects of Windows game development:
? Game history
? Game type
? Game programming elements
? Tools used
? Instance: FreakOut
A glimpse of History
Everything can be traced back to the advent of the first large computer in 1960s. In retrospect, I think the Core Wars running on Unix computers can be listed as one of the earliest computer games. When the 1970s s passed away, many adventure games were available on large and small computers around the world. Most of them are based on text and dialogs and have a simple graphic interface.
Interestingly, most games were online in that era! I mean, at that time, 90% of the Games were MUD (Multi-User Dungeons, multiplayer dragons and underground games) or similar simulation games, such as Star Trek (Star Trek) AND SOME War simulation games. However, the masses still waited until a computer game named Pong appeared to start to appreciate the charm of computer games. Nolan Bushnell designed Pong, a single player that truly started the entire video gaming industry overnight. The Atari brand was born at that time.
Since then, it has been around 1976 ~ In 1978, TRS-80, Apple, Atari 800 and other computers were put into the market, they are the first generation of computers that consumers can buy. Of course, you can also buy assembly machines similar to Altair 8000, but who would like to assemble them? However, these computers have their own advantages and disadvantages. Among these computers, Atari 800 was one of the most powerful computers at the time (I was confident that it could be developed for a runable version of Wolfenstein (German command), the most commercially available TRS-80, apple has the best sales experience.
Gradually, the games on these computer systems began to hit the market, and overnight there were many millionaires in their teenage years. At that time, just a good game like "Lunar Lander" or Pong can make its producers suddenly rich! At that time, computer games started to look like real computer games, and only a few people knew how to write games. At that time, there was absolutely no such book as the game development guide, but some people occasionally published 50 ~ The 100-page brochure answers the mysteries of game development. It seems that Byte magazine has published an article, but most of the time, you have to rely on yourself.
1980s was the time when games warmed up. The first generation of 16 computers, such as ibm pc (and compatible machines), Mac, Atari ST, Amiga 500, and so on. At this stage, the game screen began to look good, and even 3D games appeared on the market, such as Wing Commander and Flight Simulator ). However, at that time, PC machines were still behind game machines. As of 1985, Amiga 500 and Atair ST have dominated the game market as the most powerful game consoles. However, PC has gradually become popular for its low price and wide commercial use. The result is that no matter the technology or quality, the PC will eventually be integrated.
In the early 1990s S, ibm pc and its compatible devices were the mainstream in the market. With the release of Microsoft's Windows 3.0, Apple's Macintosh has never died. PC is a "computer of workers ". Users can use it to play, write programs, and connect various devices. I think this can explain why so many computer enthusiasts are infatuated with PC rather than a more beautiful Mac. In a word, you cannot have fun using Mac.
However, at that time, PC still lags behind in image and sound. PC seems to be a lack of horsepower, and PC games are always far from the good performance of Amiga or games on home consoles.
God said, there is light, so there is light ......
In the second half of 1993, id software released doom, as a continuation of Wolfenstein 3D (German command 3D, one of the earliest 3D shared game software, also developed by ID. In the home computer market, PC has become the first choice for playing games and programming. The success of doom proves that as long as it is smart enough, people can make PCs do anything. This is important. Remember that nothing can replace imagination and determination. If you think one thing is possible, it is possible!
Microsoft started to reevaluate its position in Game and game programming with the impact of doom. It realizes that the entertainment industry is huge and will only become bigger. If it is in this industry, it will have nothing to do. As a result, Microsoft has made a huge plan to take part in the game industry.
The problem is that, even in Windows 95, real-time video and audio processing capabilities are still poor, so Microsoft made a software called win-G, trying to solve video problems. During the promotion, win-G was said to be the best game programming and graphics subsystem, but in fact it is just a bunch of graphical calls for drawing bitmaps. What's more, Microsoft has denied the existence of Windows-g about a year after it was released!
The development of a new software suite that includes graphics, sound, input, networking, and 3D Systems (Microsoft acquired rendermorphics in 95 years) has already begun, and DirectX was born. As in the past, Microsoft release announced that it would solve all the game programming problems on the PC platform in the world, and said that Windows games would run as fast or even faster as dos32 games. But this is not the case.
The first two versions of DirectX, as a complete software product, have too many bad defects, but this does not mean technology. Microsoft only underestimated the complexity of video game programming (and also underestimated the capabilities of video game programmers !). With DirectX 3.0, DirectX works better than DOS! But then (1996 ~ 1997), most gaming companies are still developing for DOS32. It was not until the release of DirectX 5.0 that people switched to using DirectX for actual development on Windows.
DirectX has now been upgraded to version 9.0 (This book includes version 7.0 and version 8.0). It is a powerful and irresistible API. That's right, you should think in another way-use COM (Component Object Model, Component Object Model) to program on Win32, at the same time, you no longer have full and direct control over the entire computer-but this is what life is like. As in the series "Star Trek", Geordi (Enterprise ship's chief engineer, eagleeye) cannot personally control the entire computer system of the ship.
Using DirectX technology, you can create a virtual machine with 4 GB addressing space (or more), linear and continuous memory, and DOS-like. You have reason to think that you are programming in the DOS environment (if you like. More importantly, now you can quickly add new technical support for images and sounds to your programs. This is all due to the far-sighted Design and Technology of DirectX. Let's talk about DirectX first, because you will soon learn it in detail. Now let's go back to history.
The earliest appearance was the DOOM game, which only used the software grating technology. 1.1. Let's take a look at the screen performance of the Rex Blade game, a clone of DOOM. The next generation of 3D games, such as Quake I, Quake II, and Unreal, had a major leap. Looking at the Unreal game screen in Figure 1.2, this game and Its similar games are incredible. They both contain software grating and hardware acceleration code to maximize the advantages of both. Here I can't help but say that if you want a Pentium 4 generation GHz computer with a GeForce 4 TI graphics card to run Unreal II or Quake III, the effect would be great.
Figure 1.1 Rex Blade: first-generation DOOM technology Product
 
Figure 1.2 unreal: amazing results!
 
So where will this take us? Our technology is becoming more advanced and almost limitless. However, miracles always emerge. Although a good game like quake and unreal takes years to create, I believe you can create a game that is equally fascinating!
A glimpse of history has come to an end. Let's turn to the core design.
Design games
Designing is one of the most difficult tasks for video games. Indeed, 3D mathematics is difficult, but it is equally difficult and important to plan and design an interesting game. If a game is really fun, who cares if the game uses the latest volume photonic tracking algorithm (volumetric photon traces?
In fact, it is not particularly difficult to come up with a game idea. The key is that details, final implementations, and visual effects determine the destination of the game, whether it is thrown into the trash can or on the cover of PC gamer? The following describes some basic concepts and some of my experiences and lessons.
Game type
Currently, there are many types of games, such as political promises (some of which have vanished), but they can be classified into the following types:
Similar to doom's first perspective-most of these games are full 3D games, where players observe from the perspective of game roles. Doom, hexen, quake, unreal, Duke nukem 3D, and dark forces are among the top players in such games. Technically speaking, they may be the most difficult game to develop, and they require excellent technology to excel in such games.
Sports-sports games can be 2D or 3D. However, there are more and more 3D sports games recently. Sports Games can be played by one person or by multiple players. The image quality of sports games has been greatly improved compared with earlier ones. Although sports games may not be as impressive as those with first-view games, they are catching up. The artificial intelligence level in sports games is among the most advanced in all game types.
Fighting games can usually be played by one or two people, watching the role's movements from a side view angle or through an unfixed 3D camera. The portraits of game figures are generally 2D, 2.5D (a series of 2D bitmap images rendered by 3D models), or all 3D. Tekken (iron fist), running on the Sony Playstation I (psx) Game Machine, has carried forward fighting games in the home game machine market. Fighting games are not very popular on PCs. This may be attributed to the interface problems of the game controller and the fact that it takes two people to have fun.
Arcade/gun battles/horizontal pass-through games like asteroids, Pac-Man and jazz jackrabbit. They are basically 2d old-fashioned games, but are gradually being recreated into 3D games. The rules of the 3D version are roughly the same as those of the 2D version.
Mechanical Simulation-this type of game contains a variety of driving, flying, rowing, racing cars, tank Combat Simulation and any other types that readers can imagine. The vast majority of such games have been 3D (although it is not satisfactory until recently ).
Ecosystem simulation-This game type is quite new, except for the real world itself, there are no other similar things. I am talking about a series of games, such as populous, simcity, and simant. Such games allow players to play the gods that dominate various species, or control a certain artificial system, whether it's a city, a group of ants, or simulate Financial Finance like gazzillonaire (a cool game.
Strategy or war-these games have been divided into many sub-categories. However, I do not blindly agree with those classification methods, so I include strategic elements (sometimes turn-based) such as Warcraft and Diablo) final Fantasy VII (Final Fantasy 7) and so on. Although Diablo is a real-time game, it still contains a lot of policy factors and thinking. In contrast to Diablo, Final Fantasy is a combination instead of an instant one.
Interactive stories-this category includes games similar to Myst. Basically, the images of these games are pre-rendered, or designed based on the path, and are played by constantly solving puzzles. Generally, due to the lack of better definitions, these games do not allow gamers to wander freely. They can only be the same as playing interactive books. Finally, they are not like games in the general sense, because 99% of them are written by director or similar tools. What do I want? Verne will surely criticize that this is too boring.
Classic nostalgia-such games always seem to have emerged overnight. At any time, people always want to play an old game, but they hope that the plot and difficulty of the game are more complex than they did before. For example, Atari has produced about 1000 versions of tempest. I have to admit that their sales are not very good, but you can understand the truth. I am lucky to have re-created some of these old games, such as Dig Dug (Gold Amoy), centipede (Greedy snake), and Frogger (Frogger.
Pure intellectual puzzles and card and board games-do not need to be introduced too much. Such games are 2D, 3D, or pre-rendered. Tetris, monopoly, and mahjong are among these games.
Brainstorm
Once you decide what kind of game you want to make (this is simple because we know what we like), it's time to think about it. It is up to you to come up with ideas. There is no way you can always think of ideas.
First, you must think of a game idea you want to create. You will Gradually refine this cool and achievable idea into a game that others like.
Of course, you can also use other games as a model or starting point to get inspiration. Another product should not be copied Based on the image, but it is acceptable to imitate a successful product. You need to read a lot of science fiction books and game magazines, observe what the market is selling, watch a lot of movies to find cool story ideas, game ideas, or use the visual impact of a movie to motivate yourself!
What I usually do is sit with my friends (or myself) and throw various ideas until something sounds cool. Then I will discuss this idea until it is plausible or collapsed. This is sometimes frustrating. You may think too much about yourself and give up your thoughts in two or three hours. Don't be discouraged. This is a good thing. You know, if you think of a game idea the next day and you still like it, you may have a chance.
Warning
Here I would like to remind you of one very important thing: Don't be greedy and Chewy! I have received thousands of emails from new players in game programming. These friends are eager to develop games that match the DOOM or Quake level in a short period of time as their debut, which is obviously impossible. If a beginner can ~ We are lucky to have completed a clone version of Asteroids within six months. You need to set up an achievable goal for yourself and try to do something as you can, because at the end of the day, you are always the only one who is continuing to work, and others are leaving you. Also, remember to make your debut game as simple as possible.
Next let's continue to discuss other details.
Design document and plot Board
When you already have a game idea, you should put it on paper. Now whenever I want to develop a large game product, I want to write a decent design document. For small games, the details of several pages are enough. Basically, the design document is a map of the game development adventure. You should include as many details as you can think of, such as the details of checkpoints and game rules. In this way, you can know what you are doing so that you can work as planned. On the contrary, if the design is always modified at will during development, the game you developed one day will be messy.
Generally, I like to start with a simple story, such as using one or two pages to describe what the game is about, who is the main character, what the game idea is, and how the players play the game. Then I decided on the core details of the game-game levels and rules, listing as many details as possible. After that, I can add or delete content, but at least I have a feasible plan. If one day I came up with 100 cool new ideas, I could keep adding them to the document without having to forget.
Obviously, the design details are entirely determined by you, but you still need to write down the design, at least a game synopsis. For example, you may not like the lengthy design documents, but prefer the general block diagrams of game levels and rules. Figure 1.3 is an example of a game plot board. There are no complex details, but only sketch for easy observation and work.
Figure 1.3 a basic plot concatenation Board
 
Make the game interesting
The final part of the game design is the actual verification. As a designer, are you sure your game is interesting and people will like it? Is it true that you are not deceiving yourself? This is a serious problem. There are about 10000 games in the market and 9900 companies in the gaming industry. If you're totally fascinated by this game and desperately want to play it right away, you're almost done. But if the designer is indifferent to the method, imagine what other people will give to the game!
The key is to carry out a lot of thinking and beta testing to add a variety of cool features, because these details finally make a game lively and interesting. This is just like the craftsmanship of hand-made oak furniture-people really appreciate these details.
Composition of the game
Now let's take a look at what makes a video game program different. Video games are extremely complex software. In fact, they are undoubtedly the most difficult programs to write. Writing MS Word programs is harder than writing Asteroids games, but writing Unreal games is harder than writing any other programs I know!
This means that the reader should learn a new way of programming, which is more beneficial to real-time applications and simulation programs, instead of the single-line, event-driven, or sequential logic programs you may have become accustomed. A video game is basically a continuous loop that performs logical operations and draws images on the screen at a 30-frame/second (or higher) refresh rate. This is very similar to the film screening principle, except that the director is yourself.
Figure 1.4 is a simplified game loop structure. The following describes each part in the figure.
Figure 1.4 general game loop structure
 
Step 1: Initialize
In this step, the game program performs standard initialization operations, such as memory allocation, resource collection, and data loading from the disk.
Step 2: Enter the game loop
In this step, the code runs inside the main loop body of the game. Various operations start to run until the user exits the main loop.
Step 3: Obtain players' input information
In this step, the player's input information is processed and/or cached for use in the next step of AI and game logic.
Step 4: Execute AI and game logic
This part includes the main part of the game code, such as executing AI, physics, and general game logic, and the results are used to render the next frame of the image.
Step 5: render the next image
In this step, the player's input and the results of the game's artificial intelligence and game logic execution in Step 4 are used to generate the next animation of the game. This image is usually placed in an invisible offscreen buffer area, so players will not see it gradually rendered. Then the image is quickly copied to the Display memory and displayed.
Step 6: Synchronous Display
Generally, due to the complexity of the game, the speed of running the game on the computer may be fast and slow. For example, if there are 1000 objects on the screen, the CPU load is much heavier than when there are only 10 objects. Therefore, the game's image refresh rate (frame rate, Frame Rate) will also be high and low, which is unacceptable. Therefore, the game must be synchronized at a certain maximum frame rate, and the timing function and/or wait function must be used to maintain synchronization. Generally, the frame rate of up to 30 frames per second is very good.
Step 7: loop
This step is very simple. You only need to return to the entry of the game loop and re-execute all the above steps.
Step 8: Close
This step is the end of the game, indicating that it will exit the main program or game loop and return to the operating system. However, before the user completes, the user must release all the resources and clean up the system. These release operations are also required for any other software.
Readers may have questions about the many details in the actual game loop. It is true that the above explanation is a bit too simple, but it highlights the focus of game programming. In most cases, a game loop is a FSM (finite state machine, finite state automation) that contains a large number of States ). Listing 1.1 is a more detailed version, which is basically close to the actual C/C ++ code of the game loop.
Program list 1.1 a simple game event Loop
// Defines for game loop states
# Define game_init // The game is initializing
# Define game_menu // The game is in the menu Mode
# Define game_starting // The game is about to run
# Define game_run // The game is now running
# Define game_restart // The game is going to restart
# Define game_exit // The game is exiting

// Game globals
Int game_state = game_init; // start off in this state
Int error = 0; // used to send errors back to OS

// Main begins here

Void main ()
{
// Implementation of main game loop

While (game_state! = GAME_EXIT)
{
// What state is game loop in
Switch (game_state)
{
Case GAME_INIT: // the game is initializing
{
// Allocate all memory and resources
Init ();

// Move to menu state
Game_state = GAME_MENU;
} Break;

Case GAME_MENU: // the game is in the menu mode
{
// Call the main menu function and let it switch states
Game_state = Menu ();

// Note: we cocould force a RUN state here
} Break;

Case game_starting: // The game is about to run
{
// This state is optional, but usually used
// Set things up right before the game is run
// You might do a little more housekeeping here
Setup_for_run ();

// Switch to run state
Game_state = game_run;
} Break;

Case game_run: // The game is now running
{
// This section contains the entire game logic loop
// Clear the display
Clear ();

// Get the input
Get_Input ();

// Perform logic and ai
Do_Logic ();
// Display the next frame of animation
Render_Frame ();

// Synchronize the display
Wait ();

// The only way that state can be changed is
// Thru user interaction in
// Input section or by maybe losing the game.
} Break;

Case game_restart: // The game is restarting
{
// This section is a cleanup State used
// Fix up any loose ends before
// Running again
Fixup ();
// Switch states back to the menu
Game_state = GAME_MENU;
} Break;

Case GAME_EXIT: // the game is exiting
{
// If the game is in this state then
// It's time to bail, kill everything
// And cross your fingers
Release_And_Cleanup ();

// Set the error word to whatever
Error = 0;

// Note: we don't have to switch states
// Since we are already in this state
// On the next loop iteration the code
// Will fall out of the main while and
// Exit back to the OS
} Break;

Default: break;
} // End Switch

} // End while
// Return Error code to Operating System
Return (error );

} // End main
Although listing 1.1 does not have any specific functionality yet, studying its game loop helps to understand the entire game structure. All game loops are designed more or less based on this structure. Figure 1.5 shows the status transition of the game's cyclic logic. Obviously, the state transition is very coherent.
Figure 1.5 transition of a game loop status
 
The content of the game loop and finite state automation will be discussed in more detail in the last chapter about the freakout demo game.
General game programming guidelines
The following describes the common technologies used in game programming and the basic principles you should master and use. This makes game programming easier.
In a word, video games are super-high-performance computer programs. You should not use high-level APIs in code segments with extremely strict runtime or memory requirements. In particular, most of the Code related to in-game loops needs to be manually written. Otherwise, most games will encounter serious speed and performance problems. Of course, this does not mean that you cannot trust DirectX and other APIs, because DirectX is designed to take into account the principles of high performance and "thin. However, in general, frequent calls to high-level functions should be avoided.
In addition to the above situations, you should pay more attention to the programming skills listed below.
Tips
Do not use global variables. Many video games do not allow time-demanding functions to use parameters, but use global variables to pass parameters. For example, the code for a function is as follows:
Void Plot (int x, int y, int color)
{
// Plots a pixel on the screen
Video_buffer [x + y * MEMORY_PITCH] = color;
} // End Plot
Because the parameter needs to be pushed to and out of the stack, the time required to execute this function body is less than the time required to call the function. In this case, a better way is to set up some global variables and assign values before the call to pass the parameters, as shown below:
Int gx, gy, gz, gcolor; // define some globals

Void Plot_G (void)
{
// Plot a pixel using globals
Video_buffer [gx + gy * MEMORY_PITCH] = gcolor;

} // End Plot_G

Tips
Use inline functions. By using inline indicators to completely get rid of function calls, you can even improve the previous technique. The Inline indicator indicates that the compiler replaces the function call with the function body code. This will undoubtedly make the compiled program larger, but it effectively improves the running speed. The following is an example:
Inline void Plot_ I (int x, int y, int color)
{
// Plots a pixel on the screen
Video_buffer [x + y * MEMORY_PITCH] = color;
} // End Plot_ I
Note that the global variables are not used here, because the editor effectively executes aliases of the same type. However, global variables are very useful, especially if only one or two parameters change the value during function calling-the remaining old values can be used without being reloaded.
Tips
Try to use 32-bit variables instead of 8-bit variables or 16 variables. Pentium and the updated central processor are all 32-bit, which means they do not like 8-bit or 16-bit data words. In fact, because the addressing of the high-speed cache and other related internal memory becomes irregular, a small amount of data may speed down. For example, you have defined a structure type as follows:
Struct CPOINT
{
Short x, y;
Unsigned char c;
} // End CPOINT
Note: It looks good to define this structure, but not actually! First, the structure itself is a 5-byte Structure -- (2 * sizeof (short) + sizeof (char) = 5 bytes. This is too bad. Because you do not pay attention to byte alignment, there will be a major problem in memory addressing. A better structure is as follows:
Struct CPOINT
{
Int x, y;
Int c;
} // End CPOINT

C ++
Tip: The structure (Struct) in C ++ is very similar to a Class, except that the default accessibility (Visibility) of the structure is PUBLIC.
This new structure is much better. First, all structure members have the same size-sizeof (int) = 4 bytes. Therefore, only one pointer can be used to access any structure member through the increment DWORD (double-byte, 2-byte) boundary. The size of the new structure is (3 * sizeof (int) = 12 bytes, a multiple of 4, or on the DWORD boundary. This will significantly improve the performance.
In fact, if you really want to be secure, you can properly fill in all the structures to make them a multiple of 32 bytes. 32 bytes is the width of the standard internal cache on the Pentium family central processor, so this is the best length. You can meet this requirement by filling in useless variables in the structure or using the compiler Directive (the simplest method. It is true that filling will waste a lot of memory, but it is often worthwhile to increase the speed.
Tips
Comment out your code. Game programmers do not comment out the code. Do not make the same mistake again. In order to get a neat and well-Annotated Code, a little additional typing is definitely worth it.
Tips
It is programmed in a way similar to a reduced instruction set computer. In other words, try to simplify your code, instead of making it more complex. Pentium-level processors prefer simple commands rather than complex commands. Your program can be longer, but you should try to use simple commands to make the program simpler than the compiler. For example, do not write such a program:
If (x + = (2 * buffer [index ++])> 10)
{
// Do work
} // End if
But we should write it like this:
X + = (2 * buffer [index]);
Index ++;

If (x> 10)
{
// Do work
} // End if
There are two reasons for writing code in this way. First, it allows the debugger to place breakpoints between various parts of the Code; second, it makes it easier for the compiler to send simple commands to the Pentium processor, this will allow the processor to use more execution units to process more code in parallel. Complicated code is too bad in this regard!
Tips
The binary shift operation is used to perform simple integer multiplication with a multiplier of the power of 2. Because all data is stored in binary in the computer, moving a group of bitwise elements to the left or right is equivalent to multiplication and division operations. For example:
Int y_pos = 10;

// Multiply y_pos by 64
Y_pos = (y_pos <6); // 2 ^ 6 = 64
Similar:
// To divide y_pos by 8
Y_pos = (y_pos> 3); // 1/2 ^ 3 = 1/8
In the chapter on Optimization in this book, you will find more similar skills.
Tips
Design efficient algorithms. No assembly language can make algorithms with the complexity of O (n2) run faster. A better way is to use clear and efficient algorithms instead of brute-force and exhaustive algorithms.
Tips
Do not optimize the code during programming. This is usually a waste of time. We recommend that you wait until the main code block or the entire program is completed before you begin to carry out heavy optimization work. In the end, this will save you time, because you do not have to perform unnecessary Optimization on some obscure code. When the game is basically completed, it is time to test the performance and find out the problems to be optimized. On the other hand, you should pay attention to errors in the program code, and do not make it messy.
Tips
Do not define too many complex data structures for simple objects. The linked list structure is very useful, but this does not mean that when you need a Fixed Array of about 256 elements, you should also use the linked list, you only need to allocate static memory for it. 90% of video game programming is data operations. Therefore, the data should be as simple and visible as possible so that it can be quickly accessed and operated at will. Make sure that your data structure is suitable for the problems you really want to solve.
Tips
Exercise caution when using C ++. If you are an experienced C ++ expert, just do what you want, but do not write too many classes frantically, do not overload anything ). After all, simple and intuitive code is the best program and easier to debug. I personally don't want to see multiple inheritance in the game code!
Tips
If you know your car is about to drive a bumpy stone road, the best way is to stop, turn around and make a detour. I have seen many game programmers walk along a very poor programming path until they bury themselves in a bad code stack. It is much better to be aware of your mistakes and re-compile 500 lines of code than to write a code structure that is always unpleasant. Therefore, if you discover problems at work, you need to reevaluate and ensure that the time saved is worthwhile.
Tips
Back up your work frequently. When writing game code, you need to lock the code in the code library quite frequently. It is easy to rewrite a sorting algorithm, but it is much more difficult to rewrite the role AI or rewrite the collision detection.
Tips
Before starting your game project, you should organize your work. Use a reasonable file name and directory name to propose a consistent variable naming convention. Try to use separate directories for graphics and sound data, instead of putting everything in the same directory.
Tools used
In the past, video games usually only needed a text editor, and perhaps a self-made drawing program. But now it becomes more complicated. At least, you need a C/C ++ compiler, a 2D drawing program, and a sound processing program. In addition, if you want to write a 3D game, you may need a 3D modeling software. If you want to use any MIDI device, you also need to prepare a music sorting program.
Let's take a look at the popular products and their functions.
C/C ++ Compiler
For Windows 9X/NT platform development, there is no better compiler than ms vc ++ 6.0 +. It can do anything, or even more. It can generate the fastest. EXE executable code. Borland compiler can also work well (and it is much cheaper), but it has fewer feature settings. Whether it is MS or Borland, you do not need the complete version of any of the above compilers. A student version that can generate the. EXE file on the Win32 platform is enough.
2D art software
You can buy graphics software, drawing software, and image processing software. You can use the graphics software to draw and process images one by one pixel. As far as I know, JASC's Paint Shop Pro is a cost-effective image software package. ProCreate Painter (formerly Fractal Design Painter) is also good, but it is more suitable for traditional artists and expensive. I personally like to use Corel Photo-Paint, but for new users, its functions are indeed a bit too much.
On the other hand, the plotting software allows the reader to create images primarily composed of curves, straight lines, and basic 2D ry. This type of software is not often used in game development, but Adobe Illustrator is a good choice if you need it.
The last class of 2D art software is used for image processing. These programs are mostly used for post-production of products, rather than early artistic creations. Adobe Photoshop is a favorite software, but I think Corel Photo-Paint is better. The so-called benevolent sees benevolence, the wise sees wisdom.
Sound Processing Software
Currently, all sound effects (SFX) 90% for games are digital samples. Using this type of sound data to work, readers should need a digital sound processing software. The best program in this type is Sound Forge Xp. It has quite complex sound processing functions and is easy to use.
3D modeling software
This is a software that challenges economic strength. 3D styling software may be priced at tens of thousands of dollars. However, many low-price 3D styling software has been released recently, and their functions are powerful enough to make a video. I mainly use Caligari TrueSpace, a simple to moderately complex 3D styling and animation software. At the corresponding price, this is the best 3D modeling software, which only requires hundreds of dollars and has the best interface.
If you want to be more powerful and want to be absolutely realistic like photography, 3D Studio Max can help you. However, it costs about $2500, so you should consider it carefully. However, if we use these styling software to create only 3D styles (Mesh) instead of screen rendering, no other advanced features are required. In this way, TureSpace is sufficient.
Music and MIDI sorting program
There are two types of music in the current game: Pure Digital (like CD) and MIDI (Musical instruments Digital Interface, Musical Instrument Digital Interface, MIDI is a synthetic sound that records the notes. If you want to make MIDI information and music, you also need a sorting software (also known as sequencer software ). One of the most cost-effective software packages is Cakewalk. Therefore, if you plan to record and make MIDI music, it is recommended that you know about the software. In chapter 1 "using DirectSound and DirectMusic to play music", we will further discuss the MIDI data.
Tips
Good news: some software vendors I mentioned above allow me to put their shared version or trial versions on the CD attached to this book. We recommend that you have a try!
From preparation to completion -- use the Compiler
One of the most frustrating aspects of learning Windows game programming is learning to use compilers. It is common for beginners who are so excited to start programming game programs that they just put into the IDE (integrated development environment) and try to compile, then there are thousands of compilation and connection errors! To avoid this problem, let's first review some basic concepts about compilers.
1. Please be sure to fully read the instructions included in the compiler!
2. Install DirectX SDK (DirectX software development kit and DirectX software development kit) in the system ). All you have to do is find Directory, read the readme. txt file, and follow the instructions (in fact, it is just "double-click the install. exe program in DirectX SDK ").
3. We want to develop Win32. EXE programs, rather than. DLL files or ActiveX components. Therefore, if you want to smoothly compile and pass through, the first thing you need to do is to use the compiler to create a new project or work zone, and then set the target output file to. EXE in the Win32 environment. Using the VC ++ 6.0 Compiler for this step 1.6 is shown.
Figure 1.6 create a Win32. EXE file using Visual C ++ 6.0
 
4. Use the add files command from the main menu or project to add source code files to the project. The procedure of using the VC ++ 6.0 compiler is as follows: 1.7.
Figure 1.7 Add a file to a project using VC ++ 6.0
 
5. From the chapter on DirectX, you must include the majority of DirectX COM interface library files shown in 1.8 in the project.
O ddraw. Lib
O dsound. Lib
O dinput. Lib
O dinput8.lib
O dsetup. lib *
Note: dsetu. Lib is not required unless you are using directsetup.
Figure 1.8 resources required to create a Win32. EXE Application
 
O
These DirectX. LIB files are located in the LIB subdirectory under the installed DirectX SDK directory. These. LIB library files must also be added to the reader's project or work zone. You cannot add only the search path, because the search engine may find the old DirectX 3.0. LIB file in the library file that comes with the compiler. In this case, you need to add Windows multimedia extension library -- WINMM. LIB to the project. This file is located in the LIB subdirectory under the compiler installation directory.
6. After preparation, compile your program.
Warning
If you are a Borland user, the DirectX SDK has a separate directory to store Borland library files. Therefore, make sure to add these. LIB files instead of the MS-compatible files at the upper level in the directory tree to the project.
If you still have questions, do not worry. This book will review these steps multiple times when discussing Windows programming and DirectX for the first time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.