From ecad24450f09f8ab4b1123bdae431ab7182c2c5a Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 27 Feb 2014 15:15:44 +0100 Subject: [PATCH] GL - Normal gun implemented(not tested yet) --- Code/Game/GameLogic/AttatchmentGun.cpp | 28 +++++++++++++++--------- Code/Game/GameLogic/AttatchmentGun.h | 11 +++++++--- Code/Game/GameLogic/CollisionManager.cpp | 12 ++++++++++ Code/Game/GameLogic/Weapon.cpp | 16 ++++++++++---- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentGun.cpp b/Code/Game/GameLogic/AttatchmentGun.cpp index 6146a838..3d942ea4 100644 --- a/Code/Game/GameLogic/AttatchmentGun.cpp +++ b/Code/Game/GameLogic/AttatchmentGun.cpp @@ -10,12 +10,15 @@ AttatchmentGun::AttatchmentGun(void) { this->owner = 0; this->damage = 0.0f; + this->Cooldown = 0.0f; } AttatchmentGun::AttatchmentGun(Player &owner) { this->owner = &owner; this->damage = standardDamage; + this->Cooldown = standardCooldown; + this->TimeUntilFire = 0.0f; } @@ -33,16 +36,13 @@ void AttatchmentGun::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, float d switch (usage) { case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: - //skjut här - break; - case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: - break; + if(TimeUntilFire == 0.0f) + { + ShootBullet(usage,dt); + TimeUntilFire = this->Cooldown; + } - case WEAPON_USE_SECONDARY_RELEASE: - break; - - case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS: break; } @@ -50,6 +50,14 @@ void AttatchmentGun::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, float d void AttatchmentGun::Update(float dt) { + if(TimeUntilFire > 0.0f) + { + TimeUntilFire-= dt; + } + else + { + TimeUntilFire = 0.0f; + } } @@ -65,7 +73,7 @@ void AttatchmentGun::ShootBullet(const WEAPON_FIRE &usage, float dt) hitRay = new Oyster::Collision3D::Ray(pos,look); + Oyster::Physics::API::Instance().ApplyEffect(hitRay,&bullet,BulletCollision); - - + delete hitRay; } diff --git a/Code/Game/GameLogic/AttatchmentGun.h b/Code/Game/GameLogic/AttatchmentGun.h index 9cec7cb7..ed20d5f1 100644 --- a/Code/Game/GameLogic/AttatchmentGun.h +++ b/Code/Game/GameLogic/AttatchmentGun.h @@ -9,8 +9,9 @@ namespace GameLogic { - const Oyster::Math::Float standardDamage = 10; - + const Oyster::Math::Float standardDamage = 10.0f; + const Oyster::Math::Float standardCooldown = 0.5f; + class AttatchmentGun : public IAttatchment { public: @@ -24,9 +25,13 @@ namespace GameLogic private: Oyster::Math::Float damage; + Oyster::Math::Float Cooldown; + Oyster::Math::Float TimeUntilFire; + private: void ShootBullet(const WEAPON_FIRE &usage, float dt); - + static void BulletCollision(Oyster::Physics::ICustomBody *obj, void* args); + }; } #endif diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index f8669591..926c07c2 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -9,6 +9,7 @@ #include "JumpPad.h" #include "Portal.h" #include "ExplosiveCrate.h" +#include "AttatchmentGun.h" #include "PickupSystem/PickupHealth.h" @@ -369,6 +370,17 @@ using namespace GameLogic; } + void AttatchmentGun::BulletCollision(Oyster::Physics::ICustomBody *obj, void* args) + { + Object *realObj = (Object*)obj->GetCustomTag(); + + if(realObj->GetObjectType() != ObjectSpecialType::ObjectSpecialType_Player) + return; + + firedBullet *bullet = (firedBullet*)(args); + + ((Player*)realObj)->DamageLife(bullet->hitDamage); + } //General collision collision for pickups //It calls the collision function defined in each pickup. diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 379f53dc..a68906b8 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -1,4 +1,5 @@ #include "Weapon.h" +#include "AttatchmentGun.h" #include "AttatchmentMassDriver.h" #include "Player.h" @@ -30,11 +31,18 @@ Weapon::Weapon(int MaxNrOfSockets,Player *owner) selectedAttatchment = 0; //give the weapon a massdriver on socket 0 - IAttatchment *mD = new AttatchmentMassDriver(*owner); - attatchmentSockets[0]->SetAttatchment(mD); - this->currentNrOfAttatchments = 1; - SelectAttatchment(0); + IAttatchment *mD = new AttatchmentMassDriver(*owner); + attatchmentSockets[0]->SetAttatchment(mD); + this->currentNrOfAttatchments = 1; + SelectAttatchment(0); //give the weapon a massdriver on socket 0 + + //give the weapon a normal gun on socket 1 + IAttatchment *gun = new AttatchmentGun(*owner); + attatchmentSockets[1]->SetAttatchment(gun); + this->currentNrOfAttatchments = 2; + SelectAttatchment(1); + //give the weapon a normal gun on socket 1 }