本文整理汇总了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;
}
}
}
示例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;
}
示例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);
}
}
}
示例4: isCollisionRight
bool GameLayer::isCollisionRight(CCRect roleBox, CCRect collisionBox) {
CCPoint targetPoint = ccp(roleBox.getMaxX(), roleBox.getMidY());
return collisionBox.containsPoint(targetPoint);
}