/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Viviane Yang * Co-authors: * -- * */ /** @file Asteroids2DWeapon.h @brief Implementation of the Asteroids2DWeapon class. */ #include "Asteroids2DWeapon.h" #include "core/CoreIncludes.h" #include "graphics/Model.h" #include "weaponsystem/Weapon.h" #include "weaponsystem/WeaponPack.h" #include "weaponsystem/WeaponSystem.h" #include "weapons/projectiles/Projectile.h" #include "weapons/MuzzleFlash.h" namespace orxonox { RegisterClass(Asteroids2DWeapon); Asteroids2DWeapon::Asteroids2DWeapon(Context* context) : HsW01(context) { RegisterObject(Asteroids2DWeapon); } Asteroids2DWeapon::~Asteroids2DWeapon() { } void Asteroids2DWeapon::shot() { assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() ); // Create the projectile. Projectile* projectile = new Projectile(this->getContext()); Model* model = new Model(projectile->getContext()); model->setMeshSource(mesh_); model->setCastShadows(false); projectile->attach(model); model->setScale(5); //get position and orientation of the ship to know in which direction the projectile needs to fire off Pawn* player = this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn(); projectile->setOrientation(player->getOrientation()); projectile->setPosition(player->getPosition()); //Velocity & position of the projectile must be y = 0 since the game takes place in the x-z plane Vector3 muzzle2D = player->getOrientation()* WorldEntity::FRONT ; muzzle2D.y = 0; projectile->setVelocity(muzzle2D * this->speed_); projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()); projectile->setDamage(this->getDamage()); projectile->setShieldDamage(this->getShieldDamage()); projectile->setHealthDamage(this->getHealthDamage()); // Display the muzzle flash. this->HsW01::muzzleflash(); } }