Games and File IO


Games and File I/O

Other than a game's program file, all types of files that a game uses must either be read from or written to. For example, games often need configuration files. Reading the configuration file is done by performing file I/O.

Games process a huge amount of information that they get from reading level files, which you learned about in chapter 11, "Pointers." Each level has its own monsters, enemies, bad guys, or other type of opponents. Level files specify exactly what opponents occur in a level and where they are positioned when they appear. They also usually tell the program which files to read to load the bitmap for the opponent's sprite. In addition, they specify the sound files to play when the opponent makes any kind of noise. Level files can contain information about which music files to play during the level. Your game must read the level file, the bitmap files, and the sound files into memory.

Games must save the player's progress. To do so, they write the player's current progress information to a file. Game programmers often call this file the save file.

If you use a game engine, it will usually handle a lot of the file I/O tasks that your game needs to perform. For example, LlamaWorks2D reads bitmap images for sprites when your game calls the sprite::LoadImage() function. It also performs file I/O when your program invokes the sound::LoadWAV() function.

As helpful as they are, game engines cannot do all of your file I/O for you. Only you know exactly what you want in your level files. You are also the only one who can determine what goes into a save file. Therefore, you must become proficient with file I/O. Fortunately, it isn't difficult to grasp.

There is one thing you need to keep in mind relative to file I/O: file I/O is always slow. That's because disk drives, such as CD-ROMs, DVD-ROMs, and even hard drives operate much slower than a computer's microprocessor. Because file I/O is so slow, it may cause the game to actually pause for a moment. Of course, you don't want that to happen while a level is running; it gets players quite irritated. Therefore, your game must perform its file I/O between levels. Players expect a natural pause before and after each level, so your game can do its file I/O between levels without making them upset.



Creating Games in C++(c) A Step-by-Step Guide
Creating Games in C++: A Step-by-Step Guide
ISBN: 0735714347
EAN: 2147483647
Year: N/A
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net