Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2009, 2:06:04 PM (16 years ago)
Author:
Hagen
Message:

working laser style weapon with muzzleflash

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapons/src/orxonox/objects/weaponsystem/weaponmodes/HsW01.cc

    r2912 r2979  
    2121 *
    2222 *   Author:
    23  *      Martin Polak
     23 *      Hagen Seifert
    2424 *   Co-authors:
    2525 *      ...
     
    3232#include "core/CoreIncludes.h"
    3333#include "core/XMLPort.h"
     34#include "objects/weaponsystem/projectiles/ParticleProjectile.h"
     35#include "objects/worldentities/Model.h"
     36#include "objects/worldentities/MuzzleFlash.h"
     37
     38#include "objects/weaponsystem/Weapon.h"
     39#include "objects/weaponsystem/WeaponPack.h"
     40#include "objects/weaponsystem/WeaponSystem.h"
    3441
    3542namespace orxonox
     
    3744    CreateFactory(HsW01);
    3845
    39     HsW01::HsW01(BaseObject* creator) : Weapon(creator)
     46    HsW01::HsW01(BaseObject* creator) : WeaponMode(creator)
    4047    {
    4148        RegisterObject(HsW01);
    4249
    43         this->speed_ = 1250;
     50        this->reloadTime_ = 0.25;
     51        this->damage_ = 15;
     52        this->speed_ = 2500;
     53        this->delay_ = 0;
     54        this->setMunitionName("HsW01");
     55
     56        this->delayTimer_.setTimer(1.0f, false, this, createExecutor(createFunctor(&HsW01::shot)));
     57        this->delayTimer_.stopTimer();
     58    }
     59
     60    void HsW01::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     61    {
     62        SUPER(HsW01, XMLPort, xmlelement, mode);
     63
     64        XMLPortParam(HsW01, "delay", setDelay, getDelay, xmlelement, mode);
     65        XMLPortParam(HsW01, "material", setMaterial, getMaterial, xmlelement, mode);
    4466
    4567    }
    4668
    47     HsW01::~HsW01()
     69    void HsW01::setMaterial(const std::string& material)
    4870    {
     71        this->material_ = material;
    4972    }
    5073
    51     void HsW01::reloadBullet()
     74    std::string& HsW01::getMaterial()
    5275    {
    53         this->bulletTimer(this->bulletLoadingTime_);
     76        return this->material_;
    5477    }
    5578
    56     void HsW01::reloadMagazine()
     79    void HsW01::setDelay(float d)
    5780    {
    58         this->magazineTimer(this->magazineLoadingTime_);
     81        this->delay_ = d;
     82        this->delayTimer_.setInterval(this->delay_);
    5983    }
    6084
    61     void HsW01::takeBullets()
     85    float HsW01::getDelay() const
    6286    {
    63         this->munition_->removeBullets(1);
     87        return this->delay_;
    6488    }
    6589
    66     void HsW01::takeMagazines()
     90    void HsW01::fire()
    6791    {
    68         this->munition_->removeMagazines(1);
     92        this->delayTimer_.startTimer();
    6993    }
    7094
    71     void HsW01::createProjectile()
     95    void HsW01::muendungsfeuer()
    7296    {
    73         BillboardProjectile* projectile = new ParticleProjectile(this);
    74         projectile->setOrientation(this->getWorldOrientation());
    75         projectile->setPosition(this->getWorldPosition());
    76         projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_);
    77         projectile->setOwner(this->getWeaponSystem()->getPawn());
     97        MuzzleFlash *muzzleFlash = new MuzzleFlash(this);
     98        this->getWeapon()->attach(muzzleFlash);
     99        muzzleFlash->setPosition(this->getMuzzleOffset());
     100        muzzleFlash->setMaterial(this->material_);
     101    }
     102
     103    void HsW01::shot()
     104    {
     105        Projectile* projectile = new Projectile(this);
     106        Model* model = new Model(projectile);
     107        model->setMeshSource("laserbeam.mesh");
     108        model->setCastShadows(false);
     109        projectile->attach(model);
     110        model->setScale(5);
     111
     112        projectile->setOrientation(this->getMuzzleOrientation());
     113        projectile->setPosition(this->getMuzzlePosition());
     114        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
     115
     116        projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
     117        projectile->setDamage(this->getDamage());
     118
     119        HsW01::muendungsfeuer();
    78120    }
    79121}
Note: See TracChangeset for help on using the changeset viewer.