Initializing Ping

Initializing the Game Initializing Ping is a more complex task than you might think. To initialize Ping, the program must do the following tasks: 1. Set the size of the playable area. 2. Load the ball’s image. 3. Initialize all of the ball’s member data except the position and movement vector. 4. Load the bitmap for the paddles. 5. Initialize all of the paddles’ member data except the position and movement vectors. 6. Load the bitmap for the score markers. 7. Load...

read more

Writing a Game Called Ping in C++ (Part 2)

Mapping Other Windows Messages LlamaWorks2D enables you to connect, or map, any Windows message to any function you want. To make this happen, use the LlamaWorks2d ONMESSAGE() macro. For example, if you want to map the message WM_ACTIVATE to a function in your game class named OnActivate(), you can do so by putting the following statement in your game’s message map: ONMESSAGE(WM_ACTIVATE, OnActivate) This statement tells the game engine to automatically call the OnActivate() function any time the game receives a WM_ACTIVATE...

read more

Writing a Game Called Ping in C++ (Part1)

Introducing Ping Ping is a simple two-player game modeled on ping-pong. The ball is served randomly to the left or right player. When the ball moves toward a player’s paddle, the player moves the paddle up or down to block the progress of the ball. If the ball hits the paddle, it bounces back toward the other side. If not, it passes off the edge of the screen. When it leaves the screen, the player on the opposite side scores a point. Whenever a player scores a point, a small red dot appears on that player’s side of the screen...

read more

File Structure of a Game (C++)

After you’ve figured out what objects a game needs and the tasks it performs, designing the game’s file structure is fairly straightforward. For each class you define, you should create a .h and a .cpp file. The .h file holds the class definition and the inline member functions. The .cpp file contains the member functions that are too big or too complex to be inline. That’s all there is to it. If you follow these guidelines, you’ll find it easy to use your objects in your game. Recall that the LlamaWorks2D game...

read more

Designing Game Tasks in C

Although each game you write is unique, nearly every game performs the same set of basic tasks, which are listed below. After you’ve written code for these tasks for a couple of games, you will become very proficient at it. As a result, you’ll be able to rapidly move into the tasks that are unique to the game you’re working on. Factoid Game programmers have various terms for the message loop. They may call it the update loop, the rendering loop, the main game loop, or the game loop. Game initialization During game ...

read more

Object-Oriented Programming

Classes To define objects in C++, you create classes. Defining your own classes is actually easier than explaining it. So rather than starting with a long explanation, let’s go through the sample program below (Listing1): #include <cstdlib> 2 #include <iostream> 3 4 using namespace std; 5 6 class my_object 7 { 8 public: 9 int i; 10 float f; 11 }; 12 13 int main(int argc, char *argv[]) 14 { 15 my_object anObject; 16 17 anObject.i = 10; 18 anObject.f =...

read more