MapObject* CMapObjectManager::getObjectNearBy(int cx,int cy,MapObjectType type) { Rect rect; m_pMap->getViewRect(rect); float x = 0; float y = 0; MapObject* pRet = NULL; const int minD = 3; //最小格子距离 for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr) { MapObject* pObject = *itr; if ( pObject && !pObject->GetDeleted() ) { x = pObject->getPositionX(); y = pObject->getPositionY(); int distance = Distance(cx,cy,pObject->GetCellX(),pObject->GetCellY()); if ( rect.containsPoint(Point(x,y)) && pObject->GetType() == type && distance < minD ) { pRet = pObject; //minD = distance; } } } return pRet; }
MapObject* CMapObjectManager::getObject(int cx,int cy) { for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr) { MapObject* pObject = *itr; if ( pObject && !pObject->GetDeleted() && pObject->GetCellX() == cx && pObject->GetCellY() == cy ) { return pObject; } } return NULL; }
int CMapObjectManager::getObjects(int cx,int cy,MapObjectList& objects) { objects.clear(); for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr) { MapObject* pObject = *itr; if ( pObject && !pObject->GetDeleted() && pObject->GetCellX() == cx && pObject->GetCellY() == cy ) { objects.push_back(pObject); } } return (int)objects.size(); }