bool Cocos2dxAtlasNode::initWithTextureAtlas( CCTextureAtlas* textureAtlas , unsigned int quadIndex , const CCRect &sourceRect)
{
    m_nQuadIndex = quadIndex;

    m_tColorUnmodified = ccWHITE;
    m_bIsOpacityModifyRGB = true;

    m_tBlendFunc.src = CC_BLEND_SRC;
    m_tBlendFunc.dst = CC_BLEND_DST;

    m_pTextureAtlas = textureAtlas;

    if (! m_pTextureAtlas)
    {
        CCLOG("cocos2d: Could not initialize Cocos2dxAtlasNode. Invalid Texture.");
        return false;
    }
    m_pTextureAtlas->retain();

    this->updateBlendFunc();
    this->updateOpacityModifyRGB();


    // shader stuff
    setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor));
    m_nUniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color");

    cocos2d::ccV3F_C4B_T2F_Quad & quad = textureAtlas->getQuads()[quadIndex];

    quad.bl.vertices.x = sourceRect.getMinX();
	quad.bl.vertices.y = sourceRect.getMinY();
	quad.bl.vertices.z = 0;
	quad.br.vertices.x = sourceRect.getMaxX();
	quad.br.vertices.y = sourceRect.getMinY();
	quad.br.vertices.z = 0;
	quad.tl.vertices.x = sourceRect.getMinX();
	quad.tl.vertices.y = sourceRect.getMaxY();
	quad.tl.vertices.z = 0;
	quad.tr.vertices.x = sourceRect.getMaxX();
	quad.tr.vertices.y = sourceRect.getMaxY();
	quad.tr.vertices.z = 0;


    //*(cocos2d::CCPoint*)&quad.bl.vertices = CCPointApplyAffineTransform(*(cocos2d::CCPoint*)&(quad.bl.vertices), matrix);
    //*(cocos2d::CCPoint*)&quad.br.vertices = CCPointApplyAffineTransform(*(cocos2d::CCPoint*)&(quad.br.vertices), matrix);
    //*(cocos2d::CCPoint*)&quad.tl.vertices = CCPointApplyAffineTransform(*(cocos2d::CCPoint*)&(quad.tl.vertices), matrix);
    //*(cocos2d::CCPoint*)&quad.tr.vertices = CCPointApplyAffineTransform(*(cocos2d::CCPoint*)&(quad.tr.vertices), matrix);

    //quad.bl.vertices.y = -quad.bl.vertices.y;
    //quad.br.vertices.y = -quad.br.vertices.y;
    //quad.tl.vertices.y = -quad.tl.vertices.y;
    //quad.tr.vertices.y = -quad.tr.vertices.y;
    return true;
}
CCRect CollisionEngine::CCRectIntersection(CCRect r1, CCRect r2) {

	CCRect intersection;
	intersection = CCRectMake(std::max(r1.getMinX(), r2.getMinX()),
			std::max(r1.getMinY(), r2.getMinY()), 0, 0);
	intersection.size.width = std::min(r1.getMaxX(), r2.getMaxX())
			- intersection.getMinX();
	intersection.size.height = std::min(r1.getMaxY(), r2.getMaxY())
			- intersection.getMinY();

	return intersection;

}
예제 #3
0
CCRect CCControlUtils::CCRectUnion(const CCRect& src1, const CCRect& src2) 
{
    CCRect result;
    
    float x1 = MIN(src1.getMinX(), src2.getMinX());
    float y1 = MIN(src1.getMinY(), src2.getMinY());
    float x2 = MAX(src1.getMaxX(), src2.getMaxX());
    float y2 = MAX(src1.getMaxY(), src2.getMaxY());
    
    result.origin=ccp(x1,x2);
    result.size=CCSizeMake(x2-x1, y2-y1);
    return result;
}
예제 #4
0
void ItemTortoiseFly::collision()
{
	if (_bGodMode || _mario->_status == Mario::DEAD || _mario->_bGodMode)
	{
		return;
	}

	CCRect rcItem = boundingBox();
	CCRect rcMario = _mario->boundingBox();
	if (rcItem.intersectsRect(rcMario))
	{
		if (_status == NORMAL)
		{
			if (_mario->_status == Mario::FLY && _mario->_speedUp <= 0 && rcMario.getMinY() > rcItem.getMaxY() - rcItem.size.height / 2)
			{
				_status = DROPPING;
				updateStatus();
			}
			else
			{
				_mario->die(false);
			}
		}
		else if (_status == DROPPING)
		{
			// ... nothing to do
			// 设计中,乌龟下降的速度应该大于mario下降的速度,所以不应该有碰撞
		}
		else if (_status == ONLAND)
		{
			if (_mario->_status == Mario::FLY && _mario->_speedUp <= 0 && rcMario.getMinY() > rcItem.getMaxY() - rcItem.size.height / 2)
			{
				_status = SLEEP;
				updateStatus();
			}
			else
			{
				_mario->die(false);
			}
		}
		else if (_status == SLEEP)
		{
			if (_bGodMode) return;

			_status = CRAZY;
			updateStatus();
		}
	}
}
예제 #5
0
bool JoinMembers::AABB(CCRect a, CCRect b)
{
	//접하면 충돌로 봄.
	//x축에대하여
	
	if( a.getMaxX() < b.getMinX() ||
	   a.getMinX() > b.getMaxX() )
		return false;
	
	//y축에대하여
		
	if(a.getMaxY() < b.getMinY() ||
	   a.getMinY() > b.getMaxY() )
		return false;
	return true;
}
예제 #6
0
파일: CtrlEdit.cpp 프로젝트: twkevin/ddz
void KeyboardNotificationLayer::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
{
	if (! m_pTrackNode)
	{
		return;
	}

	CCRect rectTracked = ccGetRect(m_pTrackNode);
	// if the keyboard area doesn't intersect with the tracking node area, nothing need to do.
	if (! rectTracked.intersectsRect(info.end))
	{
		return;
	}

	// assume keyboard at the bottom of screen, calculate the vertical adjustment.
	float adjustVert = info.end.getMaxY() - rectTracked.getMinY();
	CCLOG("TextInputTest:needAdjustVerticalPosition(%f)", adjustVert);

	// move all the children node of KeyboardNotificationLayer
	/*CCArray * children = getChildren();
	CCNode * node = 0;
	int count = children->count();
	CCPoint pos;
	for (int i = 0; i < count; ++i)
	{
		node = (CCNode*)children->objectAtIndex(i);
		pos = node->getPosition();
		pos.y += adjustVert;
		node->setPosition(pos);
	}*/
}
예제 #7
0
void GameLayer::fixCollision(COLL_STATE state, CCNode *role, cocos2d::CCRect collisionBox) {
    CCRect roleBox = role->boundingBox();
    
    switch (state) {
        case COLL_STATE_LEFT: {
            float fixedX = role->getPositionX();
            fixedX += collisionBox.getMaxX() - roleBox.getMinX();
            role->setPositionX(fixedX);
            break;
        }
        case COLL_STATE_RIGHT: {
            float fixedX = role->getPositionX();
            fixedX -= roleBox.getMaxX() - collisionBox.getMinX();
            role->setPositionX(fixedX);
            break;
        }
        case COLL_STATE_TOP: {
            float fixedY = role->getPositionY();
            fixedY -= roleBox.getMaxY() - collisionBox.getMinY();
            role->setPositionY(fixedY);
            break;
        }
        case COLL_STATE_BOTTOM: {
            float fixedY = role->getPositionY();
            fixedY += collisionBox.getMaxY() - roleBox.getMinY();
            role->setPositionY(fixedY);
            break;
        }
        default:
            break;
    }
}
예제 #8
0
bool CAScrollView::isScrollWindowNotOutSide()
{
    CCSize size = this->getBounds().size;
    CCRect rect = m_pContainer->getFrame();
    
    if (rect.getMinX() > 0.5f)
    {
        return true;
    }
    
    if ((rect.getMaxX() - size.width) < -0.5f)
    {
        return true;
    }
    
    float y_max = this->isHeaderRefreshing() ? _px(128) : 0.0f;
    float y_min = (this->isFooterRefreshing() ? _px(128) : 0.0f) - size.height;
    
    if (rect.getMinY() + y_max > 0.5f)
    {
        return true;
    }
    
    if (rect.getMaxY() + y_min < -0.5f)
    {
        return true;
    }
    
    return false;
}
예제 #9
0
void CCEditBox::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
{
    // CCLOG("CCEditBox::keyboardWillShow");
    CCRect rectTracked = getRect(this);
    
    //postion bug fix code -sunxy
    if (m_pParent != NULL)
    {
        rectTracked.origin = m_pParent->convertToWorldSpace(rectTracked.origin);
    }
    
    // if the keyboard area doesn't intersect with the tracking node area, nothing needs to be done.
    if (!rectTracked.intersectsRect(info.end))
    {
        CCLOG("needn't to adjust view layout.");
        return;
    }
    
    // assume keyboard at the bottom of screen, calculate the vertical adjustment.
    m_fAdjustHeight = info.end.getMaxY() - rectTracked.getMinY();
    // CCLOG("CCEditBox:needAdjustVerticalPosition(%f)", m_fAdjustHeight);
    
    if (m_pEditBoxImpl != NULL)
    {
        m_pEditBoxImpl->doAnimationWhenKeyboardMove(info.duration, m_fAdjustHeight);
    }
}
예제 #10
0
bool CCRect::intersectsRect(const CCRect& rect) const
{
    return !(     getMaxX() < rect.getMinX() ||
             rect.getMaxX() <      getMinX() ||
                  getMaxY() < rect.getMinY() ||
             rect.getMaxY() <      getMinY());
}
예제 #11
0
static bool isCollide(const CCRect r1, const CCRect r2)
{
	bool bRet = false;
	if(r1.intersectsRect(r2))
	{
		double area1 = (r1.getMaxX()-r1.getMinX())*(r1.getMaxY()-r1.getMinY());
		double area2 = (r2.getMaxX()-r2.getMinX())*(r2.getMaxY()-r2.getMinY());
		float maxX = min(r1.getMaxX(), r2.getMaxX());
		float minX = max(r1.getMinX(), r2.getMinX());
		float maxY = min(r1.getMaxY(), r2.getMaxY());
		float minY = max(r1.getMinY(), r2.getMinY());
		double interarea = (maxX-minX) * (maxY-minY);

		bRet = interarea * 5 > max(area1, area2);
	}
	return bRet;
}
예제 #12
0
파일: Player.cpp 프로젝트: dps999/mario
CCRect Player::collisionBoundingBox() {
	CCRect collisionBox = this->boundingBox();
	CCPoint diff = ccpSub(this->desiredPosition, this->getPosition());
	CCRect returnBoundingBox;
	returnBoundingBox.setRect(collisionBox.getMinX() + diff.x, collisionBox.getMinY() + diff.y, collisionBox.getMaxX()-collisionBox.getMinX(), collisionBox.getMaxY()-collisionBox.getMinY());
	return returnBoundingBox;
	//  return CCRect::intersectsRect(this->boundingBox, 2, 0);
}
예제 #13
0
static bool inVisibleRigion(const CCRect& rect)
{
	CCSize size = CCDirector::sharedDirector()->getVisibleSize();

	return rect.getMinX() < size.width
		&& rect.getMaxX() > 0
		&& rect.getMinY() < size.height
		&& rect.getMaxY() > 0;
}
예제 #14
0
static void printRect(const CCRect& rect)
{
	char msg[128];
	sprintf(msg, "%f, %f, %f, %f",
		rect.getMinX(),
		rect.getMinY(),
		rect.getMaxX(),
		rect.getMaxY());

	CCLOG(msg);
	
}
예제 #15
0
파일: Tank.cpp 프로젝트: jun199004/Tank
bool Tank::command(enumOrder order)
{
	float stepX = 0.0f;
	float stepY = 0.0f;
	float fRotation = getRotation();

	switch (order)
	{
	case cmdNothing:
		break;
	case cmdGoUP:
		stepY = 1.0f;
		fRotation = 0.0f;
		break;
	case cmdGoDown:
		stepY = -1.0f;
		fRotation = 180.0f;
		break;
	case cmdGoLeft:
		stepX = -1.0f;
		fRotation = 270.0f;
		break;
	case cmdGoRight:
		stepX = 1.0f;
		fRotation = 90.0f;
		break;
	case cmdFire:
		//调用子弹开火
		return mBullet->fire();
	default:
		break;
	}

	//根据运行方向旋转坦克
	setRotation(fRotation);

	CCRect rect = this->boundingBox();
	mMovedRect = CCRectMake(rect.getMinX() + stepX,
		rect.getMinY() + stepY, rect.size.width, rect.size.height);
	//检测地图上的碰撞
	if (!mTileMapInfo->collisionTest(mMovedRect))
	{
		IsBlock = false;
		return true;
	}
	//如果碰撞了就不要移动,设置为阻塞状态
	mMovedRect = rect;
	IsBlock = true;

	return false;
}
예제 #16
0
void UIScrollView::UpdateBounding()
{
	CCRect kRect = boundingBox();
	if(m_kChildren.Size())
	{
		m_f32MinX = VE_MAXFLOAT_F;
		m_f32MaxX = -VE_MAXFLOAT_F;
		m_f32MinY = VE_MAXFLOAT_F;
		m_f32MaxY = -VE_MAXFLOAT_F;
		m_kChildren.BeginIterator();
		while(!m_kChildren.IsEnd())
		{
			UIWidget* pkWidget = m_kChildren.GetIterNode()->m_tContent;
			m_kChildren.Next();
			VE_ASSERT(pkWidget);
			if(pkWidget->GetVisible())
			{
				CCRect kRectWidget = pkWidget->boundingBox();
				kRectWidget.origin.x -= kRectWidget.size.width * pkWidget->GetTouchAnchorPoint().x;
				kRectWidget.origin.y -= kRectWidget.size.height * pkWidget->GetTouchAnchorPoint().y;
				m_f32MinX = VE_MIN(kRectWidget.getMinX(), m_f32MinX);
				m_f32MaxX = VE_MAX(kRectWidget.getMaxX(), m_f32MaxX);
				m_f32MinY = VE_MIN(kRectWidget.getMinY(), m_f32MinY);
				m_f32MaxY = VE_MAX(kRectWidget.getMaxY(), m_f32MaxY);
			}
		}
		m_f32MinY = VE_MIN(m_f32MinY, m_f32MaxY - kRect.size.height);
	}
	else
	{
		m_f32MinX = 0;
		m_f32MaxX = kRect.size.width;
		m_f32MinY = 0;
		m_f32MaxY = kRect.size.height;
	}

	m_f32MoveLeft = m_f32MinX;
	m_f32MoveRight = m_f32MaxX - kRect.size.width;
	m_f32MoveBottom = m_f32MinY;
	m_f32MoveTop = m_f32MaxY - kRect.size.height;

	VeFloat32 f32Rate = m_f32MaxY > m_f32MinY ? kRect.size.height / (m_f32MaxY - m_f32MinY) : 1.0f;
	f32Rate = VE_MIN(f32Rate, 1.0f);
	m_f32ScrollBarLen = VeFloorf(VeFloat32(kRect.size.height) * f32Rate);

	m_bCanScroll = f32Rate < 1.0f;

	UpdateScrollBar();
}
예제 #17
0
/**
*   键盘将要出现的时候
*/
void LoginView::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
{
    CCLog("LoginView:keyboardWillShowAt(origin:%f,%f, size:%f,%f)",
        info.end.origin.x, info.end.origin.y, info.end.size.width, info.end.size.height);

    if (! this->mTrackNodeArray)
    {
        return;
    }

    CCNode* trackNode = NULL ;
    CCRect rectTracked ;
    for(int i=0; i<this->mTrackNodeArray->count(); i++) 
    {
        trackNode = (CCNode*) this->mTrackNodeArray->objectAtIndex(i) ;

        rectTracked = getRect(trackNode);
        CCLog("LoginView:trackingNodeAt(origin:%f,%f, size:%f,%f)",
            rectTracked.origin.x, rectTracked.origin.y, rectTracked.size.width, rectTracked.size.height);

        // if the keyboard area doesn't intersect with the tracking node area, nothing need to do.
        if (! CCRect::CCRectIntersectsRect(rectTracked, info.end))
        {
            continue ;
        }

        // assume keyboard at the bottom of screen, calculate the vertical adjustment.
        float adjustVert = info.end.getMaxY() - rectTracked.getMinY();
        CCLog("LoginView:needAdjustVerticalPosition(%f)", adjustVert);

        // move all the children node of KeyboardNotificationLayer
        CCArray* children = getChildren();
        CCNode* node = 0;
        int count = children->count();
        CCPoint pos;
        for (int i = 0; i < count; ++i)
        {
            node = (CCNode*)children->objectAtIndex(i);
            pos = node->getPosition();
            pos.y += adjustVert;
            node->setPosition(pos);
        }
    }

    
}
bool ObstacleSimple::collision(BaseVehicle &vehicle)
{
    float top, bottom;
    CCRect area = boundingBox();
    
    top = area.getMinY() + getContentSize().height * 0.0f;
    bottom = top + getContentSize().height * 0.37f;
    
    float y = vehicle.getGroundCollision().getMinY() + (vehicle.getGroundCollision().getMaxY() - vehicle.getGroundCollision().getMinY()) * 0.25f;
    
    y = vehicle.getPlayerY() + vehicle.getContentSize().height * 0.3f * 0.5f;
    
    if(y < top || y > bottom)
        return false;
    
    // CCLog("Pass %f ; %f ; %f", y, top, bottom);
    
    return BaseObstacle::collision(vehicle);
}
예제 #19
0
CCRect CCRectApplyAffineTransform(const CCRect& rect, const CCAffineTransform& anAffineTransform)
{
    float top    = rect.getMinY();
    float left   = rect.getMinX();
    float right  = rect.getMaxX();
    float bottom = rect.getMaxY();
    
    CCPoint topLeft = CCPointApplyAffineTransform(CCPointMake(left, top), anAffineTransform);
    CCPoint topRight = CCPointApplyAffineTransform(CCPointMake(right, top), anAffineTransform);
    CCPoint bottomLeft = CCPointApplyAffineTransform(CCPointMake(left, bottom), anAffineTransform);
    CCPoint bottomRight = CCPointApplyAffineTransform(CCPointMake(right, bottom), anAffineTransform);

    float minX = min(min(topLeft.x, topRight.x), min(bottomLeft.x, bottomRight.x));
    float maxX = max(max(topLeft.x, topRight.x), max(bottomLeft.x, bottomRight.x));
    float minY = min(min(topLeft.y, topRight.y), min(bottomLeft.y, bottomRight.y));
    float maxY = max(max(topLeft.y, topRight.y), max(bottomLeft.y, bottomRight.y));
        
    return CCRectMake(minX, minY, (maxX - minX), (maxY - minY));
}
void ItemFireString::collision()
{
	if (_mario->_dead) return;
	// »ñÈ¡fireStringÏ߶Î
	struct Line
	{
		CCPoint pt1;
		CCPoint pt2;
	} lineFireString;

	CCRect rcItem = boundingBox();
	int angle = getRotation();
	angle %= 360;
	if (angle > 270)
	{
		lineFireString.pt1 = ccp(rcItem.getMinX(), rcItem.getMinY());
		lineFireString.pt2 = ccp(rcItem.getMaxX(), rcItem.getMaxY());
	}
	else if (angle > 180)
	{
		lineFireString.pt1 = ccp(rcItem.getMinX(), rcItem.getMaxY());
		lineFireString.pt2 = ccp(rcItem.getMaxX(), rcItem.getMinY());
	}
	else if (angle > 90)
	{
		lineFireString.pt1 = ccp(rcItem.getMinX(), rcItem.getMinY());
		lineFireString.pt2 = ccp(rcItem.getMaxX(), rcItem.getMaxY());
	}
	else
	{
		lineFireString.pt1 = ccp(rcItem.getMinX(), rcItem.getMaxY());
		lineFireString.pt2 = ccp(rcItem.getMaxX(), rcItem.getMinY());
	}


	// MarioÏ߶Î
	Line lineMario[2];
	CCRect rcMario = _mario->boundingBox();
	lineMario[0].pt1 = ccp(rcMario.getMinX(), rcMario.getMinY());
	lineMario[0].pt2 = ccp(rcMario.getMaxX(), rcMario.getMaxY());
	lineMario[1].pt1 = ccp(rcMario.getMaxX(), rcMario.getMinY());
	lineMario[1].pt2 = ccp(rcMario.getMinX(), rcMario.getMaxY());

	for (int i = 0; i < 2; ++i)
	{
		if (ccpSegmentIntersect(lineMario[i].pt1, lineMario[i].pt2, lineFireString.pt1, lineFireString.pt2))
			_mario->Die(false);
	}

}
예제 #21
0
파일: Ball.cpp 프로젝트: acc85/cocos2d-x
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);
        }
    }    
} 
예제 #22
0
/** Transform the bounding rectangle of the 2D node on the X-Y plane into 3D. */
void CC3BillboardBoundingBoxArea::transformVolume()
{
	super::transformVolume();

	// Get the corners of the CCNode bounding box
	CCRect br = getBillboardBoundingRect();
	CCPoint bbMin = ccp(br.getMinX(), br.getMinY());
	CCPoint bbMax = ccp(br.getMaxX(), br.getMaxY());
	
	// Construct all 4 corner vertices of the local bounding box and transform each to global coordinates
	m_vertices[0] = m_pNode->getGlobalTransformMatrix()->transformLocation( cc3v(bbMin.x, bbMin.y, 0.0) );
	m_vertices[1] = m_pNode->getGlobalTransformMatrix()->transformLocation( cc3v(bbMin.x, bbMax.y, 0.0) );
	m_vertices[2] = m_pNode->getGlobalTransformMatrix()->transformLocation( cc3v(bbMax.x, bbMin.y, 0.0) );
	m_vertices[3] = m_pNode->getGlobalTransformMatrix()->transformLocation( cc3v(bbMax.x, bbMax.y, 0.0) );
	
	/*LogTrace(@"%@ bounding volume transformed %@ MinMax(%@, %@) to (%@, %@, %@, %@)", _node,
			 NSStringFromCGRect(br),
			 NSStringFromCGPoint(bbMin), NSStringFromCGPoint(bbMax), 
			 NSStringFromCC3Vector(_vertices[0]), NSStringFromCC3Vector(_vertices[1]),
			 NSStringFromCC3Vector(_vertices[2]), NSStringFromCC3Vector(_vertices[3]));*/
}
예제 #23
0
void CAScrollView::setContainerFrame(const CCPoint& point, const CCSize& size)
{
    if (!size.equals(CCSizeZero))
    {
        CCRect rect;
        rect.origin = point;
        rect.size = size;
        m_pContainer->setFrame(rect);
    }
    else
    {
        m_pContainer->setFrameOrigin(point);
    }
    
    CCRect rect = m_pContainer->getFrame();
    
    m_bSlidingMinX = fabsf(rect.getMinX()) < FLT_EPSILON;
    m_bSlidingMaxX = fabsf(rect.getMaxX() - this->getBounds().size.width) < FLT_EPSILON;
    m_bSlidingMinY = fabsf(rect.getMinY()) < FLT_EPSILON;
    m_bSlidingMaxY = fabsf(rect.getMaxY() - this->getBounds().size.height) < FLT_EPSILON;
}
//-------------------------------------------------------------------------
void FKMaskChunk::draw()
{
	if( !m_bIsUseDebugRender )
		return;
	if( !m_bIsVisible )
		return;

	CCPoint tagOriginPos;
	CCPoint tagDestPos;
	CCRect tagRect;
	MaskGridsMap::iterator Ite = m_mapMaskGrids.begin();
	for( ; Ite != m_mapMaskGrids.end(); ++Ite )
	{
		if( Ite->second )
		{
			Ite->second->GetRectInChunk( tagRect );
			tagOriginPos = ccp( tagRect.getMinX(), tagRect.getMinY() );
			tagDestPos = ccp( tagRect.getMaxX(), tagRect.getMaxY() );
			FKCW_Base_DrawingPrimitives::DrawSolidRoundRect( 
				tagOriginPos, tagDestPos, 4, ccc4BFromccc4F(s_MaskGridDebugColor) );
		}
	}
}
CCSize getRectSize(const CCRect&rect){
    CCSize size=CCSize(rect.getMaxX()-rect.getMinX(),rect.getMaxY()-rect.getMinY());
    return size;
}
예제 #26
0
/** Calculate bounding box from bounding rect of 2D node. */
CC3Box CC3Billboard::getLocalContentBoundingBox()
{
	CCRect bRect = getBillboardBoundingRect();
	return CC3Box(bRect.getMinX(), bRect.getMinY(), 0.0,
							  bRect.getMaxX(), bRect.getMaxY(), 0.0);
}
예제 #27
0
bool GameLayer::isCollisionBottom(CCRect roleBox, CCRect collisionBox) {
    
    CCPoint targetPoint = ccp(roleBox.getMidX(), roleBox.getMinY());
    return collisionBox.containsPoint(targetPoint);
}
예제 #28
0
CCRect CSystem::rectSetScale(CCRect rect, float scale)
{
	return CCRectMake(rect.getMinX() * scale, rect.getMinY() * scale, rect.size.width * scale, rect.size.height * scale);
}
예제 #29
0
void ItemTortoise::collision()
{
	// 防止持续碰撞检测
	if ( _bGodMode || _mario->_status ==Mario::DEAD ||_mario->_bGodMode)
	{
		return;
	}
	CCRect rcMario = _mario->boundingBox();
	CCRect rcItem = this->boundingBox();
	bool coll = rcMario.getMinY() > rcItem.getMaxY() - rcItem.size.height / 2;
	// mario 碰撞
	if (rcMario.intersectsRect(rcItem))
	{
		if ((_status == NORMAL))
		{
			if (marioUpHit(rcMario, rcItem, coll))
			{
				_status = SLEEP;
				scheduleOnce(schedule_selector(ItemTortoise::revive), 10.0f);
			}
			else
			{
				_mario->die(false);
			}
		}
		else if (_status == SLEEP)
		{
			Common::playMusic(std::string("CaiSiGuaiWu"));

			_speed = 150;
			_status = CRAZY;
			setGodMode(1.0f);
			unschedule(schedule_selector(ItemTortoise::revive));

			if (_mario->getPositionX() < getPositionX())
			{
				_dir = Common::RIGHT;
			}
			else
			{
				_dir = Common::LEFT;
			}

		}
		else if (_status == CRAZY)
		{
			if (marioUpHit(rcMario, rcItem, coll))
			{
				_status = DEAD;
			}
			else
			{
				_mario->die(false);
			}
		}
		else 
		{
			Common::playMusic(std::string("CaiSiGuaiWu"));

			_speed = 0;
			CCJumpBy* moveUp = CCJumpBy::create(0.7f, ccp(7, -10), 8, 1);
			CCMoveBy* moveDown = CCMoveBy::create(8.0f, ccp(0, -winSize.height));
			CCCallFunc* callfunc = CCCallFunc::create(this, callfunc_selector(ItemTortoise::die));
			CCSequence* seq = CCSequence::create(moveUp, moveDown, callfunc, NULL);

			this->runAction(seq);
		}
	}
}
예제 #30
0
// 边界碰撞检测
bool TileMapInfo::collisionTest(CCRect rect) {

    int gid = 0;
    CCSize mapSize = mTMXTileMap->getContentSize();  //地图的逻辑大小
    CCSize tileSize = mTMXTileMap->getTileSize();    // 地图的基本元的大小

    if(rect.getMinX() <0 || rect.getMaxX() >= mapSize.width
            || rect.getMinY() < 0 || rect.getMaxY() >= mapSize.height
      ) {
        return true;
    }

    /*
    for(int i=0;i<26;i++) {
        for(int j=0;j<26;j++) {
          int gid = mTMXLayers[0]->tileGIDAt(ccp(i,j));
            enumTileType type = gidToTileType[gid];
            int flag = 0;
            switch ((type)) {
                case tileNone:
                    flag = 0;
                    break;
                case tileGrass:
                    flag = 1;
                    break;
                case tileSteel:
                    flag = 2;
                    break;
                case tileWall:
                    flag = 3;
                    break;
                case tileRiver:
                    flag = 4;
                    break;
                case tileKing:
                    flag = 5;
                    break;
                default:
                    break;
            }
            printf("%d,",flag);
        }
    }
    */
    //将坦克Y坐标转换为地图上的Y坐标
    float MinY = mapSize.height - rect.getMinY();   //底边的y坐标
    float MaxY = mapSize.height - rect.getMaxY();   //顶边的y坐标

    //对坦克四个顶点进行碰撞检测
    gid = mTMXLayers[0]->tileGIDAt(ccp((int)(rect.getMinX() / tileSize.width),
                                       (int)(MinY / tileSize.height)));
    if (gidToTileType[gid] != tileNone && gidToTileType[gid] != tileGrass)
        return true;
    gid = mTMXLayers[0]->tileGIDAt(ccp((int)(rect.getMinX() / tileSize.width),
                                       (int)(MaxY / tileSize.height)));
    if (gidToTileType[gid] != tileNone && gidToTileType[gid] != tileGrass)
        return true;
    gid = mTMXLayers[0]->tileGIDAt(ccp((int)(rect.getMaxX() / tileSize.width),
                                       (int)(MaxY / tileSize.height)));
    if (gidToTileType[gid] != tileNone && gidToTileType[gid] != tileGrass)
        return true;
    gid = mTMXLayers[0]->tileGIDAt(ccp((int)(rect.getMaxX() / tileSize.width),
                                       (int)(MinY / tileSize.height)));
    if (gidToTileType[gid] != tileNone && gidToTileType[gid] != tileGrass)
        return true;

    return false;
}