You are viewing the NetWars Project

The entrance (WinMain) to the application is in NetWars.cpp. It is currently utilizing DirectX, D3DX, XInput (360 controller), Box2D and eventually Enet for networking.

Last Updated 5/30/08

B2DWrapper.cpp
B2DWrapper.h
Engine.cpp
Engine.h
GameBorder.cpp
GameBorder.h
LinkedList.h
NetWars.cpp
NetWars.h
SceneObject.cpp
SceneObject.h
Shield.cpp
Shield.h
SimpleWindow.cpp
SimpleWindow.h
SpaceShip.cpp
SpaceShip.h
UserInput.cpp
UserInput.h

Zips :
The zip file contains the exe and the dll's needed to run the application.

NetWars.zip


Syntax Highlighting by: SyntaxHighlighter
//-----------------------------------------------------------------------------
// Box2D Wrapper implementation.
// This will server as a wrapper for the Box2D library:
// http://box2d.org/ 
//-----------------------------------------------------------------------------

#include "NetWars.h"

//-----------------------------------------------------------------------------
// The B2DWrapper class constructor.
//-----------------------------------------------------------------------------
B2DWrapper::B2DWrapper()
{
	m_worldAABB.lowerBound.Set(-200.0f, -200.0f);
	m_worldAABB.upperBound.Set(200.0f, 200.0f);
	b2Vec2 gravity;
	gravity.Set(0.0f, 0.0f);
	bool doSleep = true;
	m_world = new b2World( m_worldAABB, gravity, doSleep );

	
	// Creating the Box2D GameBorder:
	b2BodyDef groundBodyDef;
	groundBodyDef.massData.mass = 0.0f;

	// Lower Border
	groundBodyDef.position.Set(  0.0f, -GAMEBORDER_HEIGHT - 10.0f );
	b2Body* groundBody = m_world->CreateBody(&groundBodyDef);
	b2PolygonDef groundShapeDef;
	groundShapeDef.SetAsBox(GAMEBORDER_WIDTH, 10.0f);
	groundBody->CreateShape(&groundShapeDef);

	// Upper Border
	groundBodyDef.position.Set(  0.0f, GAMEBORDER_HEIGHT + 10.0f );
	groundBody = m_world->CreateBody(&groundBodyDef);
	groundShapeDef.SetAsBox(GAMEBORDER_WIDTH, 10.0f);
	groundBody->CreateShape(&groundShapeDef);

	// Right Border
	groundBodyDef.position.Set( GAMEBORDER_WIDTH + 10.0f, 0.0f );
	groundBody = m_world->CreateBody(&groundBodyDef);
	groundShapeDef.SetAsBox( 10.0f, GAMEBORDER_HEIGHT);
	groundBody->CreateShape(&groundShapeDef);

	// Left Border
	groundBodyDef.position.Set( -GAMEBORDER_WIDTH - 10.0f, 0.0f );
	groundBody = m_world->CreateBody(&groundBodyDef);
	groundShapeDef.SetAsBox( 10.0f, GAMEBORDER_HEIGHT );
	groundBody->CreateShape(&groundShapeDef);
	 
}

//-----------------------------------------------------------------------------
// The B2DWrapper class destructor.
//-----------------------------------------------------------------------------
B2DWrapper::~B2DWrapper()
{
	SAFE_DELETE( m_world );
}


/// Updates the Box2D System with the elapsed time.
/// @param elapsedTime since the previous frame
void B2DWrapper::Update( float elapsedTime )
{
	m_world->Step( elapsedTime, 10 );
}


/// Adds a new body to the Box2D physics system
/// @param   b2BodyDef bodyDef of new body
/// @param   b2ShapeDef shapeDef of new body
/// returns a pointer to the body 
void B2DWrapper::AddBody( b2Body ** body, b2BodyDef * bodyDef, b2ShapeDef * shapeDef )
{
	(*body) = m_world->CreateBody( bodyDef );
	(*body)->CreateShape( shapeDef );
	(*body)->SetMassFromShapes();
}


/// Removes a body from the Box2D physics system
/// @param   b2BodyDef the bodyDef to remove
void B2DWrapper::RemoveBody( b2Body * body )
{
	m_world->DestroyBody( body );
}