How Does Llamaworks2D Work?


LlamaWorks2D is built around objects. Remember how I said in chapter 3 that objects could represent anything? LlamaWorks2D uses that ability to hide many of the mundane tasks of game programming from you. That's a good thing. The tasks it hides from you are the ones that are not directly related to making games. They're all about Windows and OpenGL.

LlamaWorks2D uses an application object and a game object to do most of its work. The application object represents the program itself. The game object is your game class that you saw back in Listing 4.1 Figure 4.1 illustrates how these objects work.

Figure 4.1. The design of LlamaWorks2D.


Warning

When you follow the instructions presented here to create and compile your program, the compiler names the program SimpleGame.exe. On the CD, I've provided a compiled version of this program. However, it's called Prog_ 04_01.exeI did that to make it easier to figure out which program goes with which example. When you're writing games, the name of your game's executable file should be something that resembles the name of the game.


The game object in Figure 4.1 represents the portion of the program that is your game. When you write a game with LlamaWorks2D, you put all of your game's data and all of the functions that make your game operate into your game class. Note that you can also define other classes that your game class uses. But the code that defines what your game is and how it works goes into the game class. Of all the objects in Figure 4.1, the game class is the only one you write. LlamaWorks2D provides you with the message objects, sprite objects (I'll explain sprite objects later in this chapter when we create a stationary ball), and the application object.

By using an application object and a game object, you ensure that your game code is separated from the code that makes the overall program run. That means you don't have to bother with the code that gets Windows and OpenGL up and running. You don't have to know all of the ins and outs of handling user input (there are many). Figure 4.1 shows that player input comes into the application object, which packages that input as message objects that your game can handle fairly easily.

Note

You may be wondering whether you should learn how to initialize Windows and OpenGL yourself. The answer is yes, but not now. When you feel like you're a proficient C++ programmer, feel free to go through the source code for LlamaWorks2D. It will help you learn both Windows and OpenGL programming. Also, you should go through the Windows and OpenGL programming documentation at www.msdn.microsoft.com.


In addition, you don't have to know how OpenGL does bitmap animation. It's not a topic most beginners want to tackle. Instead, LlamaWorks2D provides a sprite object that handles all that for you. Almost all the animation you do in 2D games can be handled with just the sprite class.

As you become more proficient with C++, Windows, and OpenGL, you can easily enhance or customize the objects LlamaWorks2D provides. There is nothing in LlamaWorks2D that prevents you from adding your own objects. You can even bypass any of the engine's components and handle the tasks yourself. This enables you to perform those tasks in the way that is best for your game.

2LlamaWorks2D creates an application object itself. However, the engine does need a bit of configuration information to do so. If you don't provide that information (we didn't in Listing 4.1), LlamaWorks2D uses a reasonable set of default values. The application object is accessible from anywhere in the program. It is the only object in the program that is set up that way.

LlamaWorks2D also creates the game object using your game class when you use the macro CREATE_GAME_OBJECT(). Functions in your game will need to access the game object at times. When they do, they call a function in the application object that provides them with access to the game object. The name of that function is Game().



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