当前位置: 首页>>代码示例>>C++>>正文


C++ CCRect::getMidY方法代码示例

本文整理汇总了C++中CCRect::getMidY方法的典型用法代码示例。如果您正苦于以下问题:C++ CCRect::getMidY方法的具体用法?C++ CCRect::getMidY怎么用?C++ CCRect::getMidY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCRect的用法示例。


在下文中一共展示了CCRect::getMidY方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initTerritory

/*!
 * Determines initial territory size for this player based on the size of the screen and the location of the initial touch.
 * Sets player identifier based on initial territory.
 *
 * @param screenBox Size of the screen.
 */
void Player::initTerritory(CCRect screenBox) {

    this->territory = CCRectMake(screenBox.origin.x, screenBox.origin.y, screenBox.size.width, screenBox.size.height);
    territory.size.width /= 2;

    if (startingPoint.x < screenBox.getMidX()) {
        territory.origin.x = screenBox.origin.x / 2;

        if (GameManager::sharedManager()->tabletDevice()) {
            if (startingPoint.y > screenBox.getMidY()) {
                this->_identifier = GameManager::kPlayer1;
            } else {
                this->_identifier = GameManager::kPlayer3;
            }
        } else {
            this->_identifier = GameManager::kPlayer1;
        }
    } else {
        territory.origin.x = screenBox.origin.x / 2 + screenBox.size.width / 2;

        if (GameManager::sharedManager()->tabletDevice()) {
            if (startingPoint.y > screenBox.getMidY()) {
                this->_identifier = GameManager::kPlayer2;
            } else {
                this->_identifier = GameManager::kPlayer4;
            }
        } else {
            this->_identifier = GameManager::kPlayer2;
        }
    }
}
开发者ID:emmett9001,项目名称:fingerrace-core,代码行数:37,代码来源:Player.cpp

示例2: IsPutable

bool CBoxBehaviorState::IsPutable(CCSprite* sprite, CCPoint touchPos, CCPoint& avaliablePos)
{
	auto arr = CObjectManager::getInstance()->getBox2dSprite();
	CCPoint setPos;
	bool bIsEnable = true;
	CCRect rect;

	for (int i = 0; i <= 20; i++)
	{
		for (int j = 0; j <= 20; j++)
		{
			CCRect r;
			r.setRect(i * 105 + CScrollManager::getInstance()->getDeltaPosition().x, j * 105 + CScrollManager::getInstance()->getDeltaPosition().y, 105, 105);

			if (r.containsPoint(touchPos))
			{
				setPos = ccp(r.getMidX(), r.getMidY());
				rect = r;
			}
		}
	}

	for (int i = 0; i < arr->getSize(); i++)
	{
		auto anothersprite = arr->getObjectAt(i)->getSpritePtr();

		if (rect.intersectsRect(anothersprite->getBoundingBox()))
			bIsEnable = false;
	}

	avaliablePos = setPos;
	return bIsEnable;
}
开发者ID:godole,项目名称:Memory,代码行数:33,代码来源:BoxBehaviorState.cpp

示例3: collideWithPaddle

void Ball::collideWithPaddle(Paddle* paddle)
{
    CCRect paddleRect = paddle->rect();
    paddleRect.origin.x += paddle->getPosition().x;
    paddleRect.origin.y += paddle->getPosition().y;
    
    float lowY  = paddleRect.getMinY();
    float midY  = paddleRect.getMidY();
    float highY = paddleRect.getMaxY();
    
    float leftX  = paddleRect.getMinX();
    float rightX = paddleRect.getMaxX();
    
    if (getPosition().x > leftX && getPosition().x < rightX) {
    
        bool hit = false;
        float angleOffset = 0.0f; 
        
        if (getPosition().y > midY && getPosition().y <= highY + radius()) 
        {
            setPosition( CCPointMake(getPosition().x, highY + radius()) );
            hit = true;
            angleOffset = (float)M_PI / 2;
        }
        else if (getPosition().y < midY && getPosition().y >= lowY - radius()) 
        {
            setPosition( CCPointMake(getPosition().x, lowY - radius()) );
            hit = true;
            angleOffset = -(float)M_PI / 2;
        }
        
        if (hit) 
        {
            float hitAngle = ccpToAngle(ccpSub(paddle->getPosition(), getPosition())) + angleOffset;
            
            float scalarVelocity = ccpLength(m_velocity) * 1.05f;
            float velocityAngle = -ccpToAngle(m_velocity) + 0.5f * hitAngle;
            
            m_velocity = ccpMult(ccpForAngle(velocityAngle), scalarVelocity);
        }
    }    
} 
开发者ID:acc85,项目名称:cocos2d-x,代码行数:42,代码来源:Ball.cpp

示例4: isCollisionRight

bool GameLayer::isCollisionRight(CCRect roleBox, CCRect collisionBox) {
    
    CCPoint targetPoint = ccp(roleBox.getMaxX(), roleBox.getMidY());
    return collisionBox.containsPoint(targetPoint);
}
开发者ID:DoubleHH,项目名称:FlappyBird,代码行数:5,代码来源:GameLayer.cpp


注:本文中的CCRect::getMidY方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。