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
//-----------------------------------------------------------------------------
// Shield implementation.
//-----------------------------------------------------------------------------

#include "NetWars.h"

//-----------------------------------------------------------------------------
// The Shield class constructor.
//-----------------------------------------------------------------------------
Shield::Shield( float x, float y, float radius ) 
{	

	m_objectType = "Shield";

	m_shieldRadius = 10.0f;
	m_weaponRadius = 3.0f;

	UpdateShieldRadius( radius );
}

//-----------------------------------------------------------------------------
// The Shield UpdateShieldRadius creates the vetex buffer with 
// the vertexes for the defined radius. 
//-----------------------------------------------------------------------------
void Shield::UpdateShieldRadius( float radius )
{

	static float shortDist = 0.5f;
	static float longDist = 0.866f;
	m_radius = radius;

	simplevertex vertices[] =
	{
		{ 1.0f * m_radius, 0.0f, 0.0f }, 
		{ longDist * m_radius, shortDist * m_radius, 0.0f, },
		{ shortDist * m_radius, longDist * m_radius, 0.0f, }, 
		{ 0.0f,  1.0f * m_radius, 0.0f, }, 
		{ -shortDist * m_radius, longDist * m_radius, 0.0f }, 
		{ -longDist * m_radius, shortDist * m_radius, 0.0f, },
		{ -1.0f * m_radius, 0.0f, 0.0f }, 
		{ -longDist * m_radius, -shortDist * m_radius, 0.0f, },
		{ -shortDist * m_radius, -longDist * m_radius, 0.0f, }, 
		{ 0.0f, -1.0f * m_radius, 0.0f }, 
		{ shortDist * m_radius, -longDist * m_radius, 0.0f, },
		{ longDist * m_radius, -shortDist * m_radius, 0.0f, }, 
		{ 1.0f * m_radius, 0.0f, 0.0f },
	};


	int numberOfVerticies = (int) sizeof( vertices ) / sizeof( simplevertex );
	CreateVertexBuffer( vertices, numberOfVerticies );

	//m_shieldRadius = 10.0f;

}

//-----------------------------------------------------------------------------
// The Shield Method that creates the Physical body.
//-----------------------------------------------------------------------------
void Shield::SetUpPhysics( float x, float y )
{
	// The Shield's Physics are not set up yet.
	m_physicalBody = false;
}

//-----------------------------------------------------------------------------
// The SpaceShip Method that creates the Shield Weapon Body.
//-----------------------------------------------------------------------------
void Shield::Fire( float x, float y, float angle )
{
	UpdateShieldRadius( m_weaponRadius );
	SetUpWeaponBody( x, y );
	m_Body->SetLinearVelocity( 10000.0f * b2Vec2( -cos(angle), sin(angle)));

}

//-----------------------------------------------------------------------------
// The SpaceShip Method that re-attaches the Shield Body to the ship.
//-----------------------------------------------------------------------------
void Shield::Attach( )
{
	UpdateShieldRadius( m_shieldRadius );
	DestroyWeaponBody( );
}

//-----------------------------------------------------------------------------
// The SpaceShip Method that creates the Shield Weapon Body.
//-----------------------------------------------------------------------------
void Shield::DestroyWeaponBody(  )
{
	g_Engine->GetB2D()->RemoveBody( m_Body );
}

//-----------------------------------------------------------------------------
// The SpaceShip Method that creates the Shield Weapon Body.
//-----------------------------------------------------------------------------
void Shield::SetUpWeaponBody( float x, float y )
{
	// Set up the b2D Body Def:
	b2BodyDef bodyDef;
	bodyDef.position.Set(-x, y);
	bodyDef.allowSleep = false;
	
	// Set up the b2D Body Def:
	b2CircleDef circleDef;
	circleDef.radius = 3.0f;
	circleDef.density = 1.0f;
	circleDef.friction = 0.0f;
	circleDef.restitution = 1.0f;

	g_Engine->GetB2D()->AddBody( &m_Body, &bodyDef, &circleDef );

	m_physicalBody = true;
}