Advertisement
Guest User

Untitled

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