1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Client's Meteor
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "c_effect_shootingstar.h"
#include "clienteffectprecachesystem.h"
//=============================================================================
//
// Shooting Star Spawner Functionality
//
IMPLEMENT_CLIENTCLASS_DT( C_ShootingStarSpawner, DT_ShootingStarSpawner, CShootingStarSpawner )
RecvPropFloat( RECVINFO( m_flSpawnInterval ) ),
END_RECV_TABLE()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
C_ShootingStarSpawner::C_ShootingStarSpawner( void )
{
SetNextClientThink( gpGlobals->curtime + m_flSpawnInterval );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_ShootingStarSpawner::ClientThink( void )
{
// Spawn a number of shooting stars.
SpawnShootingStars();
// Randomly generate a next think time.
SetNextClientThink( gpGlobals->curtime + random->RandomFloat( 0.25, m_flSpawnInterval ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_ShootingStarSpawner::SpawnShootingStars( void )
{
C_ShootingStar *pShootingStar = new C_ShootingStar;
if ( pShootingStar )
{
// In Space.
pShootingStar->SetFriction( 1.0f );
pShootingStar->SetGravity( 0.0f );
// Randomize the velocity. -- This isn't right, but works for the test!
Vector vecVelocity;
vecVelocity.x = ( GetAbsAngles().x ) * random->RandomFloat( 1.0f, 10.0f );
vecVelocity.y = ( GetAbsAngles().y ) * random->RandomFloat( 1.0f, 10.0f );
vecVelocity.z = ( GetAbsAngles().z ) * random->RandomFloat( 1.0f, 10.0f );
pShootingStar->Init( GetAbsOrigin(), vecVelocity, random->RandomFloat( 10.0f, 100.0f ), random->RandomFloat( 10.0f, 30.0f ) );
}
}
//=============================================================================
//
// Shooting Star Functionality
//
//Precahce the effects
CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffectShootingStars )
CLIENTEFFECT_MATERIAL( "effects/redflare" )
CLIENTEFFECT_REGISTER_END()
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
C_ShootingStar::C_ShootingStar( void ) : CSimpleEmitter( "ShootingStar" )
{
m_flScale = 1.0f;
SetDynamicallyAllocated( false );
}
//-----------------------------------------------------------------------------
// Destructor
//-----------------------------------------------------------------------------
C_ShootingStar::~C_ShootingStar( void )
{
}
//-----------------------------------------------------------------------------
// Destructor
//-----------------------------------------------------------------------------
void C_ShootingStar::Init( const Vector vecOrigin, const Vector vecVelocity, int nSize,
float flLifeTime )
{
// Set the sort origin.
SetSortOrigin( vecOrigin );
// Create the initial particle and set the data.
SimpleParticle *pParticle = ( SimpleParticle* )AddParticle( sizeof( SimpleParticle ), GetPMaterial( "effects/redflare" ), vecOrigin );
if ( pParticle )
{
pParticle->m_vecVelocity = vecVelocity;
pParticle->m_uchColor[0] = pParticle->m_uchColor[1] = pParticle->m_uchColor[2] = 255;
pParticle->m_flRoll = random->RandomInt( 0, 360 );
pParticle->m_flRollDelta = random->RandomFloat( 1.0f, 4.0f );
pParticle->m_flLifetime = 0.0f;
pParticle->m_flDieTime = flLifeTime;
pParticle->m_uchStartAlpha = 255;
pParticle->m_uchEndAlpha = 0;
pParticle->m_uchStartSize = nSize;
pParticle->m_uchEndSize = ( nSize / 3 );
}
int iParticle = m_aParticles.AddToTail();
m_aParticles[iParticle] = pParticle;
}
//-----------------------------------------------------------------------------
// Destructor
//-----------------------------------------------------------------------------
void C_ShootingStar::Destroy( void )
{
// Destroy shooting star particles.
int nParticleCount = m_aParticles.Count();
for ( int iParticle = ( nParticleCount - 1 ); iParticle >= 0; iParticle-- )
{
SimpleParticle *pParticle = m_aParticles[iParticle];
m_aParticles.Remove( iParticle );
CSimpleEmitter::NotifyDestroyParticle( pParticle );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_ShootingStar::SetSortOrigin( const Vector &vSortOrigin )
{
CSimpleEmitter::SetSortOrigin( vSortOrigin );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : timeDelta -
//-----------------------------------------------------------------------------
void C_ShootingStar::Update( float timeDelta )
{
// Parent update.
CSimpleEmitter::Update( timeDelta );
// Don't update if the console is down.
if ( timeDelta <= 0.0f )
return;
// Are we still alive? Get the tail of the shooting star (last valid index)
// and test.
int nParticleCount = m_aParticles.Count();
if ( nParticleCount <= 0 )
return;
SimpleParticle *pParticle = m_aParticles[nParticleCount-1];
if ( pParticle->m_flLifetime >= pParticle->m_flDieTime )
{
Destroy();
return;
}
// Update the particles lifetime.
pParticle->m_flLifetime += timeDelta;
// Update the particle position.
pParticle->m_Pos += ( pParticle->m_vecVelocity * timeDelta );
SetLocalOrigin( pParticle->m_Pos );
SetSortOrigin( GetAbsOrigin() );
}
|