Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Simple brush entity that moves when touched
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. class CMyBrushEntity : public CBaseToggle
  8. {
  9. public:
  10. DECLARE_CLASS( CMyBrushEntity, CBaseToggle );
  11. DECLARE_DATADESC();
  12. void Spawn( void );
  13. bool CreateVPhysics( void );
  14. void BrushTouch( CBaseEntity *pOther );
  15. };
  16. LINK_ENTITY_TO_CLASS( my_brush_entity, CMyBrushEntity );
  17. // Start of our data description for the class
  18. BEGIN_DATADESC( CMyBrushEntity )
  19. // Declare this function as being a touch function
  20. DEFINE_ENTITYFUNC( BrushTouch ),
  21. END_DATADESC()
  22. //-----------------------------------------------------------------------------
  23. // Purpose: Sets up the entity's initial state
  24. //-----------------------------------------------------------------------------
  25. void CMyBrushEntity::Spawn( void )
  26. {
  27. // We want to capture touches from other entities
  28. SetTouch( &CMyBrushEntity::BrushTouch );
  29. // We should collide with physics
  30. SetSolid( SOLID_VPHYSICS );
  31. // We push things out of our way
  32. SetMoveType( MOVETYPE_PUSH );
  33. // Use our brushmodel
  34. SetModel( STRING( GetModelName() ) );
  35. // Create our physics hull information
  36. CreateVPhysics();
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose: Setup our physics information so we collide properly
  40. //-----------------------------------------------------------------------------
  41. bool CMyBrushEntity::CreateVPhysics( void )
  42. {
  43. // For collisions with physics objects
  44. VPhysicsInitShadow( false, false );
  45. return true;
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose: Move away from an entity that touched us
  49. // Input : *pOther - the entity we touched
  50. //-----------------------------------------------------------------------------
  51. void CMyBrushEntity::BrushTouch( CBaseEntity *pOther )
  52. {
  53. // Get the collision information
  54. const trace_t &tr = GetTouchTrace();
  55. // We want to move away from the impact point along our surface
  56. Vector vecPushDir = tr.plane.normal;
  57. vecPushDir.Negate();
  58. vecPushDir.z = 0.0f;
  59. // Move slowly in that direction
  60. LinearMove( GetAbsOrigin() + ( vecPushDir * 64.0f ), 32.0f );
  61. }