Authoring a Brush Entity/Code

From Valve Developer Community
Jump to navigation Jump to search

employment in san antonio texas page advance card credit no global warming 3 doors down pokemon cards sony playstation reverend dean honda generator parts discount wedding invitation used dirt bike engines algebric formula equipping force rapid stephen miller japan cigarette sale monty python spamalot ticket rocket launch video birthday party supplies free sprint pcs ringtones mobility scooter small fish image low frequency pulse measuring transducer john shepherd vaughan and co university of florida womens basketball tube amplification effects of slave trade on africa urban golf game pioneer dvd remote palm software development tools mouth herpes free virus scan sleeping during the day i hide away safe children samsung cell phone index houston rockets south africa police services knowledge management model business card paper glossy translate latvian search engine marketing boston inventor tutorial personal checks six security services paid in full album cover american legal reform url ashley furniture company social network maps black jack prices of petrol acrage for sale in texas the simpsons aria movie clips monahan pat ics collection agency terri lynch application for extension of time texas release of lien form iron serum levels glucose spain 92 nj sherry north overnight tramadol add animal bite link la weightloss successful home businesses illinois missing child alabama segregation laws download free music air canada reservation in situ definition science cingular go phone prepaid no such thing as a witch eating disorder million dollars picture pro tect security the star spangled banner porno sites airline continental reservation metal sign western index academy award winning documentaries artificial flowers in the uk mobic ancient greek writing pictures paper cutter phentermine cheap best 6 month cd rates make a wish foundation of central florida phase correlation method elysian fields texas department state health services ocean city webcams free hardcore porn graphic design amd 64 computers page free online dating teen thumb tgp

//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ========
//
// Purpose: Simple brush entity that moves when touched
//
//=============================================================================

#include "cbase.h"

class CMyBrushEntity : public CBaseToggle
{
public:
	DECLARE_CLASS( CMyBrushEntity, CBaseToggle );
	DECLARE_DATADESC();

	void Spawn( void );
	bool CreateVPhysics( void );

	void BrushTouch( CBaseEntity *pOther );
};

LINK_ENTITY_TO_CLASS( my_brush_entity, CMyBrushEntity );

// Start of our data description for the class
BEGIN_DATADESC( CMyBrushEntity )
	
	// Declare this function as being a touch function
	DEFINE_ENTITYFUNC( BrushTouch ),

END_DATADESC()

//-----------------------------------------------------------------------------
// Purpose: Sets up the entity's initial state
//-----------------------------------------------------------------------------
void CMyBrushEntity::Spawn( void )
{
	// We want to capture touches from other entities
	SetTouch( &CMyBrushEntity::BrushTouch );

	// We should collide with physics
	SetSolid( SOLID_VPHYSICS );
	
	// We push things out of our way
	SetMoveType( MOVETYPE_PUSH );
	
	// Use our brushmodel
	SetModel( STRING( GetModelName() ) );

	// Create our physics hull information
	CreateVPhysics();
}

//-----------------------------------------------------------------------------
// Purpose: Setup our physics information so we collide properly
//-----------------------------------------------------------------------------
bool CMyBrushEntity::CreateVPhysics( void )
{
	// For collisions with physics objects
	VPhysicsInitShadow( false, false );

	return true;
}

//-----------------------------------------------------------------------------
// Purpose: Move away from an entity that touched us
// Input  : *pOther - the entity we touched
//-----------------------------------------------------------------------------
void CMyBrushEntity::BrushTouch( CBaseEntity *pOther )
{
	// Get the collision information
	const trace_t &tr = GetTouchTrace();

	// We want to move away from the impact point along our surface
	Vector	vecPushDir = tr.plane.normal;
	vecPushDir.Negate();
	vecPushDir.z = 0.0f;

	// Move slowly in that direction
	LinearMove( GetAbsOrigin() + ( vecPushDir * 64.0f ), 32.0f );
}