Danbias/Code/Game/GameLogic/AttatchmentGun.cpp

80 lines
1.6 KiB
C++
Raw Normal View History

2014-02-27 14:38:03 +01:00
#include "AttatchmentGun.h"
#include "PhysicsAPI.h"
#include "GameLogicStates.h"
#include "Game.h"
using namespace GameLogic;
AttatchmentGun::AttatchmentGun(void)
{
this->owner = 0;
this->damage = 0.0f;
this->Cooldown = 0.0f;
2014-02-27 14:38:03 +01:00
}
AttatchmentGun::AttatchmentGun(Player &owner)
{
this->owner = &owner;
this->damage = standardDamage;
this->Cooldown = standardCooldown;
this->TimeUntilFire = 0.0f;
2014-02-27 14:38:03 +01:00
}
AttatchmentGun::~AttatchmentGun(void)
{
}
/********************************************************
* Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used
********************************************************/
void AttatchmentGun::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, float dt)
{
//switch case to determin what functionallity to use in the attatchment
switch (usage)
{
case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS:
if(TimeUntilFire == 0.0f)
{
ShootBullet(usage,dt);
TimeUntilFire = this->Cooldown;
}
2014-02-27 14:38:03 +01:00
break;
}
}
void AttatchmentGun::Update(float dt)
{
if(TimeUntilFire > 0.0f)
{
TimeUntilFire-= dt;
}
else
{
TimeUntilFire = 0.0f;
}
2014-02-27 14:38:03 +01:00
}
void AttatchmentGun::ShootBullet(const WEAPON_FIRE &usage, float dt)
{
Oyster::Collision3D::Ray *hitRay;
Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos;
Oyster::Math::Float3 look = owner->GetLookDir().GetNormalized();
Oyster::Math::Float hitDamage = this->damage;
firedBullet bullet;
bullet.hitDamage = hitDamage;
hitRay = new Oyster::Collision3D::Ray(pos,look);
Oyster::Physics::API::Instance().ApplyEffect(hitRay,&bullet,BulletCollision);
2014-02-27 14:38:03 +01:00
delete hitRay;
2014-02-27 14:38:03 +01:00
}