diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /sp/src/game/client/hl2/c_waterbullet.cpp | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'sp/src/game/client/hl2/c_waterbullet.cpp')
| -rw-r--r-- | sp/src/game/client/hl2/c_waterbullet.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/sp/src/game/client/hl2/c_waterbullet.cpp b/sp/src/game/client/hl2/c_waterbullet.cpp new file mode 100644 index 00000000..2b05ebee --- /dev/null +++ b/sp/src/game/client/hl2/c_waterbullet.cpp @@ -0,0 +1,121 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================//
+
+#include "cbase.h"
+#include "particles_simple.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+class C_WaterBullet : public C_BaseAnimating
+{
+public:
+
+ DECLARE_CLIENTCLASS();
+ DECLARE_CLASS( C_WaterBullet, C_BaseAnimating );
+
+ C_WaterBullet( void ) {};
+ ~C_WaterBullet( void ) {};
+
+ void OnDataChanged( DataUpdateType_t updateType )
+ {
+ BaseClass::OnDataChanged( updateType );
+
+ if ( updateType == DATA_UPDATE_CREATED )
+ {
+ m_pEmitter = CSimpleEmitter::Create( "FX_Bubble" );
+ m_pEmitter->SetSortOrigin( GetAbsOrigin() );
+
+ m_vecLastOrigin = GetAbsOrigin();
+ }
+ }
+
+#define BUBBLES_PER_INCH 0.2
+
+ void AddEntity( void )
+ {
+ Vector direction = GetAbsOrigin() - m_vecLastOrigin;
+ float flDist = VectorNormalize( direction );
+
+ int numBubbles = (int) ( flDist * BUBBLES_PER_INCH );
+
+ if ( numBubbles < 1 )
+ numBubbles = 1;
+
+ // Make bubbles
+ SimpleParticle *sParticle;
+
+ Vector offset;
+
+ for ( int i = 0; i < numBubbles; i++ )
+ {
+ offset = m_vecLastOrigin + ( direction * ( flDist / numBubbles ) * i ) + RandomVector( -2.5f, 2.5f );
+
+ sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_pEmitter->GetPMaterial( "effects/bubble" ), offset );
+
+ if ( sParticle )
+ {
+ sParticle->m_flLifetime = 0.0f;
+ sParticle->m_flDieTime = random->RandomFloat( 0.75f, 1.25f );
+
+ sParticle->m_flRoll = 0;
+ sParticle->m_flRollDelta = 0;
+
+ unsigned char color = random->RandomInt( 128, 255 );
+
+ sParticle->m_uchColor[0] = color;
+ sParticle->m_uchColor[1] = color;
+ sParticle->m_uchColor[2] = color;
+ sParticle->m_uchStartAlpha = 255;
+ sParticle->m_uchEndAlpha = 0;
+ sParticle->m_uchStartSize = random->RandomInt( 1, 2 );
+ sParticle->m_uchEndSize = sParticle->m_uchStartSize;
+
+ sParticle->m_vecVelocity = ( direction * 64.0f ) + Vector( 0, 0, 32 );
+ }
+
+ sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_pEmitter->GetPMaterial( "effects/splash2" ), offset );
+
+ if ( sParticle )
+ {
+ sParticle->m_flLifetime = 0.0f;
+ sParticle->m_flDieTime = 0.2f;
+
+ sParticle->m_flRoll = random->RandomInt( 0, 360 );
+ sParticle->m_flRollDelta = random->RandomInt( -4, 4 );;
+
+ unsigned char color = random->RandomInt( 200, 255 );
+
+ sParticle->m_uchColor[0] = color;
+ sParticle->m_uchColor[1] = color;
+ sParticle->m_uchColor[2] = color;
+ sParticle->m_uchStartAlpha = 128;
+ sParticle->m_uchEndAlpha = 0;
+ sParticle->m_uchStartSize = 2;
+ sParticle->m_uchEndSize = sParticle->m_uchStartSize * 4;
+
+ sParticle->m_vecVelocity = ( direction * 64.0f ) + Vector( 0, 0, 32 );
+ }
+ }
+
+ // Save our last position
+ m_vecLastOrigin = GetAbsOrigin();
+
+ BaseClass::AddEntity();
+ }
+
+ bool ShouldDraw( void ) { return true; }
+
+private:
+ C_WaterBullet( const C_WaterBullet & );
+
+ CSmartPtr<CSimpleEmitter> m_pEmitter;
+
+ Vector m_vecLastOrigin;
+};
+
+IMPLEMENT_CLIENTCLASS_DT( C_WaterBullet, DT_WaterBullet, CWaterBullet )
+END_RECV_TABLE()
|