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.

121 lines
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "particles_simple.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. class C_WaterBullet : public C_BaseAnimating
  11. {
  12. public:
  13. DECLARE_CLIENTCLASS();
  14. DECLARE_CLASS( C_WaterBullet, C_BaseAnimating );
  15. C_WaterBullet( void ) {};
  16. ~C_WaterBullet( void ) {};
  17. void OnDataChanged( DataUpdateType_t updateType )
  18. {
  19. BaseClass::OnDataChanged( updateType );
  20. if ( updateType == DATA_UPDATE_CREATED )
  21. {
  22. m_pEmitter = CSimpleEmitter::Create( "FX_Bubble" );
  23. m_pEmitter->SetSortOrigin( GetAbsOrigin() );
  24. m_vecLastOrigin = GetAbsOrigin();
  25. }
  26. }
  27. #define BUBBLES_PER_INCH 0.2
  28. void AddEntity( void )
  29. {
  30. Vector direction = GetAbsOrigin() - m_vecLastOrigin;
  31. float flDist = VectorNormalize( direction );
  32. int numBubbles = (int) ( flDist * BUBBLES_PER_INCH );
  33. if ( numBubbles < 1 )
  34. numBubbles = 1;
  35. // Make bubbles
  36. SimpleParticle *sParticle;
  37. Vector offset;
  38. for ( int i = 0; i < numBubbles; i++ )
  39. {
  40. offset = m_vecLastOrigin + ( direction * ( flDist / numBubbles ) * i ) + RandomVector( -2.5f, 2.5f );
  41. sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_pEmitter->GetPMaterial( "effects/bubble" ), offset );
  42. if ( sParticle )
  43. {
  44. sParticle->m_flLifetime = 0.0f;
  45. sParticle->m_flDieTime = random->RandomFloat( 0.75f, 1.25f );
  46. sParticle->m_flRoll = 0;
  47. sParticle->m_flRollDelta = 0;
  48. unsigned char color = random->RandomInt( 128, 255 );
  49. sParticle->m_uchColor[0] = color;
  50. sParticle->m_uchColor[1] = color;
  51. sParticle->m_uchColor[2] = color;
  52. sParticle->m_uchStartAlpha = 255;
  53. sParticle->m_uchEndAlpha = 0;
  54. sParticle->m_uchStartSize = random->RandomInt( 1, 2 );
  55. sParticle->m_uchEndSize = sParticle->m_uchStartSize;
  56. sParticle->m_vecVelocity = ( direction * 64.0f ) + Vector( 0, 0, 32 );
  57. }
  58. sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_pEmitter->GetPMaterial( "effects/splash2" ), offset );
  59. if ( sParticle )
  60. {
  61. sParticle->m_flLifetime = 0.0f;
  62. sParticle->m_flDieTime = 0.2f;
  63. sParticle->m_flRoll = random->RandomInt( 0, 360 );
  64. sParticle->m_flRollDelta = random->RandomInt( -4, 4 );
  65. unsigned char color = random->RandomInt( 200, 255 );
  66. sParticle->m_uchColor[0] = color;
  67. sParticle->m_uchColor[1] = color;
  68. sParticle->m_uchColor[2] = color;
  69. sParticle->m_uchStartAlpha = 128;
  70. sParticle->m_uchEndAlpha = 0;
  71. sParticle->m_uchStartSize = 2;
  72. sParticle->m_uchEndSize = sParticle->m_uchStartSize * 4;
  73. sParticle->m_vecVelocity = ( direction * 64.0f ) + Vector( 0, 0, 32 );
  74. }
  75. }
  76. // Save our last position
  77. m_vecLastOrigin = GetAbsOrigin();
  78. BaseClass::AddEntity();
  79. }
  80. bool ShouldDraw( void ) { return true; }
  81. private:
  82. C_WaterBullet( const C_WaterBullet & );
  83. CSmartPtr<CSimpleEmitter> m_pEmitter;
  84. Vector m_vecLastOrigin;
  85. };
  86. IMPLEMENT_CLIENTCLASS_DT( C_WaterBullet, DT_WaterBullet, CWaterBullet )
  87. END_RECV_TABLE()