Merge branch 'GameLogic' of https://github.com/dean11/Danbias into GameLogic

This commit is contained in:
Linda Andersson 2014-02-27 15:30:33 +01:00
commit 3c3e21209b
6 changed files with 65 additions and 25 deletions

View File

@ -10,12 +10,15 @@ AttatchmentGun::AttatchmentGun(void)
{ {
this->owner = 0; this->owner = 0;
this->damage = 0.0f; this->damage = 0.0f;
this->Cooldown = 0.0f;
} }
AttatchmentGun::AttatchmentGun(Player &owner) AttatchmentGun::AttatchmentGun(Player &owner)
{ {
this->owner = &owner; this->owner = &owner;
this->damage = standardDamage; 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) switch (usage)
{ {
case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS:
//skjut här
break;
case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: if(TimeUntilFire == 0.0f)
break; {
ShootBullet(usage,dt);
TimeUntilFire = this->Cooldown;
}
case WEAPON_USE_SECONDARY_RELEASE:
break;
case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS:
break; break;
} }
@ -50,6 +50,14 @@ void AttatchmentGun::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, float d
void AttatchmentGun::Update(float dt) 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); hitRay = new Oyster::Collision3D::Ray(pos,look);
Oyster::Physics::API::Instance().ApplyEffect(hitRay,&bullet,BulletCollision);
delete hitRay;
} }

View File

@ -9,8 +9,9 @@
namespace GameLogic 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 class AttatchmentGun : public IAttatchment
{ {
public: public:
@ -24,9 +25,13 @@ namespace GameLogic
private: private:
Oyster::Math::Float damage; Oyster::Math::Float damage;
Oyster::Math::Float Cooldown;
Oyster::Math::Float TimeUntilFire;
private: private:
void ShootBullet(const WEAPON_FIRE &usage, float dt); void ShootBullet(const WEAPON_FIRE &usage, float dt);
static void BulletCollision(Oyster::Physics::ICustomBody *obj, void* args);
}; };
} }
#endif #endif

View File

@ -9,6 +9,7 @@
#include "JumpPad.h" #include "JumpPad.h"
#include "Portal.h" #include "Portal.h"
#include "ExplosiveCrate.h" #include "ExplosiveCrate.h"
#include "AttatchmentGun.h"
#include "PickupSystem/PickupHealth.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 //General collision collision for pickups
//It calls the collision function defined in each pickup. //It calls the collision function defined in each pickup.

View File

@ -6,6 +6,8 @@
using namespace GameLogic; using namespace GameLogic;
using namespace Oyster::Physics; using namespace Oyster::Physics;
using namespace Oyster::Math;
const float MOVE_FORCE = 30; const float MOVE_FORCE = 30;
const float KEY_TIMER = 0.03f; const float KEY_TIMER = 0.03f;
const float AFFECTED_TIMER = 1.0f; const float AFFECTED_TIMER = 1.0f;
@ -63,16 +65,21 @@ void Player::initPlayerData()
this->deathTimer = 0; this->deathTimer = 0;
this->rotationUp = 0; this->rotationUp = 0;
ICustomBody::State state;
this->rigidBody->GetState( state );
state.staticFrictionCoeff = 0.0f;
state.dynamicFrictionCoeff = 0.0f;
this->rigidBody->SetState( state );
} }
void Player::BeginFrame() void Player::BeginFrame()
{ {
if( this->playerState != PLAYER_STATE_DEAD && this->playerState != PLAYER_STATE_DIED) if( !(this->playerState & (PLAYER_STATE_DEAD || PLAYER_STATE_DIED)) )
{ {
static const Float maxSpeed = 30;
weapon->Update(0.002f); weapon->Update(0.002f);
Oyster::Math::Float maxSpeed = 30;
// Rotate player accordingly // Rotate player accordingly
this->rigidBody->AddRotationAroundY(this->rotationUp); this->rigidBody->AddRotationAroundY(this->rotationUp);
this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized());
@ -81,9 +88,9 @@ void Player::BeginFrame()
Oyster::Math::Float4x4 xform; Oyster::Math::Float4x4 xform;
xform = this->rigidBody->GetState().GetOrientation(); xform = this->rigidBody->GetState().GetOrientation();
Oyster::Math::Float3 forwardDir = xform.v[2]; Oyster::Math::Float3 &forwardDir = xform.v[2].xyz;
Oyster::Math::Float3 upDir = xform.v[1]; Oyster::Math::Float3 &upDir = xform.v[1].xyz;
Oyster::Math::Float3 rightDir = xform.v[0]; Oyster::Math::Float3 &rightDir = xform.v[0].xyz;
forwardDir.Normalize(); forwardDir.Normalize();
upDir.Normalize(); upDir.Normalize();
rightDir.Normalize(); rightDir.Normalize();
@ -98,7 +105,7 @@ void Player::BeginFrame()
// Walking data // Walking data
Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0);
Oyster::Math::Float walkSpeed = this->playerStats.movementSpeed*0.2f; Oyster::Math::Float &walkSpeed = this->playerStats.movementSpeed;
// Check for input // Check for input
if(key_forward > 0.001) if(key_forward > 0.001)

View File

@ -10,7 +10,7 @@
#include "DynamicArray.h" #include "DynamicArray.h"
const float MAX_HP = 100.0f; const float MAX_HP = 100.0f;
const float BASIC_SPEED = 30.0f; const float BASIC_SPEED = 10.0f;
namespace GameLogic namespace GameLogic
{ {

View File

@ -1,4 +1,5 @@
#include "Weapon.h" #include "Weapon.h"
#include "AttatchmentGun.h"
#include "AttatchmentMassDriver.h" #include "AttatchmentMassDriver.h"
#include "Player.h" #include "Player.h"
@ -30,11 +31,18 @@ Weapon::Weapon(int MaxNrOfSockets,Player *owner)
selectedAttatchment = 0; selectedAttatchment = 0;
//give the weapon a massdriver on socket 0 //give the weapon a massdriver on socket 0
IAttatchment *mD = new AttatchmentMassDriver(*owner); IAttatchment *mD = new AttatchmentMassDriver(*owner);
attatchmentSockets[0]->SetAttatchment(mD); attatchmentSockets[0]->SetAttatchment(mD);
this->currentNrOfAttatchments = 1; this->currentNrOfAttatchments = 1;
SelectAttatchment(0); SelectAttatchment(0);
//give the weapon a massdriver on socket 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
} }