Authoring a Brush Entity/Code

From Valve Developer Community
Jump to navigation Jump to search

search engines ointment free online poker activex coupons prevacid bupropion alltel cellular phone traffic lights canon camera airline ticket bid surgical instrument travel brazil play roulette online buy use car food gift baskets mexicana airline registration numbers car rental kaiser permanente bridal dress halloween prop synthroid watch replica buy adipex online medical insurance designer wedding gowns modem sexy halloween costumes download songs security jobs awning virgins bars psychics virginia birth certificate small business grants buy viagra cheap cheap laptops sony computer black canon printers shower curtain rings aciphex online lee jean dildo asian jet ski insurance cheapest airplane tickets free t mobile phone business plan lose weight while you sleep handbags replica volvo dealerships roulette bluetooth technology airline schedules lawn tractors renault car dealers best casino online vegas hotels public auto auction dexter shoe real estate in surfside beach south carolina carhartt sports bras corelle free ringer downloads ringtone software free antivirus download free virus scan work at home mom cherokee cheap airline ticket international kitchen sex webcam free credit report no credit card patio umbrella gas pump friendship home decor dell computers home businesses akai costume pirate wicked tickets indiana foreclosure psychic clonidine t mobile candy start a business football betting nokia play game coffee grinder watch didrex diplomas the game

//===== 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 );
}