void CGuard::Update(float fElapsedTime) { if(CheckForPlayer()) { ComputeMovement(fElapsedTime); this->addTime(fElapsedTime); CBase::Update(fElapsedTime); } else CEnemy::Update( fElapsedTime ); m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY()); for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++) { Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i]; tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY())); // Create a circle based on clsoest point with capsule radius Circle testCircle; testCircle.m_Center = ClosestPoint; testCircle.m_fRadius = temp->GetRadius(); if( GetSphere()->CheckCollision(testCircle) ) { tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center; sphere2_to_1 = Vector2DNormalize(sphere2_to_1); float dist = GetSphere()->m_fRadius + testCircle.m_fRadius; tVector2D scaler = (sphere2_to_1 * (dist * 0.01f)); tVector2D newpos = GetSphere()->m_Center + scaler; SetPosX(newpos.fX); SetPosY(newpos.fY); } } if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_1)) { IsUndead = true; AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Zombie Walking" ); } if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_2)) { IsUndead = false; AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Person Walking" ); } }
void SmartChaseState::Update(float _deltaTime) { if (!m_zombie->m_pathToTake.empty()) { FollowPath(_deltaTime); } else { if (!m_requestedPath) { FindPath(); } } if (!m_zombie->CollideWithAgent(m_zombie->m_player.lock().get())) { //collision handle } if (m_zombie->m_health <= 50.0f) { //The zombie is low health, he wants to run ! if (!m_requestedPath) { //only switch states if there is no path requested (or the callback will try to access deleted memory) m_zombie->m_stateManager.SetState(new RetreatState(m_zombie)); } } else if (!CheckForPlayer()) { //The player is out of zombie chase range if (!m_requestedPath) { //only switch states if there is no path requested (or the callback will try to access deleted memory) m_zombie->m_stateManager.SetState(new SmartPatrolState(m_zombie)); } } }