bool CCollider::CollideWith(CCollider& other, const double dt) { if (!this->m_active || !other.GetActive()) // If one of the collider does not collide, no collision will occur, hence false { return false; } if (this->m_type == CT_AABB) { if (other.GetType() == CT_AABB) { // AABB - AABB collision return AABBCollision(other, dt); } else if (other.GetType() == CT_DIST) { // AABB - Dist collision return AABBCollision(other, dt); // Use AABB - AABB collision } } else if (this->m_type == CT_DIST) { if (other.GetType() == CT_AABB) { // Dist - AABB collision return AABBCollision(other, dt); // Use AABB - AABB collision } else if (other.GetType() == CT_DIST) { // Dist - Dist collision return distCollision(other, dt); } } }
/***************************************************************** * 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; } } } }