CMinotaur::CMinotaur(const XMFLOAT3& spawnPosition, CObjectManager* _manager, CAnimationManager* _animManager) : CBoid(15.0f, 300.0f, "Minotaur") { // Drop Shadow Creation // CMesh cDropShadow; cDropShadow.GetIndices().push_back(0); cDropShadow.GetIndices().push_back(1); cDropShadow.GetIndices().push_back(2); cDropShadow.GetIndices().push_back(0); cDropShadow.GetIndices().push_back(2); cDropShadow.GetIndices().push_back(3); cDropShadow.GetVertices().push_back ({ { -400.0f, 3.0f, 400.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, { 0, 0 } }); cDropShadow.GetVertices().push_back ({ { 400.0f, 3.0f, 400.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, { 1, 0 } }); cDropShadow.GetVertices().push_back ({ { 400.0f, 3.0f, -400.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, { 1, 1 } }); cDropShadow.GetVertices().push_back ({ { -400.0f, 3.0f, -400.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, { 0, 1 } }); m_cDropShadow = new CRenderMesh(&cDropShadow, GRAPHICS->GetStandardVS(), GRAPHICS->GetStandardPS()); m_cDropShadow->SetTexture(L"../Game/Assets/Art/2D/Textures/Shadow.dds"); m_cDropShadow->GetTransparent() = true; m_cDropShadow->GetRender() = false; GRAPHICS->AddRenderMesh(m_cDropShadow); XMStoreFloat4x4(&m_mWorld, XMMatrixTranslation(spawnPosition.x, spawnPosition.y, spawnPosition.z)); m_tSpawnPosition = spawnPosition; m_pPathPlanner = new CPathFinding("MinotaurNavGraph", _manager, false); CNavGraph* cNavGraph = CNavGraphManager::GetReference().GetNavGraph("MinotaurNavGraph"); int unNodes[2]; unNodes[0] = rand() % cNavGraph->GetNodes().size(); unNodes[1] = rand() % cNavGraph->GetNodes().size(); if (unNodes[1] == unNodes[0]) { unNodes[1]++; } m_vWaypoints.push_back(unNodes[0]); m_vWaypoints.push_back(unNodes[1]); //m_pSteering = new CSteeringManager(this); m_pAssetManager = CAssetManager::GetInstance(); m_cpAnimationManager = _animManager; m_cpObjectManager = _manager; m_pPlayer = m_cpObjectManager->GetPlayer(); CMesh* m_cMesh = m_pAssetManager->GetPrefabMesh("minotaur"); m_cpRenderMesh = new CAnimationMesh(m_cMesh, GRAPHICS->GetSkinningVS(), GRAPHICS->GetStandardPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Minotaur.dds"); m_cpRenderMesh->GetRender() = false; GRAPHICS->AddRenderMesh(m_cpRenderMesh); enum EMinotaurAnimation{ eIdleAnim, eRunAnim, eTellAnim, eChargeAnim, eStompAnim, eDeathAnim, eEnrageAnim, eStunnedAnim, eAnimCount }; m_cpAnimations[eIdleAnim] = CAssetManager::GetInstance()->GetAnimation("MinotaurIdle"); m_cpAnimations[eRunAnim] = CAssetManager::GetInstance()->GetAnimation("MinotaurRun"); m_cpAnimations[eTellAnim] = CAssetManager::GetInstance()->GetAnimation("MinotaurTell"); m_cpAnimations[eChargeAnim] = CAssetManager::GetInstance()->GetAnimation("MinotaurCharge"); m_cpAnimations[eStompAnim] = CAssetManager::GetInstance()->GetAnimation("MinotaurStomp"); m_cpAnimations[eDeathAnim] = CAssetManager::GetInstance()->GetAnimation("MinotaurDeath"); m_cpAnimations[eEnrageAnim] = CAssetManager::GetInstance()->GetAnimation("MinotaurEnrage"); m_cpAnimations[eStunnedAnim] = CAssetManager::GetInstance()->GetAnimation("MinotaurHurt"); for (unsigned int animation = 0; animation < eAnimCount; animation++) { m_cpAnimations[animation].SetAnimMesh((CAnimationMesh*)m_cpRenderMesh); } //m_cpAnimationManager->AddAnimation(&m_cpAnimations[eRunAnim]); /*m_cpAnimationManager->AddAnimation(&m_cpAnimations[eWalkAnim]); m_cpAnimationManager->AddAnimation(&m_cpAnimations[eRunAnim]); m_cpAnimationManager->AddAnimation(&m_cpAnimations[eStompAnim]);*/ CCapsule* pCapsule = new CCapsule(XMFLOAT3(spawnPosition.x, 90.0f, spawnPosition.z), XMFLOAT3(spawnPosition.x, 250.0f, spawnPosition.z), 90.0f); CCollider* pCapCollider = new CCollider(true, pCapsule, true, false); CCollider* pBoxCollider = new CCollider(true, new CAABB(float3(spawnPosition.x, 250.0f, spawnPosition.z), float3(250.0f, 250.0f, 250.0f)), false, false); CCollider* pZoneCollider = new CCollider(true, new CAABB(float3(spawnPosition.x, 250.0f, spawnPosition.z), float3(2500.0f, 250.0f, 2500.0f)), true, false); m_pMinotaurZone = new CMinotaurZone(); m_pMinotaurZone->AddCollider(pZoneCollider); pBoxCollider->GetBounds()->UpdatePosition(spawnPosition); AddCollider(pBoxCollider); AddCollider(pCapCollider); m_pParticleManager = new CParticleManager(_manager); m_unParticleEmitters[eBloodParticle] = m_pParticleManager->LoadEmitter("BloodDrop.xml"); m_unParticleEmitters[eBloodString] = m_pParticleManager->LoadEmitter("BloodString.xml"); m_unParticleEmitters[eBloodMist] = m_pParticleManager->LoadEmitter("BloodMist.xml"); m_unParticleEmitters[eBloodMist2] = m_pParticleManager->LoadEmitter("BloodMist.xml"); m_unParticleEmitters[eStompDustOut] = m_pParticleManager->LoadEmitter("MinotaurStompDust1.xml"); m_unParticleEmitters[eStompDustUp] = m_pParticleManager->LoadEmitter("MinotaurStompDust2.xml"); m_unParticleEmitters[eStepDust] = m_pParticleManager->LoadEmitter("MinoStepDust.xml"); m_unParticleEmitters[eChargeParticle] = m_pParticleManager->LoadEmitter("MinoCharge.xml"); m_pParticleManager->GetEmitter(m_unParticleEmitters[eChargeParticle])->GetParent() = this; m_pParticleManager->GetEmitter(m_unParticleEmitters[eChargeParticle])->Stop(); m_pStates[ePatrolState] = new CMinotaurPatrol; m_pStates[eHostileState] = new CMinotaurHostile; m_pStates[eDeadState] = new CMinotaurDead; m_unCurrAnim = -1; m_nCurrState = ePatrolState; //Activate(); }
/***************************************************************** * CollisionResponse() Responds to collision * * Ins: IObject* * * Outs: None * * Returns: void * * Mod. Date: 08/20/2015 * Mod. Initials: NS *****************************************************************/ void CSkeleton::CollisionResponse(IObject * _cCollidedObject) { if (_cCollidedObject->GetTag() == "PlayerAttack" && !m_bInvincible && m_fCurrentHealth > 0.0f) { m_bInvincible = true; m_fInvincibilityTimer = 0.35f; m_fCurrentHealth -= ((CAttack*)_cCollidedObject)->GetDamage(); m_eNewState = HURT; m_eCurrState = HURT; EnterSubState(); } else if (_cCollidedObject->GetTag() == "TrapPrefab") { for (size_t i = 1; i < _cCollidedObject->GetColliders().size(); i++) { if (_cCollidedObject->GetColliders()[i]->GetCollided()) { if (_cCollidedObject->GetColliders()[i]->GetType() == Bounds::AABB) { CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]); _cCollidedObject->GetColliders()[i]->SetCollided(false); } else if (_cCollidedObject->GetColliders()[i]->GetType() == Bounds::Plane) { if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f) { CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]); _cCollidedObject->GetColliders()[i]->SetCollided(false); m_bIsGrounded = true; } } } } } else if (_cCollidedObject->GetTag() == "Wall" || _cCollidedObject->GetTag() == "Door" || _cCollidedObject->GetTag() == "CrackedWall" || _cCollidedObject->GetTag() == "SafeHaven" || _cCollidedObject->GetTag() == "MinotaurSpawn") { if (m_eCurrState == ESkeletonStates::BACKING_OUT || m_eCurrState == ESkeletonStates::MANUVERING) { m_eNewState = ESkeletonStates::MOVING_IN; } for (size_t i = 1; i < _cCollidedObject->GetColliders().size(); i++) { if (_cCollidedObject->GetColliders()[i]->GetCollided()) { if (_cCollidedObject->GetColliders()[i]->GetType() == Bounds::AABB) { CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]); _cCollidedObject->GetColliders()[i]->SetCollided(false); } else if (_cCollidedObject->GetColliders()[i]->GetType() == Bounds::Plane) { if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f) { CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]); _cCollidedObject->GetColliders()[i]->SetCollided(false); m_bIsGrounded = true; } } } } if (_cCollidedObject->GetTag() == "SafeHaven") { m_eNewState = RETREAT; } } else if (_cCollidedObject->GetTag() == "SmallPit") { if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f) { for (size_t i = 1; i < _cCollidedObject->GetColliders().size(); i++) { CCollider* tested = _cCollidedObject->GetColliders()[i]; if (tested->GetCollided()) { if (tested->GetType() == Bounds::Plane) { if (((CPlane*)(tested->GetBounds()))->GetCenter().y < 0.0f) { CapsuleToFloor(this, m_pvColliders[1], tested); tested->SetCollided(false); m_bIsGrounded = true; } } else { CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]); _cCollidedObject->GetColliders()[i]->SetCollided(false); m_bIsGrounded = true; } } } } else if (m_f3Velocity.y < 0.0f) { for (size_t i = 1; i < _cCollidedObject->GetColliders().size() - 2; i++) { if (_cCollidedObject->GetColliders()[i]->GetCollided()) { CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]); _cCollidedObject->GetColliders()[i]->SetCollided(false); } } } } else if (_cCollidedObject->GetTag() == "BigPit") { if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f) { for (size_t i = 1; i < _cCollidedObject->GetColliders().size(); i++) { CCollider* tested = _cCollidedObject->GetColliders()[i]; if (tested->GetCollided()) { CapsuleToFloor(this, m_pvColliders[1], tested); tested->SetCollided(false); m_bIsGrounded = true; } } } else if (m_f3Velocity.y < 0.0f) { for (size_t i = 1; i < _cCollidedObject->GetColliders().size() - 1; i++) { CCollider* collider = _cCollidedObject->GetColliders()[i]; if (collider->GetCollided()) { CapsuleToWall(this, m_pvColliders[1], collider); collider->SetCollided(false); } } } } else if (_cCollidedObject->GetTag() == "Skeleton") { //Need capsule to capulse to make slide off eachother CapsuleToCapsule(this, m_pvColliders[1], _cCollidedObject->GetColliders()[1]); } else if (_cCollidedObject->GetTag() == "Floor" || _cCollidedObject->GetTag() == "SafeHavenFloor") { if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f) { CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[0]); m_bIsGrounded = true; } } else if (_cCollidedObject->GetTag() == "SpikeTrap") { if (m_fCurrentHealth > 0.0f) { CSpikeTrap* curTrap = reinterpret_cast<CSpikeTrap*>(_cCollidedObject); if (curTrap->GetActive() || curTrap->GetReset()) { SetWorldVelocity({ 0.0f, 0.0f, 0.0f }); } if (curTrap->GetActive() && !m_bInvincible) { TakeDamage(curTrap->GetTrapDamage()); SetWorldVelocity({ 0, 1000.0f, 0 }); //ChangeState(ESkeletonStates::eIdleState); } else { CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[0]); } } } else if (_cCollidedObject->GetTag() == "FireTrap") { if (m_fCurrentHealth > 0.0f) { CFireTrap* curTrap = reinterpret_cast<CFireTrap*>(_cCollidedObject); if (curTrap->GetActive() && !m_bInvincible) { TakeDamage(curTrap->GetTrapDamage()); } } } else if (_cCollidedObject->GetTag() == "SpinningBlade") { if (m_fCurrentHealth > 0.0f && !m_bInvincible) { CSpinningBlade* curTrap = reinterpret_cast<CSpinningBlade*>(_cCollidedObject); XMVECTOR mathTarget = XMVector3Normalize(XMLoadFloat3(GetPosition()) - XMLoadFloat3(curTrap->GetPosition())); mathTarget *= 1000.0f; XMFLOAT3 toTarget; XMStoreFloat3(&toTarget, mathTarget); SetWorldVelocity(toTarget); TakeDamage(curTrap->GetTrapDamage()); } } else if (_cCollidedObject->GetTag() == "PressurePlate") { _cCollidedObject->CollisionResponse(this); } else if (_cCollidedObject->GetTag() == "Bridge") { CBridge* curBridge = reinterpret_cast<CBridge*>(_cCollidedObject); curBridge->SetCollided(true); if (curBridge->IsActive() && curBridge->IsIntact()) { if (_cCollidedObject->GetColliders()[1]->GetCollided()) { if (_cCollidedObject->GetColliders()[1]->GetCollided()) _cCollidedObject->GetColliders()[1]->SetCollided(false); } for (size_t i = 2; i < 10; i++) { if (_cCollidedObject->GetColliders()[i]->GetCollided()) { if (GetPosition()->y < 20.0f) { CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]); _cCollidedObject->GetColliders()[i]->SetCollided(false); m_bIsGrounded = true; } else { CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]); _cCollidedObject->GetColliders()[i]->SetCollided(false); } } } for (size_t i = 10; i < _cCollidedObject->GetColliders().size(); i++) { if (_cCollidedObject->GetColliders()[i]->GetCollided()) { CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]); _cCollidedObject->GetColliders()[i]->SetCollided(false); } } } } else if (_cCollidedObject->GetTag() == "Minotaur") { TakeDamage(200.0f); } else if (_cCollidedObject->GetTag() == "MinotaurZone") { if (m_pDayNight->IsNight()) { if (m_eNewState != DEATH && m_eCurrState != DEATH) { m_eNewState = RETREAT; } } } }
/***************************************************************** * SmoothPath() Removes uneeded nodes from given path to smooth it out * it out. * * Ins: vector<CNode*>& * * * Outs: None * * Returns: None * * Mod. Date: 09/01/2015 * Mod. Initials: CM *****************************************************************/ vector<XMFLOAT3> CPathFinding::SmoothPath(vector<CNode*>& path) { vector<XMFLOAT3> smoothedPath; if (path.size() > 2) { XMFLOAT3 checkPoint = path[0]->GetPosition(); XMFLOAT3 currPoint = path[1]->GetPosition(); smoothedPath.push_back(path[0]->GetPosition()); for (size_t currNode = 1; currNode + 2 < path.size(); currNode++) { CCapsule* tempCapsule = new CCapsule(path[currNode + 2]->GetPosition(), checkPoint, 100.0f); CCollider* tempCollider = new CCollider(true, tempCapsule); std::vector<IObject*> colliders = m_pObjectManager->GetQuadTree()->GetNearbyObjects(tempCollider->GetBounds()); std::vector<IObject*> hit; CheckCollision(tempCollider, colliders, hit); bool skip = false; for (size_t currHit = 0; currHit < hit.size(); currHit++) { if (hit[currHit]->GetTag() == "Wall") { checkPoint = currPoint; currPoint = path[currNode + 1]->GetPosition(); skip = true; smoothedPath.push_back(path[currNode]->GetPosition()); break; } } if (skip == false) { currPoint = path[currNode + 1]->GetPosition(); } delete tempCollider; } //currIndex++; } smoothedPath.push_back(path[path.size() - 1]->GetPosition()); return smoothedPath; }