SHARE
TWEET

CTileManager

a guest Mar 29th, 2017 187 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include    <tgSystem.h>
  2. #include    "CPhysicsManager.h"
  3. #include    "CCharacter.h"
  4. #include    "CharSelEnums.h"
  5. #include    "CAudioHandler.h"
  6. #include    "CUIHandler.h"
  7. #include    "CGrenade.h"
  8. #include    "CBodyManager.h"
  9. #include    "GameStateMachine/CGameStates.h"
  10. #include    "CTileManager.h"
  11. #include    "CApplication.h"
  12. #include    "CCamera.h"
  13. #include    "CClock.h"
  14. #include    "CSettings.h"
  15. #include    "AppRoot.h"
  16. #include    <tgCCore.h>
  17. #include    "Managers/CModelManager.h"
  18. #include    <tgCPluginInput.h>
  19. #include    <tgCQuadManager.h>
  20. #include    <tgCTextureManager.h>
  21. #include    <tgCDebugManager.h>
  22. #include    "Managers/CLightManager.h"
  23. #include    "tgCLine3D.h"
  24. #include "CParticleEmitter.h"
  25. #include "CAnimationHandler.h"
  26. #include    "Managers/CConfigManager.h"
  27. #include    "tgCInterpolator.h"
  28. #include    "tgCAnimation.h"
  29. #include    "CAnimationHandler.h"
  30. #include    "Managers/CAnimationManager.h"
  31. #include    "CParticleManager.h"
  32. #include    "CParticle.h"
  33. #include    "Renderer/CRenderCallBacks.h"
  34. #if defined (TG_PS4)
  35. #include "tgCPluginInput_PS4.h"
  36. #endif
  37. #include <tgMemoryDisable.h>
  38.  
  39. //////////////////////////////////////////////////////////////////////////
  40.  
  41. ////////////////////////////// CApplication //////////////////////////////
  42. //                                                                      //
  43. //  Info:
  44. //                                                                      //
  45. //*///////////////////////////////////////////////////////////////////////
  46. CCharacter::CCharacter(tgBool IsPlayerCharacter, tgUInt8 ControllerIndex, tgSInt8 PickedCharacter, tgSInt8 PickedColor)
  47.     : m_CurrentAnimation(ANIMATION_IDLE)
  48.     , m_NextAnimation(ANIMATION_IDLE)
  49.     , m_SubAnimation(ANIMATION_SHOOT)
  50.     , m_SubAnimationHit(ANIMATION_HIT)
  51.     , m_BlendValue(1.0f)
  52.     , m_BlendSpeed(4.0f)
  53.     , m_NumRespawnTries(0)
  54. {
  55.     m_PickedColor = PickedColor;
  56.     m_PickedChar = PickedCharacter;
  57.  
  58.     m_HasSpawned = false;
  59.     m_IsPlayerCharacter = IsPlayerCharacter;
  60.     m_ControllerIndex = ControllerIndex;
  61.     m_Connected = false;
  62.     m_OccupiedRespawn = 0;
  63.     m_GodMode = false;
  64.  
  65.     m_InvulnerabilityTime = 2.0f;
  66.     m_InvulnerabilityTimer = 2.0f;
  67.     m_IsInvulnerable = false;
  68.  
  69.     //If Windows is defined, use the CGamePad class based on XINPUT for Controller input
  70.     m_pGamePad = new CGamepad();
  71.     m_pGamePad->Create(m_ControllerIndex);
  72.     m_Connected = m_pGamePad->GetConnected();
  73.  
  74.     if (m_Connected)
  75.         m_PlayerTag = m_pGamePad->GetIndex();
  76.     else
  77.         m_PlayerTag = 0;
  78.  
  79.     m_TaggedBy = m_PlayerTag;
  80.  
  81.  
  82.  
  83.     // Set model of character, this is a placeholder way of handling it
  84.     // The models and textures should be taken from character select state
  85.     InitModelAndTextures(PickedCharacter, PickedColor);
  86.  
  87.     m_ModelMatrix = new tgCMatrix(tgCMatrix::Identity);
  88.     m_pShadowModel = CModelManager::GetInstance().LoadModel("models/ball_shadow.tfm", "grenade_shadow", false);
  89.     m_pShadowModel->GetMesh(0)->GetSubMesh(0)->Material.SetColor(tgCColor(0.0f, 0.0f, 0.0f, 0.5f));
  90.  
  91.     m_Score = 0;
  92.  
  93.     // Movement variables
  94.     tgFloat movementspeed, inairspeed, rotationspeed, jumpheight, mass;
  95.  
  96.     // Combat variables
  97.     tgFloat shootingforce, shootingminforce, shootingmaxforce, shootingcooldown, chargerate, shootanglelow, shootanglehigh;
  98.  
  99.     // Camera variables
  100.     tgFloat camposy, camposz;
  101.  
  102.     // Misc variables
  103.     tgFloat rumblemax, respawntime;
  104.     tgSInt32 rumbleactivated;
  105.  
  106.     if (CConfigManager::OpenFile("data/settings/Settings_Players.ini"))
  107.     {
  108.         CConfigManager::ReadSetting("Movement", "movementspeed", NULL, NULL, &movementspeed);
  109.         CConfigManager::ReadSetting("Movement", "inairspeed", NULL, NULL, &inairspeed);
  110.         CConfigManager::ReadSetting("Movement", "rotationspeed", NULL, NULL, &rotationspeed);
  111.         CConfigManager::ReadSetting("Movement", "jumpheight", NULL, NULL, &jumpheight);
  112.         CConfigManager::ReadSetting("Movement", "mass", NULL, NULL, &mass);
  113.  
  114.         CConfigManager::ReadSetting("Combat", "shootingforce", NULL, NULL, &shootingforce);
  115.         CConfigManager::ReadSetting("Combat", "shootingminforce", NULL, NULL, &shootingminforce);
  116.         CConfigManager::ReadSetting("Combat", "shootingmaxforce", NULL, NULL, &shootingmaxforce);
  117.         CConfigManager::ReadSetting("Combat", "shootingcooldown", NULL, NULL, &shootingcooldown);
  118.         CConfigManager::ReadSetting("Combat", "shootanglehigh", NULL, NULL, &shootanglehigh);
  119.         CConfigManager::ReadSetting("Combat", "shootanglelow", NULL, NULL, &shootanglelow);
  120.  
  121.         CConfigManager::ReadSetting("Combat", "chargerate", NULL, NULL, &chargerate);
  122.  
  123.         CConfigManager::ReadSetting("Camera", "camposy", NULL, NULL, &camposy);
  124.         CConfigManager::ReadSetting("Camera", "camposz", NULL, NULL, &camposz);
  125.  
  126.         CConfigManager::ReadSetting("Misc", "rumbleactivated", NULL, &rumbleactivated, NULL);
  127.         CConfigManager::ReadSetting("Misc", "rumblemax", NULL, NULL, &rumblemax);
  128.         CConfigManager::ReadSetting("Misc", "respawntime", NULL, NULL, &respawntime);
  129.  
  130.         CConfigManager::CloseFile();
  131.     }
  132.  
  133.     // Movement
  134.     m_MovementSpeed = movementspeed;
  135.     m_Sensitivity = rotationspeed;
  136.     m_Mass = mass;
  137.     m_JumpHeight = jumpheight;
  138.     m_InAirSpeed = inairspeed;
  139.  
  140.     // Combat
  141.     m_GrenadeForceMax = shootingmaxforce;
  142.     m_GrenadeForceMin = shootingminforce;
  143.     m_GrenadeForce = 0.f;
  144.     m_GrenadeChargeRate = chargerate;
  145.     m_ShootingForce = shootingforce;
  146.     m_ShootingAngle = LOW_ANGLE;
  147.     m_ShootingCooldownMax = shootingcooldown;
  148.     m_ShootingCooldown = m_ShootingCooldownMax;
  149.     m_AngleHigh = shootanglehigh;
  150.     m_AngleLow = shootanglelow;
  151.     m_Angle = m_AngleLow;
  152.     m_LethalVelocityLimit = 35.0f;
  153.  
  154.     // Camera
  155.     m_CamPosY = camposy;
  156.     m_CamPosZ = camposz;
  157.  
  158.     // Physics
  159.     m_pWorld = CPhysicsManager::GetInstance().GetWorld();
  160.     InitPhysics();
  161.     InitCam();
  162.  
  163.     // Animations
  164.     InitAnimations(PickedCharacter);
  165.  
  166. }
  167.  
  168. void CCharacter::InitAnimations(tgSInt8 PickedChar) {
  169.     ////////////////// ANIMATIONS //////////////////
  170.     CAnimationManager&  rAnimationManager = CAnimationManager::GetInstance();
  171.  
  172.     // Create interpolators for all regular animations
  173.  
  174.     // Load the animations
  175.     if (PickedChar == Catceye) {
  176.         m_pAnimations[ANIMATION_IDLE] = rAnimationManager.LoadAnimation("animations/joe_idle.tfa", "joe_Idle");
  177.         m_pAnimations[ANIMATION_RUN] = rAnimationManager.LoadAnimation("animations/joe_run.tfa", "joe_Run");
  178.         m_pAnimations[ANIMATION_SHOOT] = rAnimationManager.LoadAnimation("animations/joe_shoot.tfa", "joe_Shoot");
  179.         m_pAnimations[ANIMATION_HIT] = rAnimationManager.LoadAnimation("animations/joe_hit.tfa", "joe_Hit");
  180.         m_pAnimations[ANIMATION_CHARGEUP] = rAnimationManager.LoadAnimation("animations/joe_chargeup.tfa", "joe_Chargeup");
  181.         m_pAnimations[ANIMATION_CHARGEUP_LOOP] = rAnimationManager.LoadAnimation("animations/joe_chargeup_loop.tfa", "joe_Chargeup_Loop");
  182.         m_pAnimations[ANIMATION_LOWERBODY_JUMP] = rAnimationManager.LoadAnimation("animations/joe_jump.tfa", "Cupcake_Lowerbody_Jump");
  183.         m_pAnimations[ANIMATION_LOWERBODY_STAND] = rAnimationManager.LoadAnimation("animations/cupcake_lowerbody_stand.tfa", "Cupcake_Lowerbody_Stand");
  184.         m_pAnimations[ANIMATION_VICTORY] = rAnimationManager.LoadAnimation("animations/cactai_victory.tfa", "cactai_victory");
  185.         m_pAnimations[ANIMATION_VICTORY_LOOP] = rAnimationManager.LoadAnimation("animations/cactai_victory_loop.tfa", "cactai_victory_loop");
  186.     }
  187.     else if (PickedChar == Zuki) {
  188.         m_pAnimations[ANIMATION_IDLE] = rAnimationManager.LoadAnimation("animations/zuki_idle.tfa", "zuki_Idle");
  189.         m_pAnimations[ANIMATION_RUN] = rAnimationManager.LoadAnimation("animations/zuki_run.tfa", "zuki_Run");
  190.         m_pAnimations[ANIMATION_SHOOT] = rAnimationManager.LoadAnimation("animations/zuki_shoot.tfa", "zuki_Shoot");
  191.         m_pAnimations[ANIMATION_HIT] = rAnimationManager.LoadAnimation("animations/zuki_hit.tfa", "zuki_Hit");
  192.         m_pAnimations[ANIMATION_CHARGEUP] = rAnimationManager.LoadAnimation("animations/zuki_chargeup.tfa", "zuki_Chargeup");
  193.         m_pAnimations[ANIMATION_CHARGEUP_LOOP] = rAnimationManager.LoadAnimation("animations/zuki_chargeup_loop.tfa", "zuki_Chargeup_Loop");
  194.         m_pAnimations[ANIMATION_LOWERBODY_JUMP] = rAnimationManager.LoadAnimation("animations/zuki_jump.tfa", "zuki_Lowerbody_Jump");
  195.         m_pAnimations[ANIMATION_LOWERBODY_STAND] = rAnimationManager.LoadAnimation("animations/zuki_lowerbody_stand.tfa", "zuki_Lowerbody_Stand");
  196.         m_pAnimations[ANIMATION_VICTORY] = rAnimationManager.LoadAnimation("animations/zuki_victory.tfa", "zuki_Victory");
  197.     }
  198.     else if (PickedChar == Laguna) {
  199.         m_pAnimations[ANIMATION_IDLE] = rAnimationManager.LoadAnimation("animations/laguna_idle.tfa", "laguna_Idle");
  200.         m_pAnimations[ANIMATION_RUN] = rAnimationManager.LoadAnimation("animations/laguna_run.tfa", "laguna_Run");
  201.         m_pAnimations[ANIMATION_SHOOT] = rAnimationManager.LoadAnimation("animations/laguna_shoot.tfa", "laguna_Shoot");
  202.         m_pAnimations[ANIMATION_HIT] = rAnimationManager.LoadAnimation("animations/laguna_hit.tfa", "laguna_Hit");
  203.         m_pAnimations[ANIMATION_CHARGEUP] = rAnimationManager.LoadAnimation("animations/laguna_chargeup.tfa", "laguna_Chargeup");
  204.         m_pAnimations[ANIMATION_CHARGEUP_LOOP] = rAnimationManager.LoadAnimation("animations/laguna_chargeup_loop.tfa", "laguna_Chargeup_Loop");
  205.         m_pAnimations[ANIMATION_LOWERBODY_JUMP] = rAnimationManager.LoadAnimation("animations/laguna_jump.tfa", "laguna_Lowerbody_Jump");
  206.         m_pAnimations[ANIMATION_LOWERBODY_STAND] = rAnimationManager.LoadAnimation("animations/laguna_lowerbody_stand.tfa", "laguna_Lowerbody_Stand");
  207.         m_pAnimations[ANIMATION_VICTORY] = rAnimationManager.LoadAnimation("animations/laguna_victory.tfa", "laguna_Victory");
  208.         m_pAnimations[ANIMATION_VICTORY_LOOP] = rAnimationManager.LoadAnimation("animations/laguna_victory_loop.tfa", "laguna_victory_loop");
  209.     }
  210.     else {
  211.         m_pAnimations[ANIMATION_IDLE] = rAnimationManager.LoadAnimation("animations/cupcake_idle.tfa", "Cupcake_Idle");
  212.         m_pAnimations[ANIMATION_RUN] = rAnimationManager.LoadAnimation("animations/cupcake_run.tfa", "Cupcake_Run");
  213.         m_pAnimations[ANIMATION_SHOOT] = rAnimationManager.LoadAnimation("animations/cupcake_shoot.tfa", "Cupcake_Shoot");
  214.         m_pAnimations[ANIMATION_HIT] = rAnimationManager.LoadAnimation("animations/cupcake_hit.tfa", "Cupcake_Hit");
  215.         m_pAnimations[ANIMATION_CHARGEUP] = rAnimationManager.LoadAnimation("animations/cupcake_chargeup.tfa", "Cupcake_Chargeup");
  216.         m_pAnimations[ANIMATION_CHARGEUP_LOOP] = rAnimationManager.LoadAnimation("animations/cupcake_chargeup_loop.tfa", "Cupcake_Chargeup_Loop");
  217.         m_pAnimations[ANIMATION_LOWERBODY_JUMP] = rAnimationManager.LoadAnimation("animations/cupcake_lowerbody_jump.tfa", "Cupcake_Lowerbody_Jump");
  218.         m_pAnimations[ANIMATION_LOWERBODY_STAND] = rAnimationManager.LoadAnimation("animations/cupcake_lowerbody_stand.tfa", "Cupcake_Lowerbody_Stand");
  219.         m_pAnimations[ANIMATION_VICTORY] = rAnimationManager.LoadAnimation("animations/cupcake_victory.tfa", "cupcake_Victory");
  220.     }
  221.  
  222.     m_pInterpolators[INTERPOLATOR_CURRENT] = new tgCInterpolator(*m_pAnimations[m_CurrentAnimation]);
  223.     m_pInterpolators[INTERPOLATOR_NEXT] = new tgCInterpolator(*m_pAnimations[m_CurrentAnimation]);
  224.     m_pInterpolators[INTERPOLATOR_BLEND] = new tgCInterpolator(*m_pAnimations[m_CurrentAnimation]);
  225.  
  226.     m_pInterpolators[INTERPOLATOR_SUB] = new tgCInterpolator(*m_pAnimations[m_SubAnimation]);
  227.     m_pInterpolators[INTERPOLATOR_SUB]->SetEndOfInterpolatorCallBack(ShootOnceAnimationCB, this);
  228.  
  229.     m_pInterpolators[INTERPOLATOR_SUB_HIT] = new tgCInterpolator(*m_pAnimations[m_SubAnimationHit]);
  230.     m_pInterpolators[INTERPOLATOR_SUB_HIT]->SetEndOfInterpolatorCallBack(HitOnceAnimationCB, this);
  231. }
  232.  
  233. void CCharacter::InitModelAndTextures(tgSInt8 PickedChar, tgSInt8 PickedColor) {
  234.     tgCString CharName = "";
  235.     tgCString Color = "";
  236.  
  237.     switch (PickedColor)
  238.     {
  239.     case Blue:
  240.     {
  241.         Color = "blue";
  242.         break;
  243.     }
  244.     case Red:
  245.     {
  246.         Color = "red";
  247.         break;
  248.     }
  249.     case Green:
  250.     {
  251.         Color = "green";
  252.         break;
  253.     }
  254.     case Pink:
  255.     {
  256.         Color = "pink";
  257.         break;
  258.     }
  259.     case Orange:
  260.     {
  261.         Color = "orange";
  262.         break;
  263.     }
  264.     case Cyan:
  265.     {
  266.         Color = "cyan";
  267.         break;
  268.     }
  269.     default:
  270.         break;
  271.     }
  272.  
  273.     switch (PickedChar)
  274.     {
  275.     case Laguna:
  276.     {
  277.         CharName = "laguna";
  278.         break;
  279.     }
  280.     case Catceye:
  281.     {
  282.         CharName = "joe";
  283.         break;
  284.     }
  285.     case CupCake:
  286.     {
  287.         CharName = "cupcake";
  288.         break;
  289.     }
  290.     case Zuki:
  291.     {
  292.         CharName = "zuki";
  293.         break;
  294.     }
  295.     default:
  296.         break;
  297.     }
  298.  
  299.     tgCString PlayerTextureName = tgCString("char_%s_%s", CharName.String(), Color.String());
  300.     m_pModel = CModelManager::GetInstance().LoadModel(tgCString("models/char_%s.tfm", CharName.String()), CharName, true);
  301.     tgCTexture* Texture = tgCTextureManager::GetInstance().Create(PlayerTextureName);
  302.  
  303.     if (PickedChar == Zuki)
  304.     {
  305.         m_pModel->GetMesh(0)->GetSubMesh(2)->Material.SetColormap(*Texture);
  306.     }
  307.     else
  308.     {
  309.         m_pModel->GetMesh(0)->GetSubMesh(0)->Material.SetColormap(*Texture);
  310.     }
  311. }
  312.  
  313. void CCharacter::InitPhysics(void)
  314. {
  315.     tgFloat CharHeight = 2.20f;
  316.     tgFloat CharWidth = 0.6f;
  317.  
  318.     hkVector4 VertexTop = hkVector4(0.0f, (CharHeight - CharWidth * 2) * 0.5f, 0.0f);
  319.     hkVector4 VertexBot = hkVector4(0.0f, (CharHeight - CharWidth * 2) * -0.5f, 0.0f);
  320.  
  321.     hkVector4 CrouchVertexTop = hkVector4(0.0f, ((CharHeight / 3) - CharWidth * 2) * 0.5f, 0.0f);
  322.     hkVector4 CrouchVertexBot = hkVector4(0.0f, (CharHeight - CharWidth * 2) * -0.5f, 0.0f);
  323.  
  324.     hknpShape* ShapeStand = hknpCapsuleShape::createCapsuleShape(VertexTop, VertexBot, CharWidth);
  325.     //m_pShapeCrouch = hknpCapsuleShape::createCapsuleShape(CrouchVertexTop, CrouchVertexBot, CharWidth);
  326.  
  327.     m_AnalogJumpBoost = 0.0f;
  328.  
  329.     // Create rigid body
  330.     hknpCharacterRigidBodyCinfo Info;
  331.     Info.m_world = m_pWorld;
  332.     Info.m_mass = m_Mass;
  333.     Info.m_shape = ShapeStand;
  334.     Info.m_up.set(hkVector4(0.0f, 1.0f, 0.0f));
  335.     Info.m_weldingTolerance = 0.5f;
  336.     for (tgUInt32 i = 0; i < CTileManager::GetInstance().GetAllTiles().size(); i++)
  337.     {
  338.         if (CTileManager::GetInstance().GetAllTiles().at(i)->GetType() == CTile::TILETYPE_RESPAWNPOINT) {
  339.             m_RespawnTiles.push_back(CTileManager::GetInstance().GetAllTiles().at(i));
  340.         }
  341.     }
  342.  
  343.     tgUInt32 RespawnTile = GetAvailableRespawn(&m_RespawnTiles);
  344.  
  345.     m_NumRespawnTries = 0;
  346.  
  347.     tgCV3D RespawnPos;
  348.     if (m_RespawnTiles.size() <= 0)
  349.         RespawnPos = tgCV3D(-10.0f, 1.6f, 10.0f);
  350.     else
  351.         RespawnPos = m_RespawnTiles.at(RespawnTile)->GetPosition() + tgCV3D(0.0f, 1.6f, 0.0f);
  352.  
  353.     Info.m_position.set(hkVector4(RespawnPos.x, RespawnPos.y, RespawnPos.z));
  354.     m_Position = RespawnPos;
  355.     m_OccupiedRespawn = RespawnTile;
  356.     //  Info.m_maxSlope = 45.0f * HK_REAL_DEG_TO_RAD;
  357.     Info.m_maxForce = 250.0f;
  358.  
  359.     m_pRigidbody = new hknpCharacterRigidBody(Info);
  360.  
  361.     // Create state machine
  362.     hknpCharacterStateManager *pStateManager = new hknpCharacterStateManager();
  363.  
  364.     hknpCharacterStateOnGround *pStateOnGround = new hknpCharacterStateOnGround();
  365.     pStateOnGround->setSpeed(0.30f);
  366.  
  367.     pStateManager->registerState(pStateOnGround, hknpCharacterState::HK_CHARACTER_ON_GROUND);
  368.     pStateOnGround->removeReference();
  369.  
  370.     hknpCharacterStateInAir *pStateInAir = new hknpCharacterStateInAir();
  371.     pStateInAir->setSpeed(m_InAirSpeed);
  372.     pStateManager->registerState(pStateInAir, hknpCharacterState::HK_CHARACTER_IN_AIR);
  373.     pStateInAir->removeReference();
  374.  
  375.     if (m_IsPlayerCharacter) {
  376.         hknpCharacterStateJumping *pStateJumping = new hknpCharacterStateJumping();
  377.         pStateJumping->setJumpHeight(m_JumpHeight);
  378.         pStateManager->registerState(pStateJumping, hknpCharacterState::HK_CHARACTER_JUMPING);
  379.         pStateJumping->removeReference();
  380.     }
  381.     // Set up context
  382.     m_pContext = new hknpCharacterContext(pStateManager, hknpCharacterState::HK_CHARACTER_ON_GROUND);
  383.     m_pContext->setCharacterType(hknpCharacterContext::HK_CHARACTER_RIGIDBODY);
  384.  
  385.     UpdateCam(0.0f);
  386.  
  387.     m_pWorld->markForWrite();
  388.     m_pWorld->setBodyProperty<int>(m_pRigidbody->getBodyId(), 10008, 1);
  389.     m_pWorld->setBodyProperty<int>(m_pRigidbody->getBodyId(), 10000, 1);
  390.     m_pWorld->unmarkForWrite();
  391.  
  392.     m_pWorld->setBodyQuality(m_pRigidbody->getBodyId(), hknpBodyQualityId::PRESET_CHARACTER);
  393.  
  394.     ShapeStand->removeReference();
  395.     pStateManager->removeReference();
  396. }
  397.  
  398. CCharacter::~CCharacter(void)
  399. {
  400.     RumbleController(0.0f);
  401.     m_pContext->removeReference();
  402.  
  403. #if defined (TG_WINDOWS)
  404.     delete m_pGamePad;
  405. #elif defined(TG_PS4)
  406.     //delete m_pPad; Caused crash
  407.  
  408. #endif
  409.  
  410.     // Get reference to animation manager instance
  411.     CAnimationManager&  rAnimationManager = CAnimationManager::GetInstance();
  412.  
  413.     // Destroy the interpolators
  414.     for (tgUInt32 InterpolatorIndex = 0; InterpolatorIndex < INTERPOLATOR_SIZE; ++InterpolatorIndex)
  415.     {
  416.         if (m_pInterpolators[InterpolatorIndex])
  417.             delete m_pInterpolators[InterpolatorIndex];
  418.     }
  419.  
  420.     delete m_pCharCircleInterpolator;
  421.     delete m_pChargeArrowInterpolator;
  422.     delete m_pChargeMuzzleInterpolator;
  423.  
  424.     CModelManager::GetInstance().DestroyModel(m_pModel);
  425.     CModelManager::GetInstance().DestroyModel(m_pCharCircle);
  426.     CModelManager::GetInstance().DestroyModel(m_pChargeArrowModel);
  427.  
  428.     delete m_ModelMatrix;
  429.  
  430.     m_pRigidbody->removeReference();
  431. }
  432.  
  433. tgCInterpolator::ECallBackResult
  434. CCharacter::ShootOnceAnimationCB(tgCInterpolator& /*rInterpolator*/, void* pUserData)
  435. {
  436.     // Grab pointer to CPlayer item
  437.     CCharacter* pPlayer = (CCharacter*)pUserData;
  438.  
  439.     pPlayer->SetIsShooting(false);
  440.  
  441.     // Make the animation repeat itself
  442.     return tgCInterpolator::CALLBACK_RESULT_WRAP;
  443. }   // */ // AttackOnceAnimationCB
  444.  
  445. tgCInterpolator::ECallBackResult
  446. CCharacter::HitOnceAnimationCB(tgCInterpolator& /*rInterpolator*/, void* pUserData)
  447. {
  448.     // Grab pointer to CPlayer item
  449.     CCharacter* pPlayer = (CCharacter*)pUserData;
  450.  
  451.     pPlayer->SetGotHit(false);
  452.  
  453.     // Make the animation repeat itself
  454.     return tgCInterpolator::CALLBACK_RESULT_WRAP;
  455. }   // */ // AttackOnceAnimationCB
  456.  
  457. void CCharacter::UpdateCam(tgFloat DeltaTime)
  458. {
  459.     if (!m_IsDead) {
  460.         m_pWorld->getBodyTransform(m_pRigidbody->getBodyId()).get4x4ColumnMajor(reinterpret_cast<tgFloat*>(&m_pModel->GetTransform().GetMatrixLocal()));
  461.         m_pWorld->getBodyTransform(m_pRigidbody->getBodyId()).get4x4ColumnMajor(reinterpret_cast<tgFloat*>(&m_pChargeArrowModel->GetTransform().GetMatrixLocal()));
  462.         m_pWorld->getBodyTransform(m_pRigidbody->getBodyId()).get4x4ColumnMajor(reinterpret_cast<tgFloat*>(&m_pChargeMuzzleModel->GetTransform().GetMatrixLocal()));
  463.     }
  464. }
  465.  
  466. void CCharacter::UpdateCrouch(tgFloat /*DeltaTime*/)
  467. {
  468. }
  469.  
  470. void CCharacter::Update(tgFloat DeltaTime)
  471. {
  472.     tgUInt16 WindowWidth = tgCCore::GetInstance().GetWindowWidth();
  473.     tgUInt16 WindowHeight = tgCCore::GetInstance().GetWindowHeight();
  474.  
  475.     m_AliveTime += DeltaTime;
  476.  
  477.     m_ShootingCooldown += DeltaTime;
  478.     m_InitialSpawnTimer += DeltaTime;
  479.  
  480.     if (m_InitialSpawnTimer >= m_InitialSpawnTime && !m_HasSpawned) {
  481.         CAnimationHandler::GetInstance().SpawnRespawnAnimation(m_Position, m_PickedColor);
  482.         CAudioHandler::GetInstance().StartSound(CAudioHandler::RESPAWN);
  483.         m_HasSpawned = true;
  484.         m_OccupiedRespawn = 0;
  485.         if (m_RumbleActivated) {
  486.             RumbleController(0.5f);
  487.         }
  488.     }
  489.  
  490.     m_Rumble += DeltaTime;
  491.     m_Rumble = tgMathClamp(0.0f, m_Rumble, m_RumbleMax);
  492.  
  493.     if (m_Rumble < m_RumbleMax)
  494.         m_pGamePad->Rumble(m_RumbleValue, m_RumbleValue);
  495.     else
  496.         m_pGamePad->Rumble(0.0f, 0.0f);
  497.  
  498.     const tgCPluginInput&   rPluginInput = tgCPluginInput::GetInstance();
  499.  
  500.     m_pGamePad->Update();
  501.     m_Connected = m_pGamePad->GetConnected();
  502.  
  503.     HandleMovement(DeltaTime);
  504.     HandleShooting(DeltaTime);
  505.  
  506.     UpdateCam(DeltaTime);
  507.  
  508.     if (m_IsDead) {
  509.         m_RespawnTimer += DeltaTime;
  510.         m_RespawnTimer = tgMathClamp(0.0f, m_RespawnTimer, m_RespawnTime);
  511.     }
  512.  
  513.     // If fallen of, die
  514.     if (m_pWorld->getBodyTransform(m_pRigidbody->getBodyId()).getTranslation().getComponent(1) <= -6.0f) {
  515.         Die(0);
  516.     }
  517.  
  518.     // Respawn
  519.     if (m_IsDead && (m_RespawnTimer >= m_RespawnTime)) {
  520.         Respawn();
  521.     }
  522.  
  523.     // Animate
  524.     AnimateCharacter(DeltaTime);
  525.  
  526.     // Cheat codes
  527.     if (m_pGamePad->ButtonHeld(CGamepad::DPAD_LEFT) && m_pGamePad->ButtonHeld(CGamepad::DPAD_DOWN) && m_pGamePad->ButtonHeld(CGamepad::X)
  528.         && m_pGamePad->ButtonHeld(CGamepad::B) && m_pGamePad->LeftTrigger() > 0.0f)
  529.     {
  530.         CAudioHandler::GetInstance().StartSound(CAudioHandler::QUACK);
  531.         ActivateGodMode();
  532.     }
  533. }
  534.  
  535. void CCharacter::AnimateCharacter(tgFloat DeltaTime)
  536. {
  537.     if (m_JustJumped) {
  538.         m_NextAnimation = ANIMATION_LOWERBODY_JUMP;
  539.         m_JustJumped = false;
  540.     }
  541.  
  542.     if (m_CurrentAnimation != m_NextAnimation) {
  543.         m_BlendValue = 0.0f;
  544.         m_CurrentAnimation = m_NextAnimation;
  545.         m_pInterpolators[INTERPOLATOR_NEXT]->SetAnimation(*m_pAnimations[m_CurrentAnimation]);
  546.     }
  547.  
  548.     // Animate and blend /////////////////////////////////////////////
  549.     m_pCharCircleInterpolator->AddTime(DeltaTime);
  550.     m_pCharCircle->SetAnimationMatrices(*m_pCharCircleInterpolator);
  551.     m_pCharCircle->Update();
  552.  
  553.     tgFloat AnimationSpeed = DeltaTime;
  554.  
  555.     if (m_CurrentAnimation == ANIMATION_RUN) {
  556.         if (m_Connected)
  557.             AnimationSpeed = m_pGamePad->LeftStick().Length()  * DeltaTime;
  558.     }
  559.  
  560.     if (m_BlendValue < 1.0f) {
  561.         m_BlendValue += AnimationSpeed * m_BlendSpeed;
  562.         m_BlendValue = tgMathClamp(0.0f, m_BlendValue, 1.0f);
  563.  
  564.         //Still below 1.0f?
  565.         if (m_BlendValue < 1.0f) {
  566.             m_pInterpolators[INTERPOLATOR_CURRENT]->AddTime(AnimationSpeed);
  567.             m_pInterpolators[INTERPOLATOR_NEXT]->AddTime(AnimationSpeed);
  568.             m_pInterpolators[INTERPOLATOR_BLEND]->Blend(*m_pInterpolators[INTERPOLATOR_CURRENT], *m_pInterpolators[INTERPOLATOR_NEXT], m_BlendValue);
  569.             m_pModel->SetAnimationMatrices(*m_pInterpolators[INTERPOLATOR_BLEND]);
  570.         }
  571.         else {
  572.             m_pInterpolators[INTERPOLATOR_CURRENT]->SetAnimation(*m_pInterpolators[INTERPOLATOR_NEXT]->GetAnimation());
  573.             m_pInterpolators[INTERPOLATOR_CURRENT]->SetTime(m_pInterpolators[INTERPOLATOR_NEXT]->GetTime());
  574.             m_pInterpolators[INTERPOLATOR_CURRENT]->AddTime(AnimationSpeed);
  575.             m_pModel->SetAnimationMatrices(*m_pInterpolators[INTERPOLATOR_CURRENT]);
  576.         }
  577.     }
  578.     else {
  579.         m_pInterpolators[INTERPOLATOR_CURRENT]->AddTime(AnimationSpeed);
  580.         m_pModel->SetAnimationMatrices(*m_pInterpolators[INTERPOLATOR_CURRENT]);
  581.     }
  582.  
  583.     if (m_IsShooting) {
  584.         if (m_CurrentAnimation == ANIMATION_RUN) {
  585.             m_pInterpolators[INTERPOLATOR_CURRENT]->AddTime(AnimationSpeed);
  586.             m_pModel->SetAnimationMatrices(*m_pInterpolators[INTERPOLATOR_CURRENT]);
  587.     }
  588.         m_pInterpolators[INTERPOLATOR_SUB]->AddTime(AnimationSpeed);
  589.         m_pModel->SetAnimationMatrices(*m_pInterpolators[INTERPOLATOR_SUB]);
  590.     }
  591.  
  592.     if (m_GotHit) {
  593.         m_pInterpolators[INTERPOLATOR_SUB_HIT]->AddTime(AnimationSpeed);
  594.         m_pModel->SetAnimationMatrices(*m_pInterpolators[INTERPOLATOR_SUB_HIT]);
  595.     }
  596.  
  597.     if (!RStick_InDeadZone && m_Connected)
  598.         m_pModel->GetTransform().GetMatrixLocal().At = tgCV3D(-m_ModelDir.x, 0.f, -m_ModelDir.y);
  599.     else if (!m_Connected) {
  600.         m_pModel->GetTransform().GetMatrixLocal().RotateY(m_Yaw, tgCMatrix::COMBINE_PRE_MULTIPLY);
  601.     }
  602.     else
  603.     {
  604.         m_pModel->GetTransform().GetMatrixLocal().At = tgCV3D(-m_DirNormalized.x, 0.f, -m_DirNormalized.y);
  605.     }
  606.  
  607.     RStick_InDeadZone = true;
  608.  
  609.     if (!m_IsDead) {
  610.         m_pModel->GetTransform().GetMatrixLocal().OrthoNormalize();
  611.  
  612.         if (m_IsInTheLead) {
  613.             m_pModel->GetTransform().GetMatrixLocal().Scale(tgCV3D(1.3f, 1.3f, 1.3f), tgCMatrix::COMBINE_PRE_MULTIPLY);
  614.         }
  615.         else {
  616.             m_pModel->GetTransform().GetMatrixLocal().Scale(tgCV3D(1.0f, 1.0f, 1.0f), tgCMatrix::COMBINE_PRE_MULTIPLY);
  617.         }
  618.  
  619.         m_pModel->Update();
  620.     }
  621. }
  622.  
  623.  
  624. void CCharacter::HandleMovement(tgFloat DeltaTime) {
  625.     const tgCPluginInput&   rPluginInput = tgCPluginInput::GetInstance();
  626.  
  627.     // Reset the next animation to IDLE
  628.     m_NextAnimation = ANIMATION_IDLE;
  629.  
  630.     if (!m_Connected) {
  631.         // Calculate mouse movement
  632.         const tgSInt32  MoveX = rPluginInput.GetMouseMoveX();
  633.         const tgSInt32  MoveY = rPluginInput.GetMouseMoveY();
  634.         if (rPluginInput.KeyHeld('W') || rPluginInput.KeyHeld('S') || rPluginInput.KeyHeld('A') || rPluginInput.KeyHeld('D')) {
  635.             m_NextAnimation = ANIMATION_RUN;
  636.         }
  637.         //If mouse have moved
  638.         if (MoveX != 0 || MoveY != 0)
  639.         {
  640.             m_Yaw -= MoveX * m_Sensitivity;
  641.             m_Pitch += MoveY * m_Sensitivity;
  642.             m_Pitch = tgMathClamp(-89.0f, m_Pitch, 89.0f);
  643.  
  644.             if (m_Yaw > 359.0f)
  645.                 m_Yaw = 0.0f;
  646.             if (m_Yaw < 0.0f)
  647.                 m_Yaw = 359.f;
  648.             m_Yaw = tgMathClamp(-1.0f, m_Yaw, 359.0f);
  649.  
  650.             m_DirNonNormalized = tgCV2D(MoveX, -MoveY);
  651.             m_DirNormalized = tgCV2D(MoveX, -MoveY);
  652.             m_DirNormalized.Normalize();
  653.             m_ModelDir = tgCV2D(MoveX, -MoveY);
  654.         }
  655.     }
  656.     else {
  657.         if (!m_pGamePad->LStick_InDeadZone()) {
  658.             const tgFloat MoveX = m_pGamePad->LeftStick().x;
  659.             const tgFloat MoveY = m_pGamePad->LeftStick().y;
  660.  
  661.             m_DirNonNormalized = tgCV2D(MoveX, -MoveY);
  662.             m_DirNormalized = tgCV2D(MoveX, -MoveY);
  663.             m_DirNormalized.Normalize();
  664.             m_ModelDir = tgCV2D(MoveX, -MoveY);
  665.  
  666.             m_NextAnimation = ANIMATION_RUN;
  667.         }
  668.         if (!m_pGamePad->RStick_InDeadZone()) {
  669.             const tgFloat MoveX = m_pGamePad->RightStick().x;
  670.             const tgFloat MoveY = m_pGamePad->RightStick().y;
  671.  
  672.             m_ModelDir = tgCV2D(MoveX, -MoveY);
  673.             RStick_InDeadZone = false;
  674.         }
  675.         else
  676.         {
  677.             if (m_pGamePad->LStick_InDeadZone()) {
  678.                 m_DirNonNormalized = m_ModelDir;
  679.                 m_DirNormalized = m_ModelDir;
  680.                 m_DirNormalized.Normalize();
  681.             }
  682.         }
  683.         if (m_pGamePad->ButtonHeld(CGamepad::A)) {
  684.             m_NextAnimation = ANIMATION_LOWERBODY_JUMP;
  685.         }
  686.     }
  687. }
  688.  
  689. void CCharacter::HandleShooting(tgFloat DeltaTime)
  690. {
  691.     const tgCPluginInput&   rPluginInput = tgCPluginInput::GetInstance();
  692.     tgUInt16 WindowWidth = tgCCore::GetInstance().GetWindowWidth();
  693.     tgUInt16 WindowHeight = tgCCore::GetInstance().GetWindowHeight();
  694.     // PC Controls
  695.     if (m_GodMode)
  696.     {
  697.         if ((m_pGamePad->ButtonHeld(CGamepad::RB) || m_pGamePad->RightTrigger() > 0.0f)) {
  698.             ShootGrenade(m_GrenadeForce);
  699.         }
  700.     }
  701.  
  702.     if (m_ShootingCooldown >= m_ShootingCooldownMax) {
  703.         // Charge grenade forcek
  704.         if ((m_pGamePad->ButtonHeld(CGamepad::RB) || m_pGamePad->RightTrigger() > 0.0f)) {
  705.             if (m_GrenadeForce >= m_GrenadeForceMax && !m_HasPlayedChargeupSound) {
  706.                 m_HasPlayedChargeupSound = true;
  707.             }
  708.  
  709.             m_GrenadeForce = tgMathClamp(m_GrenadeForceMin, m_GrenadeForce, m_GrenadeForceMax);
  710.             m_GrenadeForce += DeltaTime * m_GrenadeChargeRate;
  711.  
  712.             if (m_PickedUpPowerup == POWERUP_MAX_CHARGEUP)
  713.                 m_GrenadeForce = m_GrenadeForceMax;
  714.  
  715.             if (m_GrenadeForce >= m_GrenadeForceMax) {
  716.                 m_NextAnimation = ANIMATION_CHARGEUP_LOOP;
  717.             }
  718.             else {
  719.                 m_NextAnimation = ANIMATION_CHARGEUP;
  720.             }
  721.  
  722.             m_ChargingUp = true;
  723.  
  724.             // Animate the chargup arrow
  725.             if (m_pChargeArrowInterpolator->GetTime() <= (m_pChargeArrowAnimation->GetDuration() - 0.1f)) {
  726.                 m_pChargeArrowInterpolator->AddTime(DeltaTime * m_GrenadeChargeRate * 0.775f);
  727.                 m_pChargeArrowModel->SetAnimationMatrices(*m_pChargeArrowInterpolator);
  728.             }
  729.  
  730.             m_pChargeArrowModel->GetTransform().GetMatrixLocal().At = m_pModel->GetTransform().GetMatrixLocal().At;
  731.             m_pChargeArrowModel->GetTransform().GetMatrixLocal().Up = m_pModel->GetTransform().GetMatrixLocal().Up;
  732.             m_pChargeArrowModel->GetTransform().GetMatrixLocal().Left = m_pModel->GetTransform().GetMatrixLocal().Left;
  733.  
  734.             m_pChargeArrowModel->GetTransform().GetMatrixLocal().Pos.y = (m_pModel->GetTransform().GetMatrixLocal().Pos.y + 0.05f);
  735.             m_pChargeArrowModel->GetTransform().GetMatrixLocal().Scale(tgCV3D(3.0f, 3.0f, 3.0f), tgCMatrix::COMBINE_PRE_MULTIPLY);
  736.  
  737.             m_pChargeArrowModel->Update();
  738.  
  739.             // Animate chargeup muzzle
  740.  
  741.             // Animate the chargup arrow
  742.             if (m_pChargeMuzzleInterpolator->GetTime() <= (m_pChargeMuzzleAnimation->GetDuration() - 0.1f)) {
  743.                 m_pChargeMuzzleInterpolator->AddTime(DeltaTime * m_GrenadeChargeRate * 0.775f);
  744.                 m_pChargeMuzzleModel->SetAnimationMatrices(*m_pChargeMuzzleInterpolator);
  745.             }
  746.  
  747.             m_pChargeMuzzleModel->GetTransform().GetMatrixLocal().At = m_pModel->GetTransform().GetMatrixLocal().At;
  748.             m_pChargeMuzzleModel->GetTransform().GetMatrixLocal().Up = m_pModel->GetTransform().GetMatrixLocal().Up;
  749.             m_pChargeMuzzleModel->GetTransform().GetMatrixLocal().Left = m_pModel->GetTransform().GetMatrixLocal().Left;
  750.  
  751.             m_pChargeMuzzleModel->GetTransform().GetMatrixLocal().Pos.y = (m_pModel->GetTransform().GetMatrixLocal().Pos.y + 0.05f);
  752.             //m_pChargeMuzzleModel->GetTransform().GetMatrixLocal().Scale(tgCV3D(3.0f, 3.0f, 3.0f), tgCMatrix::COMBINE_PRE_MULTIPLY);
  753.  
  754.             m_pChargeMuzzleModel->Update();
  755.         }
  756.  
  757.         // Shoot grenade
  758.         if (((m_pGamePad->ButtonReleased(CGamepad::RB)) || ((m_pGamePad->RightTrigger() == 0.0f && m_GrenadeForce > 0.0f) && !m_pGamePad->ButtonHeld(CGamepad::RB)))) {
  759.             if (!m_IsShooting) {
  760.                 m_IsShooting = true;
  761.                 m_pInterpolators[INTERPOLATOR_SUB]->SetTime(0.0f);
  762.             }
  763.             else {
  764.                 m_pInterpolators[INTERPOLATOR_SUB]->SetTime(0.0f);
  765.             }
  766.  
  767.             ShootGrenade(m_GrenadeForce);
  768.  
  769.             if (m_PickedUpPowerup == POWERUP_BURST) {
  770.                 m_BurstedAmount = 1;
  771.                 m_ShouldBurst = true;
  772.                 m_BurstForce = m_GrenadeForce;
  773.             }
  774.  
  775.             m_GrenadeForce = 0.0f;
  776.             m_ShootingCooldown = 0.0f;
  777.             m_HasPlayedChargeupSound = false;
  778.             // Reset the animation
  779.             m_pChargeArrowInterpolator->SetTime(0.0f);
  780.             m_pChargeMuzzleInterpolator->SetTime(0.0f);
  781.         }
  782.     }
  783.  
  784.     // Explode all grenades
  785.     if (m_pGamePad->LeftTrigger() > 0.0f || m_pGamePad->ButtonPressed(CGamepad::LB)) {
  786.         for (tgUInt32 i = 0; i < CBodyManager::GetInstance().GetAllBodies().size(); i++)
  787.         {
  788.             CGrenade* Grenade = CBodyManager::GetInstance().GetAllBodies()[i];
  789.  
  790.             if (Grenade->GetPlayerTag() == m_PlayerTag && Grenade->GetTime() >= 0.1f) {
  791.                 if (!Grenade->GetShouldExplode() && Grenade->GetPowerupType() != CGrenade::CLUSTER_SPAWN) {
  792.                     Grenade->DetonateGrenade(m_PickedUpPowerup, DeltaTime);
  793.                 }
  794.             }
  795.         }
  796.     }
  797. }
  798.  
  799. void CCharacter::Die(tgUInt32 DeathType)
  800. {
  801.     if (!m_IsInvulnerable) {
  802.         CCharacter* Killer = this;
  803.  
  804.         if (!m_IsDead) {
  805.             m_OccupiedRespawn = GetAvailableRespawn(&m_RespawnTiles);
  806.         }
  807.  
  808.         m_IsDead = true;
  809.         m_KillStreak = 0;
  810.  
  811.         if (!m_AddedScore) {
  812.             m_pBloodParticleTransform = &m_pModel->GetTransform();
  813.  
  814.             if (DeathType == CUIHandler::NORMAL_DEATH_ICON && m_TaggedBy == m_PlayerTag)
  815.                 CUIHandler::GetInstance().AddPlayerKilledText(m_TaggedBy, m_PlayerTag, CUIHandler::SUICIDE_DEATH_ICON);
  816.             else
  817.                 CUIHandler::GetInstance().AddPlayerKilledText(m_TaggedBy, m_PlayerTag, DeathType);
  818.         }
  819.  
  820.         // Poor sucker
  821.         if (m_TaggedBy == m_PlayerTag && !m_AddedScore) {
  822.  
  823.             PlayFallDeathSound();
  824.  
  825.             //m_Score--;
  826.             m_AddedScore = true;
  827.             m_Stats.Deaths++;
  828.         }
  829.  
  830.         if (!m_AddedScore) {
  831.             for (tgUInt32 i = 0; i < CGameStates::GetInstance().GetStateGame()->GetCharacters()->size(); i++)
  832.             {
  833.                 if (CGameStates::GetInstance().GetStateGame()->GetCharacters()->at(i)->GetPlayerTag() == m_TaggedBy) {
  834.                     Killer = CGameStates::GetInstance().GetStateGame()->GetCharacters()->at(i);
  835.  
  836.                     if (m_IsInTheLead) {
  837.                         Killer->AddScore(true);
  838.                     }
  839.                     else
  840.                         Killer->AddScore(false);
  841.  
  842.                     m_AddedScore = true;
  843.  
  844.                     if (DeathType == CUIHandler::NORMAL_DEATH_ICON) {
  845.                         PlayFallDeathSound();
  846.                     }
  847.                 }
  848.             }
  849.  
  850.         }
  851.     }
  852. }
  853.  
  854. tgUInt32 CCharacter::GetAvailableRespawn(std::vector<CTile*>* Tiles) {
  855.     m_NumRespawnTries++;
  856.  
  857.     if (Tiles->size() <= 0)
  858.         return 0;
  859.  
  860.     tgUInt32 RandSpawn = tgMathRandom(0, Tiles->size());
  861.  
  862.     if (RandSpawn == Tiles->size())
  863.         RandSpawn = RandSpawn - 1;
  864.  
  865.     tgUInt32 NumPlayers = CGameStates::GetInstance().GetStateGame()->GetCharacters()->size();
  866.     tgUInt32 CheckedPlayers = 0;
  867.  
  868.     for (tgUInt32 i = 0; i < NumPlayers; i++)
  869.     {
  870.         CCharacter* Player = CGameStates::GetInstance().GetStateGame()->GetCharacters()->at(i);
  871.  
  872.         // Check if this tile is occupied by a respawning player
  873.         if ((Player->GetOccupiedRespawn() != RandSpawn) {
  874.             ++CheckedPlayers;
  875.             if (CheckedPlayers >= NumPlayers) {
  876.                 return GetAvailableRespawn(Tiles);
  877.             }
  878.         }
  879.        
  880.     }
  881.  
  882.     return RandSpawn;
  883. }
  884.  
  885. void CCharacter::Respawn(void)
  886. {
  887.     m_RespawnTimer = 0.0f;
  888.     m_HitPercentage = 0.0f;
  889.     m_ShouldRenderOnlyAmbient = false;
  890.     m_IsDead = false;
  891.     m_AddedScore = false;
  892.     m_TaggedBy = m_PlayerTag;
  893.     m_GrenadeForce = 0.0f;
  894.     m_PickedUpPowerup = 0;
  895.     m_NumRespawnTries = 0;
  896.  
  897.     tgCV3D RespawnPos;
  898.     if (m_RespawnTiles.size() <= 0)
  899.         RespawnPos = tgCV3D(0.0f, 2.0f, 0.0f);
  900.     else {
  901.         RespawnPos = m_RespawnTiles.at(m_OccupiedRespawn)->GetPosition() + tgCV3D(0.0f, 2.0f, 0.0f);
  902.     }
  903.  
  904.     m_pWorld->setBodyPosition(m_pRigidbody->getBodyId(), hkVector4(RespawnPos.x, RespawnPos.y, RespawnPos.z));
  905.     m_pWorld->setBodyLinearVelocity(m_pRigidbody->getBodyId(), hkVector4(0.0f, 0.0f, 0.0f));
  906.  
  907.     CAnimationHandler::GetInstance().SpawnRespawnAnimation(RespawnPos, m_PickedColor);
  908.  
  909.     m_OccupiedRespawn = 0;
  910.  
  911.     m_InvulnerabilityTimer = 0.0f;
  912.  
  913.     CAudioHandler::GetInstance().StartSound(CAudioHandler::RESPAWN);
  914.  
  915.     RumbleController(0.3f);
  916. }
  917.  
  918. void CCharacter::ShootGrenade(tgFloat Force)
  919. {
  920.     CAudioHandler::GetInstance().StartSound(CAudioHandler::GRENADE_FLOMPF);
  921.  
  922.     // Spawn Muzzle flash
  923.     tgSInt32 MuzzleWeaponIndex = m_pModel->GetJointIDFromName("gun_flash");
  924.     tgUInt32 MuzzleJointID = m_pModel->GetJoint(MuzzleWeaponIndex)->HierarchyID;
  925.     tgCMatrix NewMatrix = m_pModel->GetHierarchy(MuzzleJointID)->Transform.GetMatrixWorld();
  926.     CAnimationHandler::GetInstance().SpawnMuzzleFlashAnimation(NewMatrix.Pos, m_pModel->GetTransform().GetMatrixLocal(), m_PickedChar);
  927.  
  928.     // Get pos in front of character SPAWN FROM JOINT "AIM"
  929.     tgSInt32 weaponIndex = m_pModel->GetJointIDFromName("aim");
  930.     tgUInt32 JointID = m_pModel->GetJoint(weaponIndex)->HierarchyID;
  931.     tgSModelHierarchy* Hierarchy = m_pModel->GetHierarchy(JointID);
  932.     tgCV3D Pos = Hierarchy->Transform.GetMatrixWorld().Pos;
  933.  
  934.     hkVector4 hkPos = hkVector4(Pos.x, Pos.y, Pos.z);
  935.  
  936.     tgCV3D LinVel;
  937.     if (m_Connected)
  938.         LinVel = (m_pModel->GetTransform().GetMatrixWorld().At + (tgCV3D::PositiveY * m_Angle)) * (Force * m_ShootingForce);
  939.     else
  940.     {
  941.         tgCV3D DirTransformed;
  942.         DirTransformed.TransformVector(m_pModel->GetTransform().GetMatrixLocal().At, m_pModel->GetTransform().GetMatrixWorld());
  943.         LinVel = (Hierarchy->Transform.GetMatrixWorld().At + (tgCV3D::PositiveY * m_Angle)) * (Force * m_ShootingForce);
  944.     }
  945.     hkVector4 hkLinVel = hkVector4(LinVel.x, LinVel.y, LinVel.z);
  946.  
  947.     CBodyManager::GetInstance().AddNewBody(Pos, LinVel, m_PlayerTag, false, CGrenade::NO_POWERUP);
  948. }
  949.  
  950. void CCharacter::UpdatePhysics(tgFloat DeltaTime)
  951. {
  952.     if (!m_IsDead && CGameStates::GetInstance().GetStateGame()->CountDownFinished()) {
  953.         const tgCPluginInput&   rPluginInput = tgCPluginInput::GetInstance();
  954.         hknpCharacterInput Input;
  955.         Input.m_inputUD = 0.0f;
  956.         Input.m_inputLR = 0.0f;
  957.  
  958.         Input.m_wantJump = false;
  959.  
  960.         //If controller is not connected use keyboard and mouse input
  961.         if (!m_Connected) {
  962.             if (m_GrenadeForce <= 0.0f && m_IsPlayerCharacter) {
  963.                 tgFloat MovementScaling = 1.0f;
  964.  
  965.                 Input.m_wantJump = rPluginInput.KeyHeld(VK_SPACE);
  966.  
  967.                 if (Input.m_wantJump)
  968.                     m_JustJumped = true;
  969.  
  970.                 if (rPluginInput.KeyHeld(VK_SPACE))
  971.                     m_AnalogJumpBoost += DeltaTime * 10.0f;
  972.                 else
  973.                     m_AnalogJumpBoost = 0.0f;
  974.  
  975.                 if (rPluginInput.KeyHeld('W')) {
  976.                     Input.m_inputUD -= m_MovementSpeed * MovementScaling;
  977.                     m_IsShooting = false;
  978.                 }
  979.                 if (rPluginInput.KeyHeld('S')) {
  980.                     Input.m_inputUD += m_MovementSpeed * MovementScaling;
  981.                     m_IsShooting = false;
  982.                 }
  983.                 if (rPluginInput.KeyHeld('A')) {
  984.                     Input.m_inputLR += m_MovementSpeed * MovementScaling;
  985.                     m_IsShooting = false;
  986.                 }
  987.                 if (rPluginInput.KeyHeld('D')) {
  988.                     Input.m_inputLR -= m_MovementSpeed * MovementScaling;
  989.                     m_IsShooting = false;
  990.                 }
  991.             }
  992.         }
  993.  
  994.         //If controller is connected
  995.         else {
  996.             if (m_IsPlayerCharacter) {
  997.                 tgFloat MovementScaling = 1.0f;
  998.  
  999.                 if (CGameStates::GetInstance().GetStateGame()->GetDebugChargeupMode() == 2) {
  1000.                     MovementScaling = 1.0f - (m_GrenadeForce * 0.4f);
  1001.  
  1002.                     if (m_GrenadeForce > (m_GrenadeForceMax * 0.65f))
  1003.                         MovementScaling = 0.0f;
  1004.  
  1005.                     if (MovementScaling <= 0.0f)
  1006.                         MovementScaling = 0.0f;
  1007.                 }
  1008.                 else if (CGameStates::GetInstance().GetStateGame()->GetDebugChargeupMode() == 1 && m_GrenadeForce > 0) {
  1009.                     MovementScaling = 0.0f;
  1010.                 }
  1011.                 else if (m_GrenadeForce > 0) {
  1012.                     MovementScaling = 0.2f;
  1013.                 }
  1014.  
  1015.                 if (m_GodMode)
  1016.                 {
  1017.                     MovementScaling = 4.0f;
  1018.                 }
  1019.                 //Does not do anything if the left stick is in the deadzone
  1020.                 if (!m_pGamePad->LStick_InDeadZone()) {
  1021.                     if (!(m_PickedUpPowerup == POWERUP_MOVEMENTSPEED))
  1022.                         Input.m_inputUD += m_DirNonNormalized.Length() * m_MovementSpeed * MovementScaling;
  1023.                     else
  1024.                         Input.m_inputUD += m_DirNonNormalized.Length() * m_MovementSpeed * 4.0f;
  1025.  
  1026.                     m_IsShooting = false;
  1027.                 }
  1028.                 //Checks for 'A' on a XBOX Controller, 'A' on a XBOX Controller is 'X' on a PS Controller
  1029.                 Input.m_wantJump = m_pGamePad->ButtonHeld(CGamepad::A);
  1030.  
  1031.                 if (Input.m_wantJump)
  1032.                     m_JustJumped = true;
  1033.  
  1034.                 if (m_pGamePad->ButtonHeld(CGamepad::A))
  1035.                     m_AnalogJumpBoost += DeltaTime * 10.0f;
  1036.                 else
  1037.                     m_AnalogJumpBoost = 0.0f;
  1038.             }
  1039.         }
  1040.  
  1041.         Input.m_atLadder = false;
  1042.         Input.m_up.set(hkVector4(0.0f, 1.0f, 0.0f));
  1043.  
  1044.         if (!m_Connected) {
  1045.             hkQuaternion CurrentOriantation;
  1046.             CurrentOriantation.setAxisAngle(Input.m_up, 0.0f * HK_FLOAT_DEG_TO_RAD);
  1047.             Input.m_forward.setRotatedDir(CurrentOriantation, hkVector4(0.F, 0.f, 1.f));
  1048.         }
  1049.         else {
  1050.             Input.m_forward.set(hkVector4(m_DirNormalized.x, 0.f, m_DirNormalized.y));
  1051.         }
  1052.  
  1053.         Input.m_stepInfo.m_deltaTime = DeltaTime;
  1054.         Input.m_stepInfo.m_invDeltaTime = 1.0f / DeltaTime;
  1055.         Input.m_characterGravity.set(hkVector4(0.0f, -55.0f, 0.0f));
  1056.  
  1057.         //Input.m_characterGravity.set(hkVector4(0.0f, -85.0f, 0.0f));
  1058.         Input.m_velocity = m_pRigidbody->getLinearVelocity();
  1059.         Input.m_position = m_pRigidbody->getPosition();
  1060.  
  1061.         m_pRigidbody->checkSupport(Input.m_stepInfo, Input.m_surfaceInfo);
  1062.  
  1063.         hknpCharacterOutput Output;
  1064.  
  1065.         m_pContext->update(Input, Output);
  1066.  
  1067.         // Limit analog jump
  1068.         if (m_AnalogJumpBoost >= 0.5f)
  1069.             m_AnalogJumpBoost = 0.0f;
  1070.  
  1071.         m_pRigidbody->setLinearVelocity(hkVector4(Output.m_velocity(0), Output.m_velocity(1) + (m_AnalogJumpBoost), Output.m_velocity(2)), DeltaTime, Input.m_wantJump);
  1072.     }  
  1073. }
  1074.  
  1075. void CCharacter::Render(void)
  1076. {
  1077.     m_pModel->GetTransform().GetMatrixLocal().Up = tgCV3D::PositiveY;
  1078.     m_Position = m_pModel->GetTransform().GetMatrixLocal().Pos;
  1079.  
  1080.     // Cast ray on ground
  1081.     hknpRayCastQuery RayQuery;
  1082.     hknpClosestHitCollector Collector;
  1083.     hknpCollisionResult RayCastResult;
  1084.  
  1085.     hkcdRay Ray;
  1086.     Ray.setOriginDirection(m_pRigidbody->getPosition(), hkVector4(0.0f, -1.0f, 0.0f));
  1087.     Ray.setEndPoints(m_pRigidbody->getPosition(), hkVector4(m_pRigidbody->getPosition()(0), m_pRigidbody->getPosition()(1) - 20.0f, m_pRigidbody->getPosition()(2)));
  1088.  
  1089.     RayQuery.m_ray = Ray;
  1090.  
  1091.     m_pWorld->castRay(RayQuery, &Collector);
  1092.  
  1093.     if (Collector.hasHit()) {
  1094.         RayCastResult = Collector.getHit();
  1095.         m_pShadowModel->GetTransform().GetMatrixLocal().Translate(tgCV3D(RayCastResult.m_position(0), RayCastResult.m_position(1), RayCastResult.m_position(2)), tgCMatrix::COMBINE_REPLACE);
  1096.  
  1097.         if (RayCastResult.m_position(1) < 0.0f) {
  1098.             m_pCharCircle->GetTransform().GetMatrixLocal().Translate(tgCV3D(m_Position.x, 0.0f, m_Position.z), tgCMatrix::COMBINE_REPLACE);
  1099.         }
  1100.         else if (m_pModel->GetTransform().GetMatrixLocal().Pos.y > 0.0f) {
  1101.             m_pCharCircle->GetTransform().GetMatrixLocal().Translate(tgCV3D(RayCastResult.m_position(0), RayCastResult.m_position(1), RayCastResult.m_position(2)), tgCMatrix::COMBINE_REPLACE);
  1102.         }
  1103.         else {
  1104.             m_pCharCircle->GetTransform().GetMatrixLocal().Translate(m_Position, tgCMatrix::COMBINE_REPLACE);
  1105.         }
  1106.  
  1107.         m_pCharCircle->GetTransform().Update();
  1108.     }
  1109.  
  1110.     m_pShadowModel->GetTransform().GetMatrixLocal().Scale(tgCV3D(2.0f, 2.0f, 2.0f), tgCMatrix::COMBINE_PRE_MULTIPLY);
  1111.     m_pShadowModel->GetTransform().Update();
  1112.  
  1113.  
  1114.     const CLightManager::SLight*    pLightArray = CLightManager::GetInstance().GetLightArray();
  1115.     tgCLightManager&                rLightManager = tgCLightManager::GetInstance();
  1116.  
  1117.     // Render player model and shadowmodel
  1118.     if (!m_IsDead && m_InitialSpawnTimer >= m_InitialSpawnTime) {
  1119.         for (tgUInt32 LightIndex = 0; LightIndex < MAX_NUM_LIGHTS; ++LightIndex)
  1120.         {
  1121.             if (pLightArray[LightIndex].pLight)
  1122.             {
  1123.                 rLightManager.SetCurrentLight(*pLightArray[LightIndex].pLight);
  1124.  
  1125.                 if (m_ShouldRenderOnlyAmbient && rLightManager.GetCurrentLight()->GetType() == tgCLight::TYPE_AMBIENT)
  1126.                     m_pModel->Render();
  1127.  
  1128.                 if (!m_ShouldRenderOnlyAmbient) {
  1129.                     if (rLightManager.GetCurrentLight()->GetType() == tgCLight::TYPE_DIRECTIONAL)
  1130.                         CLightManager::GetInstance().GetLight("Directional")->SetIntensity(0.5f);
  1131.  
  1132.                     m_pModel->Render();
  1133.                 }
  1134.             }
  1135.         }
  1136.     }
  1137.     if (!m_IsDead && m_InitialSpawnTimer >= m_InitialSpawnTime) {
  1138.         if (m_GrenadeForce > 0.0f) {
  1139.             m_pChargeArrowModel->Render();
  1140.             m_pChargeMuzzleModel->Render();
  1141.         }
  1142.     }
  1143.  
  1144. }
  1145.  
  1146. void CCharacter::PlayDamagedSound(void)
  1147. {
  1148.     CAudioHandler::GetInstance().PlayDamagedVoice(m_PickedChar);
  1149. }
  1150.  
  1151. void CCharacter::PlayFallDeathSound(void)
  1152. {
  1153.     CAudioHandler::GetInstance().PlayDeathVoice(m_PickedChar);
  1154. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top