1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Viviane Yang |
---|
24 | * Co-authors: |
---|
25 | * -- |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file Asteroids2DWeapon.h |
---|
31 | @brief Implementation of the Asteroids2DWeapon class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "Asteroids2DWeapon.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | // #include "core/XMLPort.h" |
---|
38 | // #include "core/command/Executor.h" |
---|
39 | |
---|
40 | #include "graphics/Model.h" |
---|
41 | #include "weaponsystem/Weapon.h" |
---|
42 | #include "weaponsystem/WeaponPack.h" |
---|
43 | #include "weaponsystem/WeaponSystem.h" |
---|
44 | #include "worldentities/WorldEntity.h" |
---|
45 | #include "worldentities/pawns/Pawn.h" |
---|
46 | |
---|
47 | #include "weapons/projectiles/Projectile.h" |
---|
48 | #include "weapons/MuzzleFlash.h" |
---|
49 | |
---|
50 | #include "Asteroids2D.h" |
---|
51 | |
---|
52 | namespace orxonox |
---|
53 | { |
---|
54 | RegisterClass(Asteroids2DWeapon); |
---|
55 | |
---|
56 | Asteroids2DWeapon::Asteroids2DWeapon(Context* context) : HsW01(context) |
---|
57 | { |
---|
58 | RegisterObject(Asteroids2DWeapon); |
---|
59 | |
---|
60 | |
---|
61 | } |
---|
62 | |
---|
63 | Asteroids2DWeapon::~Asteroids2DWeapon() |
---|
64 | { |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | Asteroids2D* Asteroids2DWeapon::getGame() |
---|
69 | { |
---|
70 | if (game == nullptr) |
---|
71 | { |
---|
72 | for (Asteroids2D* race : ObjectList<Asteroids2D>()) |
---|
73 | { |
---|
74 | game = race; |
---|
75 | } |
---|
76 | } |
---|
77 | return game; |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | void Asteroids2DWeapon::shot() |
---|
82 | { |
---|
83 | assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() ); |
---|
84 | |
---|
85 | // Create the projectile. |
---|
86 | Projectile* projectile = new Projectile(this->getContext()); |
---|
87 | Model* model = new Model(projectile->getContext()); |
---|
88 | model->setMeshSource(mesh_); |
---|
89 | model->setCastShadows(false); |
---|
90 | projectile->attach(model); |
---|
91 | model->setScale(5); |
---|
92 | |
---|
93 | //get position and orientation of the ship to know in which direction the projectile needs to fire off |
---|
94 | Pawn* player = this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn(); |
---|
95 | |
---|
96 | projectile->setOrientation(player->getOrientation()); |
---|
97 | projectile->setPosition(player->getPosition()); |
---|
98 | |
---|
99 | //Velocity & position of the projectile must be y = 0 since the game takes place in the x-z plane |
---|
100 | Vector3 muzzle2D = player->getOrientation()* WorldEntity::FRONT ; |
---|
101 | muzzle2D.y = 0; |
---|
102 | projectile->setVelocity(muzzle2D * this->speed_); |
---|
103 | |
---|
104 | projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()); |
---|
105 | projectile->setDamage(this->getDamage()); |
---|
106 | projectile->setShieldDamage(this->getShieldDamage()); |
---|
107 | projectile->setHealthDamage(this->getHealthDamage()); |
---|
108 | |
---|
109 | // Display the muzzle flash. |
---|
110 | this->HsW01::muzzleflash(); |
---|
111 | } |
---|
112 | |
---|
113 | } |
---|