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: cWeaponBox.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 "cWeaponBox.hpp"
29 #include "cAnimationManager.hpp"
30 #include "cPlayer.hpp"
31 #include "cMixer.hpp"
32 #include "cPistol.hpp"
33 #include "cShotgun.hpp"
34 #include "cRocketLauncher.hpp"
35 #include "cFlamer.hpp"
36 #include "cMachineGun.hpp"
37 #include "cWorld.hpp"
38 #include "Debug.hpp"
39 //------------------------------------------------------------------------------
40 // Namespaces
41 using namespace ShootingStar;
42 //==============================================================================
43
44
45 //! Constructor
cWeaponBox(void)46 cWeaponBox::cWeaponBox (void):
47 mType (BoxType_Pistol),
48 mSound (cMixer::GetInstance ().LoadSound ("pickup.wav"))
49 {
50 SetCollisionModel (CollisionModel_Circle);
51 SetCollisionRadius (20.0f);
52 SetVelocity (cVector2f (0.0f, 0.0f));
53
54 mAnimation.SetAnimation (cAnimationManager::GetInstance ().LoadAnimation ("weaponbox"));
55 mAnimation.SetNumberOfFrames (1);
56 mAnimation.SetFrameDelay (999999);
57 SetLayer (-10);
58 };
59
60 //! Destructor
~cWeaponBox(void)61 cWeaponBox::~cWeaponBox (void)
62 {
63 // Empty
64 };
65
66 //! Called when object collides with other object
67 void
OnObjectCollision(cCollidable * pOther)68 cWeaponBox::OnObjectCollision (cCollidable *pOther)
69 {
70 cSoldier *pSoldier = dynamic_cast<cPlayer*>(pOther);
71 if ( pSoldier != NULL )
72 {
73 cWeapon *pWeapon = NULL;
74 switch ( mType )
75 {
76 case BoxType_Pistol:
77 pWeapon = new cPistol;
78 break;
79 case BoxType_Shotgun:
80 pWeapon = new cShotgun;
81 break;
82 case BoxType_Flamer:
83 pWeapon = new cFlamer;
84 break;
85 case BoxType_RocketLauncher:
86 pWeapon = new cRocketLauncher;
87 break;
88 case BoxType_MachineGun:
89 pWeapon = new cMachineGun;
90 break;
91 default:
92 dbg::sentinel (DBG_HERE);
93 break;
94 }
95 cWorld::GetInstance ().SpawnObject (pWeapon);
96 cMixer::GetInstance ().PlaySound (mSound);
97 pSoldier->AddWeapon (pWeapon);
98 Kill ();
99 }
100 }
101
102 //==============================================================================
103 // EOF
104 //==============================================================================
105