本文整理汇总了C++中CCArray::getIndexOfObject方法的典型用法代码示例。如果您正苦于以下问题:C++ CCArray::getIndexOfObject方法的具体用法?C++ CCArray::getIndexOfObject怎么用?C++ CCArray::getIndexOfObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCArray
的用法示例。
在下文中一共展示了CCArray::getIndexOfObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void Enemy::checkForAndResolveCollisions()
{
CCPoint playerPos = getPosition();
CCArray* tiles = getSurroundingTilesAtPosition(playerPos);
CCObject* obj;
_onGround = false;
bool isSideHit = false;
CCARRAY_FOREACH(tiles,obj)
{
CCDictionary* dict = (CCDictionary*)obj;
Integer* x = (Integer*)dict->objectForKey("x");
Integer* y = (Integer*)dict->objectForKey("y");
float height = _map->getTileSize().height;
float width = _map->getTileSize().width;
//_debugDraw->appendRect(ccp(x->getValue(), y->getValue()), width, height);
CCRect pRect = collisionBoundingBox();
//_debugDraw->appendRect(ccp(pRect.getMinX(), pRect.getMinY()), pRect.getMaxX() - pRect.getMinX() , pRect.getMaxY() - pRect.getMinY(), 1.0f, 0.0f, 0.0f);
Integer* gid = (Integer*)dict->objectForKey("gid");
if(gid->getValue())
{
CCRect tileRect = CCRectMake((float)x->getValue(),(float)y->getValue(), _map->getTileSize().width, _map->getTileSize().height);
if(pRect.intersectsRect(tileRect))
{
CCRect intersectRect = pRect.intersectsWithRect(tileRect);
int tileIndx = tiles->getIndexOfObject(obj);
//CCLOG("tileIndx %d : " ,tileIndx);
if(tileIndx == 0)
{
//CCLOG("0 intersect ");
//_debugDraw->appendRect(ccp(intersectRect.getMinX(), intersectRect.getMinY()), intersectRect.getMaxX() - intersectRect.getMinX() , intersectRect.getMaxY() - intersectRect.getMinY(), 1.0f, 0.0f, 0.0f);
_onGround = true;
setVelocity(ccp(getVelocity().x, 0.0f));
setDesiredPosition(ccp(getDesiredPosition().x, getDesiredPosition().y + intersectRect.size.height));
//_player->setDesiredPosition(ccp(_player->getDesiredPosition().x, 13));
//CCLOG("Player box %f", tileRect.getMaxY() - pRect.getMinY());
//CCLOG("tile box %f", tileRect.getMaxY());
//CCLOG("intersectRect box %f", intersectRect.size.height);
}
else if(tileIndx == 1)
{
//CCLOG("1 intersect ");
setDesiredPosition(ccp(getDesiredPosition().x, getDesiredPosition().y - intersectRect.size.height));
}
else if(tileIndx == 2)
{
//CCLOG("2 intersect ");
isSideHit = true;
setVelocity(ccp(0.0f,getVelocity().y));
setDesiredPosition(ccp(getDesiredPosition().x + intersectRect.size.width, getDesiredPosition().y));
}
else if(tileIndx == 3)
{
//CCLOG("3 intersect ");
isSideHit = true;
setVelocity(ccp(0.0f,getVelocity().y));
setDesiredPosition(ccp(getDesiredPosition().x - intersectRect.size.width, getDesiredPosition().y));
}
else
{
if(intersectRect.size.width > intersectRect.size.height)
{
float resolutionHeight;
if(tileIndx > 5)
{
resolutionHeight = intersectRect.size.height;
setVelocity(ccp(getVelocity().x, 0.0f));
_onGround = true;
}
else
{
resolutionHeight = -intersectRect.size.height;
}
setDesiredPosition(ccp(getDesiredPosition().x, getDesiredPosition().y + resolutionHeight ));
}
else
{
float resolutionWidth;
if (tileIndx == 6 || tileIndx == 4)
{
resolutionWidth = intersectRect.size.width;
}
else
{
resolutionWidth = -intersectRect.size.width;
}
setDesiredPosition(ccp(getDesiredPosition().x + resolutionWidth, getDesiredPosition().y ));
}
//.........这里部分代码省略.........