1 //==============================================================================
2 // This program is free software; you can redistribute it and/or modify
3 // it under the terms of the GNU General Public License as published by
4 // the Free Software Foundation; either version 2 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU Library General Public License for more details.
11 //
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 //==============================================================================
16 
17 //==============================================================================
18 // File: cRocket.cpp
19 // Project: Shooting Star
20 // Author: Jarmo Hekkanen <jarski@2ndpoint.fi>
21 // Copyrights (c) 2003 2ndPoint ry (www.2ndpoint.fi)
22 //------------------------------------------------------------------------------
23 // Revision history
24 //==============================================================================
25 
26 //==============================================================================
27 // Includes
28 #include "cRocket.hpp"
29 #include "cPlayer.hpp"
30 #include "cRocketLauncher.hpp"
31 #include "cParticleSystem.hpp"
32 #include "cTextureManager.hpp"
33 #include "cWorld.hpp"
34 #include "cMixer.hpp"
35 #include "Debug.hpp"
36 #include "cExplosionSystem.hpp"
37 #include "cHurtable.hpp"
38 //------------------------------------------------------------------------------
39 // Namespaces
40 using namespace ShootingStar;
41 //==============================================================================
42 
43 
44 //! Constructor
cRocket(void)45 cRocket::cRocket (void):
46 mSmokeSystem (0),
47 mSound (cMixer::GetInstance ().LoadSound ("explosion.wav")),
48 mChannel (-2)
49 {
50 	SetCollisionModel (CollisionModel_Ray);
51 	SetContactModel (ContactModel_Stop);
52 
53 	SetEmittingAngle (180.0f);
54 	SetEmittingDistance (0.0f);
55 };
56 
57 //! Destructor
~cRocket(void)58 cRocket::~cRocket (void)
59 {
60 	// Empty
61 };
62 
63 //! Create a smoke particle system
64 void
CreateSmokeSystem(void)65 cRocket::CreateSmokeSystem (void)
66 {
67 	dbg::assertion (DBG_ASSERTION (mSmokeSystem == 0));
68 
69 	cParticleSystem *pSystem = new cParticleSystem (50);
70 	pSystem->SetTexture (cTextureManager::GetInstance ().LoadTexture ("smoke.png"));
71 	pSystem->SetAngleVariation (0.0f);
72 	pSystem->SetSpeed (0.01f, 0.0f);
73 	pSystem->SetSize (16.0f, 128.0f);
74 	pSystem->SetEnergy (500, 0.3f);
75 	pSystem->SetBlending (true);
76 	pSystem->SetEmitDelay (10);
77 	pSystem->SetEmitter (this);
78 	pSystem->SetStartColor (0.5f, 0.5f, 0.5f, 1.0f);
79 	pSystem->SetEndColor (1.0f, 1.0f, 1.0f, 0.0f);
80 	pSystem->SetLayer (-1);
81 	cWorld::GetInstance ().SpawnObject (pSystem);
82 
83 	mSmokeSystem = pSystem->GetID ();
84 }
85 
86 void
OnMapCollision(const cVector2f & begin,const cVector2f & end)87 cRocket::OnMapCollision (const cVector2f &begin, const cVector2f &end)
88 {
89 	Explode ();
90 }
91 
92 void
OnObjectCollision(cCollidable * pOther)93 cRocket::OnObjectCollision (cCollidable *pOther)
94 {
95 	cHurtable *pHurtable = dynamic_cast<cHurtable*>(pOther);
96 	if ( pHurtable != NULL )
97 	{
98 		Explode ();
99 		pHurtable->DoDamage (50, cVector2f (0.0f, 0.0f), GetID ());
100 	}
101 }
102 
103 void
Explode()104 cRocket::Explode ()
105 {
106 	// Kill the smoke system
107 	cParticleSystem *pSmoke = NULL;
108 	if ( mSmokeSystem != 0 )
109 		pSmoke = dynamic_cast<cParticleSystem*> (cWorld::GetInstance ().GetObject (mSmokeSystem));
110 	if ( pSmoke != NULL )
111 	{
112 		pSmoke->SetEmitDelay (0);
113 		pSmoke->KillEmptySystem (true);
114 	}
115 
116 	if ( mChannel >= 0 )
117 	{
118 		cMixer::GetInstance ().StopSound(mChannel,250);
119 		mChannel = -2;
120 	}
121 	mChannel = cMixer::GetInstance ().PlaySound (mSound);
122 
123 	// Spawn an explosion
124 	cExplosionSystem *pSystem = new cExplosionSystem;
125 	pSystem->SetEmitter (this);
126 	pSystem->EmitAll ();
127 	pSystem->SetOwner (GetOwner ());
128 	cWorld::GetInstance ().SpawnObject (pSystem);
129 
130 	// Kill the rocket
131 	Kill ();
132 }
133 
134 
135 
136 //==============================================================================
137 // EOF
138 //==============================================================================
139