Box2D Getting Started
Chapter 5 of Ian Parberry's "Introduction to Game Physics with Box2D"
 All Classes Files Functions Variables Enumerations Pages
Functions | Variables
MyGame.cpp File Reference

Main file for your game. More...

#include "gamedefines.h"
#include "SndList.h"
#include "Box2D\Box2D.h"
#include "RenderWorld.h"
#include "ObjectWorld.h"

Functions

b2World g_b2dPhysicsWorld (b2Vec2(0, RW2PW(-100)))
 Box2D Physics World.
 
int DefaultWinMain (HINSTANCE, HINSTANCE, LPSTR, int)
 
LRESULT CALLBACK DefaultWindowProc (HWND, UINT, WPARAM, LPARAM)
 
void CreateWorldEdges ()
 
void CreateBook (float x, float y)
 
void CreateBall (float x, float y)
 
void CreateObjects ()
 Create all game objects.
 
void BeginGame ()
 Start the game.
 
void InitGame ()
 Initialize and start the game.
 
void EndGame ()
 Shut down game and release resources.
 
void RenderFrame ()
 Render a frame of animation.
 
void ProcessFrame ()
 
BOOL KeyboardHandler (WPARAM k)
 
LRESULT CALLBACK WindowProc (HWND h, UINT m, WPARAM w, LPARAM l)
 
int WINAPI WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR lpC, int nCS)
 

Variables

char g_szGameName [256]
 Name of this game.
 
CTimer g_cTimer
 The game timer.
 
CSoundManager * g_pSoundManager
 The sound manager.
 
CRenderWorld g_cRenderWorld
 The Render World.
 
CObjectWorld g_cObjectWorld
 The Object World.
 

Detailed Description

Main file for your game.

Function Documentation

void CreateBall ( float  x,
float  y 
)

Place a ball in Physics World and Object World.

Parameters
xHorizontal coordinate in Physics World units.
yVertical coordinate in Physics World units.
void CreateBook ( float  x,
float  y 
)

Place a book in Physics World and Object World.

Parameters
xHorizontal coordinate in Physics World units.
yVertical coordinate in Physics World units.
void CreateWorldEdges ( )

Create world edges in Physics World. Place Box2D edge shapes in the Physics World in places that correspond to the top, bottom, right, and left edges of the screen in Render World. The left and right edges continue upwards for a distance. There is no top to the world.

BOOL KeyboardHandler ( WPARAM  k)

Keyboard handler. Take the appropriate action when the user mashes a key on the keyboard.

Parameters
kVirtual key code for the key pressed
Returns
TRUE if the game is to exit
void ProcessFrame ( )

Process a frame of animation. Called once a frame to animate game objects and take appropriate action if the player has won or lost.

LRESULT CALLBACK WindowProc ( HWND  h,
UINT  m,
WPARAM  w,
LPARAM  l 
)

Window procedure. Handler for messages from the Windows API. Dont mess with these unless you really know what you're doing.

Parameters
hwindow handle
mmessage code
wparameter for message
lsecond parameter for message
Returns
0 if message is handled
int WINAPI WinMain ( HINSTANCE  hI,
HINSTANCE  hP,
LPSTR  lpC,
int  nCS 
)

Winmain. Main entry point for this application. Dont mess with these unless you really know what you're doing.

Parameters
hIhandle to the current instance of this application
hPunused
lpCunused
nCSspecifies how the window is to be shown
Returns
TRUE if application terminates correctly