[12295] | 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 OrxoBloxCanon.h |
---|
| 31 | @brief Implementation of the OrxoBloxCanon class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "OrxoBloxCanon.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | |
---|
| 38 | #include "graphics/Model.h" |
---|
| 39 | #include "weaponsystem/Weapon.h" |
---|
| 40 | #include "weaponsystem/WeaponPack.h" |
---|
| 41 | #include "weaponsystem/WeaponSystem.h" |
---|
| 42 | |
---|
| 43 | #include "weapons/projectiles/BallProjectile.h" |
---|
| 44 | #include "weapons/MuzzleFlash.h" |
---|
| 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
| 48 | RegisterClass(OrxoBloxCanon); |
---|
| 49 | |
---|
| 50 | OrxoBloxCanon::OrxoBloxCanon(Context* context) : HsW01(context) |
---|
| 51 | { |
---|
| 52 | RegisterObject(OrxoBloxCanon); |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | OrxoBloxCanon::~OrxoBloxCanon() |
---|
| 58 | { |
---|
| 59 | |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void OrxoBloxCanon::shot() |
---|
| 63 | { |
---|
| 64 | assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() ); |
---|
| 65 | |
---|
| 66 | // Create the projectile. |
---|
| 67 | Projectile* projectile = new BallProjectile(this->getContext()); |
---|
| 68 | Model* model = new Model(projectile->getContext()); |
---|
| 69 | model->setMeshSource(mesh_); |
---|
| 70 | model->setCastShadows(false); |
---|
| 71 | projectile->attach(model); |
---|
| 72 | model->setScale(5); |
---|
| 73 | |
---|
| 74 | //get position and orientation of the ship to know in which direction the projectile needs to fire off |
---|
| 75 | Pawn* player = this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn(); |
---|
| 76 | |
---|
| 77 | projectile->setOrientation(player->getOrientation()); |
---|
| 78 | projectile->setPosition(player->getPosition()); |
---|
| 79 | |
---|
| 80 | //Velocity & position of the projectile must be y = 0 since the game takes place in the x-z plane |
---|
| 81 | Vector3 muzzle2D = player->getOrientation()* WorldEntity::FRONT ; |
---|
| 82 | muzzle2D.y = 0; |
---|
| 83 | projectile->setVelocity(muzzle2D * this->speed_); |
---|
| 84 | |
---|
| 85 | projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()); |
---|
| 86 | projectile->setDamage(this->getDamage()); |
---|
| 87 | projectile->setShieldDamage(this->getShieldDamage()); |
---|
| 88 | projectile->setHealthDamage(this->getHealthDamage()); |
---|
| 89 | |
---|
| 90 | // Display the muzzle flash. |
---|
| 91 | this->HsW01::muzzleflash(); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | } |
---|