Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. void StateSearchAround::Update(double dt)
  2. {
  3.     PostOffice::GetInstance()->Send("Scene", new MessageWRU(m_go, MessageWRU::NEAREST_PLAYER, SceneData::GetInstance()->GetGridSize() * 10));
  4.         if (m_go->nearest != NULL)
  5.         {
  6.      
  7.         MazePt target;
  8.        
  9.         target.x = m_go->nearest->pos.x;
  10.         target.y = m_go->nearest->pos.y;
  11.  
  12.         PostOffice::GetInstance()->Send("Scene", new MessageBFSLimit(m_go, target, 10));
  13.         //set previous state number to know what previous state ai was in during next state
  14.         SceneData::GetInstance()->SetMpreviousState(2);
  15.         std::cout << "Found Player" << std::endl;
  16.         if (!m_go->path.empty())
  17.         {
  18.             m_go->sm->SetNextState("Chase");
  19.         }
  20.    
  21.          }
  22.     else
  23.     {
  24.         //Random a point
  25.         MazePt rand;
  26.         int x, y;
  27.         do
  28.         {
  29.             x = Math::RandIntMinMax(0, SceneData::GetInstance()->GetNoGrid() - 1);
  30.             y = Math::RandIntMinMax(0, SceneData::GetInstance()->GetNoGrid() - 1);
  31.  
  32.         } while (SceneData::GetInstance()->Getmaze().See(MazePt(x, y)) != Maze::TILE_EMPTY);
  33.         rand.x = x;
  34.         rand.y = y;
  35.         PostOffice::GetInstance()->Send("Scene", new MessageBFSLimit(m_go, rand, 10));
  36.  
  37.         if (!m_go->path.empty())
  38.         {
  39.             m_go->sm->SetNextState("Movearound");
  40.             //std::cout << "Path: ";
  41.             //for (auto pt : m_go->path)
  42.             //  {
  43.             //      std::cout << "(" << pt.x << "," << pt.y << ")->";
  44.             //  }
  45.         }
  46.     }
  47.  
  48.    
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement