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;

}
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;
}
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);
	}

}
Esempio n. 5
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;
}
Esempio n. 6
0
bool CCRect::intersectsRect(const CCRect& rect) const
{
    return !(     getMaxX() < rect.getMinX() ||
             rect.getMaxX() <      getMinX() ||
                  getMaxY() < rect.getMinY() ||
             rect.getMaxY() <      getMinY());
}
Esempio n. 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;
    }
}
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;
}
bool GameScene::ccTouchBegan(CCTouch *touch, CCEvent *event) {
	if (getBlocksDestroyed() >= BLOCK_COLUMN * BLOCK_ROW) {
		return false;
	}

	CCNode* lavel = dynamic_cast<CCNode*>(this->getChildByTag(kTagStartLabel));
	if (lavel) {
		this->removeChild(lavel, true);
	}

//	CCLog("ccTouchBegan1");
	//現在ボールが飛んでいなければボールを飛ばす
	if (!isTouched) {
		if (UserSettings::getSESetting())
			SimpleAudioEngine::sharedEngine()->playEffect(MP3_BALLPUSH);
		isTouched = true;
		return true;
	}

	CCPoint location = touch->getLocation();
	CCSprite *bar = dynamic_cast<CCSprite*>(this->getChildByTag(kTagBar));
	if (!bar)
		return false;

	//バーの横幅以内がタップされた場合のみタップイベントを有効にする
	bool b = false;
	CCRect rect = bar->boundingBox();
	if (!rect.containsPoint(location)) {
		b = true;
	} else if (location.x >= rect.getMinX() && location.x <= rect.getMaxX()) {
		b = true;
	}
	return b;

}
Esempio n. 10
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;
}
Esempio n. 11
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;
}
Esempio n. 12
0
void GGameLayerBase::draw()
{
	CCLayer::draw();
	//return;
	glLineWidth(1.5);
	CCRect dataRect;
	CCArray* arraychildren= _spriteLayer->getChildren();
	CCObject *obj=NULL;
	CCARRAY_FOREACH(arraychildren,obj)
	{
		ActionSprite *sprite=(ActionSprite*)obj;
		ccDrawColor4B(255, 0, 0, 255);
		dataRect=sprite->GetHitbox();
		ccDrawRect(dataRect.origin,ccp(dataRect.getMaxX(),dataRect.getMaxY()));
		ccDrawColor4B(0, 255, 0, 255);
		dataRect=sprite->GetAttackBox();
		ccDrawRect(dataRect.origin,ccp(dataRect.getMaxX(),dataRect.getMaxY()));
	}
Esempio n. 13
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);
	
}
Esempio n. 14
0
void Start::update(float dt){

	for (int i=0; i<ggroundNum; i++)
	{
		pGround[i]->setPositionX(pGround[i]->getPositionX() - 3);
		CCRect rcGroundBounding = pGround[i]->boundingBox(); 
		if (rcGroundBounding.getMaxX()<=-1)
		{
			int groundsize = pGround[i]->getContentSize().width;
			pGround[i]->setPositionX(mScreenSize.width+groundsize);
		}
	}

}
Esempio n. 15
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();
}
Esempio n. 16
0
/** If the bounding mesh exists, update its vertices to match the bounding box of the 2D node. */
void CC3Billboard::updateBoundingMesh()
{
	if (m_pMesh) 
	{
		CCRect bRect = getBillboardBoundingRect();
		GLfloat xMin = bRect.getMinX();
		GLfloat xMax = bRect.getMaxX();
		GLfloat yMin = bRect.getMinX();
		GLfloat yMax = bRect.getMaxY();
		m_pMesh->setVertexLocation( cc3v(xMax, yMax, 0.0), 0 );
		m_pMesh->setVertexLocation( cc3v(xMin, yMax, 0.0), 1 );
		m_pMesh->setVertexLocation( cc3v(xMax, yMin, 0.0), 2 );
		m_pMesh->setVertexLocation( cc3v(xMin, yMin, 0.0), 3 );
	}
}
Esempio n. 17
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));
}
Esempio n. 18
0
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);
        }
    }    
} 
Esempio n. 19
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]));*/
}
Esempio n. 20
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) );
		}
	}
}
Esempio n. 22
0
void GameLayer::onEnter()
{
    CCLayer::onEnter();

    CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(GameLayer::Update), this, 0, false);

#ifndef DEBUG_NO_UI
    // Init UI.
    CCNode* pUiNode = CCNode::create();
    addChild(pUiNode, g_uiZOrder);

    UiManager::CreateSingleton();
    UiManager::Singleton().Init(pUiNode);
#endif

    GameObjectManager::CreateSingleton();
    BuffManager::CreateSingleton();
    SkillManager::CreateSingleton();
    SkillManager::Singleton().Init(this);

#ifndef DEBUG_HIDE_TEXT
    // Back ground.
    CCSprite* pBackGround = CCSprite::create("backGround.jpg");

    CCRect rect = pBackGround->getTextureRect();
    float width = rect.getMaxX() - rect.getMinX();
    pBackGround->setScaleX((VisibleRect::right().x - VisibleRect::left().x) / width);
    float height = rect.getMaxY() - rect.getMinY();
    pBackGround->setScaleY((VisibleRect::top().y - VisibleRect::bottom().y) / height);

    pBackGround->setPosition(VisibleRect::center());
    addChild(pBackGround, g_backGroundZOrder);
#endif

    MainPlayerLogic::CreateSingleton();
    MainPlayerLogic::Singleton().Init(this);
    
#ifndef DEBUG_NO_MONSTER
    // Init monster logic.
    m_pMonsterGroupLogic = new MonsterGroupLogic();
    m_pMonsterGroupLogic->autorelease();
    addChild(m_pMonsterGroupLogic, g_monsterZOder);
#endif

#ifndef DEBUG_NO_GENERAL
    // Init general logic.
    std::vector< EGeneralType > generalVec;
    generalVec.push_back(eGT_DiaoChan);
    generalVec.push_back(eGT_MaChao);
    m_pGeneralGroupLogic = new GeneralGroupLogic(generalVec);
    m_pGeneralGroupLogic->autorelease();
    addChild(m_pGeneralGroupLogic, g_generalZOrder);
#endif

#ifndef DEBUG_NO_GPE
    // Init Gpe logic.
    m_pGpeLogic = new GpeLogic();
    m_pGpeLogic->autorelease();
    addChild(m_pGpeLogic);
#endif

    //setTouchEnabled(true);

    m_bTouchEnabled = true;
    CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 2);
}
Esempio n. 23
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);
}
void HelloWorld::update(float dt){
	if(m_istatus!=GAMEOVER){
		int lastgroud=-1;
		for (int i=0; i<m_pGroundVec.size(); i++)
		{
			m_pGroundVec[i]->setPositionX(m_pGroundVec[i]->getPositionX() - MOVESPEED/mfax);
			CCRect rcGroundBounding = m_pGroundVec[i]->boundingBox(); 
			if (rcGroundBounding.getMaxX()<=0)
			{
				lastgroud=i;			
			}
		}
		//float groundsize = m_pGround[i]->getContentSize().width*1.0;
		//m_pGround[i]->setPositionX(groundsize/2. + (GGROUNDNUM-1)*groundsize);
		if(lastgroud>-1){
			float moveposx=m_pGroundVec[m_ilastground]->boundingBox().getMaxX();
			moveposx+=m_pGroundVec[lastgroud]->getContentSize().width/2.;
			m_pGroundVec[lastgroud]->setPositionX(moveposx);
			m_ilastground=lastgroud;
			//CCLOG("win x:%f,Ground x:%f,mfac:%f,index=%d ",this->mScreenSize.width,
			//	moveposx,mfac,m_ilastground);
		}

	}
	if(m_istatus==GETREADY || m_istatus==GOSTART ){
		return;
	}
	//最后一个柱子离屏幕右边大于固定距离时放出来
	if(m_pDownBarVec.size()>0 && (mScreenSize.width-m_pDownBarVec.back()->getPositionX())
	>(mScreenSize.width*0.4))
	{
		addBar(0);
	}
	//重力响应
	mWorld->Step(dt, 8, 3); // 8和3为官方推荐数据
	myangle+=1.0f;
	if(myangle>=25)
	{
		iFlyKeep++;
		myangle=25;
	}
	if (myangle<25)
	{
		iFlyKeep=0;
		mBird->setRotation(myangle);
	}
	CCLOG("bird iFlyKeep:%d,angle:%0.2f,myangle:%d",iFlyKeep,mBird->getRotation(),myangle);
	if(iFlyKeep>30)
	{
		//if (mBird->getRotation() < 10.f/mfac && mBird->getRotation() > -85.f)
		//{
		//	mBird->setRotation(mBird->getRotation()-10.f);
		//}

		if(mBird->getRotation()-10.f<-90.f){
			mBird->setRotation(-90.f);
		}
		else{
			mBird->setRotation(mBird->getRotation()-6.f);
		}
		//if(mBird->getRotation() > -91)
		//mBird->setRotation(mBird->getRotation()-2.5f);
	}


	//CCLOG("bird angle:%0.2f,myangle:%0.2f ",mBird->getRotation(),myangle);
	if(myflag==1)
	{
		mBird->setRotation(-90);
		return;
	}
	//禁止小鸟越过屏幕高度
	if(mBird->getPositionY()>mScreenSize.height)
	{
		mBird->setPositionY(mScreenSize.height);
	}
	/*for (int i=0; i<gbackgroundNum; i++)
	{
	m_pBackGround[i]->setPositionX(m_pBackGround[i]->getPositionX() - 1); 
	CCRect rcBounding = m_pBackGround[i]->boundingBox(); 
	if (rcBounding.getMaxX() <= 0)    // 如果完全消失在屏幕上,就移动精灵1到精灵3的后面  
	{  
	int backgroundsize = m_pBackGround[i]->getContentSize().width;
	m_pBackGround[i]->setPositionX(backgroundsize/2 + (ggroundNum-1)*backgroundsize);  
	}  

	}
	*/

	//CCLOG("rcBounding1 MinX:%d MinY:%d MaxX:%d MaxY:%d", rcBounding1.getMinX()
	//, rcBounding1.getMinY(), rcBounding1.getMaxX(), rcBounding1.getMaxY());

	//给小鸟计分
	if(m_pDownBarVec.size()>0 && m_pDownBarVec.front()->boundingBox().getMaxX() <= this->mBird->boundingBox().getMaxX())
	{
		ShowNumberNode * snn = (ShowNumberNode *)this->getChildByTag(0);
		snn->f_ShowNumber(++testnum);
//		EFFECT_PLAY(true,MUSIC_POINT);
		m_pDownBarVec.pop_front();
	}

	CCSprite *s;
	std::vector<b2Body *>toDestroy;
	map<CCSprite *,int>::iterator itbar;
	for(b2Body *b = mWorld->GetBodyList(); b != NULL; b = b->GetNext()){
		s = (CCSprite *)b->GetUserData();
		if(s != NULL && s->getTag()==SPRITE_TAG_BAR){

			//CCLOG("bird x:%f guan x:%f ", mBird->getPositionX(),s->getPositionX());

			s->setPositionX(s->getPositionX() - MOVESPEED/mfax);
			if(s->getPositionX() < -20/mfac){
				s->setVisible(false);
				toDestroy.push_back(b);
				//s->removeFromParent();					
				//mWorld->DestroyBody(b);
				//b = mWorld->GetBodyList();
			}
		}
	}


	std::vector<b2Body*>::iterator pos2;
	for (pos2 = toDestroy.begin();pos2!=toDestroy.end();++pos2)
	{
		b2Body* body = *pos2;
		if(body->GetUserData()!=NULL)
		{
			CCSprite* sprite = (CCSprite*)body->GetUserData();
			this->removeChild(sprite,true);
		}

		mWorld->DestroyBody(body);
		body = NULL;

	}

}
Esempio n. 25
0
bool GameLayer::isCollisionRight(CCRect roleBox, CCRect collisionBox) {
    
    CCPoint targetPoint = ccp(roleBox.getMaxX(), roleBox.getMidY());
    return collisionBox.containsPoint(targetPoint);
}
Esempio n. 26
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;
}
Esempio n. 27
0
void CAScrollView::ccTouchMoved(CATouch *pTouch, CAEvent *pEvent)
{
    CC_RETURN_IF(m_bscrollEnabled == false);
    
    CCPoint p_container = m_pContainer->getFrameOrigin();
    CCPoint p_off = CCPointZero;
    
    if (m_pTouches->count() == 1)
    {
        p_off = ccpSub(this->convertToNodeSpace(pTouch->getLocation()),
                       this->convertToNodeSpace(pTouch->getPreviousLocation()));
    }
    else if (m_pTouches->count() == 2)
    {
        CATouch* touch0 = dynamic_cast<CATouch*>(m_pTouches->objectAtIndex(0));
        CATouch* touch1 = dynamic_cast<CATouch*>(m_pTouches->objectAtIndex(1));
        CCPoint mid_point = ccpMidpoint(this->convertToNodeSpace(touch0->getLocation()),
                                        this->convertToNodeSpace(touch1->getLocation()));
        
        if (m_fMinimumZoomScale < m_fMaximumZoomScale)
        {
            float touch_lenght = ccpDistance(touch0->getLocation(), touch1->getLocation());
            float scale_off = _px(touch_lenght - m_fTouchLength) * 0.0015f;
            
            m_fZoomScale = m_pContainer->getScale();
            m_fZoomScale += m_fZoomScale * scale_off;
            
            m_fZoomScale = MIN(m_fZoomScale, m_fMaximumZoomScale);
            m_fZoomScale = MAX(m_fZoomScale, m_fMinimumZoomScale);
            
            m_pContainer->setScale(m_fZoomScale);
            m_fTouchLength = touch_lenght;
        }
        
        p_off = ccpSub(mid_point, ccpAdd(m_pContainer->getFrameOrigin(),
                                         m_pContainer->getAnchorPointInPoints() * m_fZoomScale));
    }
    
    
    if (m_bBounces)
    {
        CCSize size = this->getBounds().size;
        CCRect rect = m_pContainer->getFrame();
        rect.size.width = MAX(rect.size.width, size.width);
        rect.size.height = MAX(rect.size.height, size.height);
        CCPoint scale = CCPoint(1.0f, 1.0f);
        
        if (p_container.x > 0)
        {
            scale.x = MAX(0, 0.5f - rect.getMinX() / size.width);
            p_off.x *= scale.x;
        }
        
        if (p_container.y > 0)
        {
            scale.y = MAX(0, 0.5f - rect.getMinY() / size.height);
            p_off.y *= scale.y;
        }
        
        if ((p_container.x + rect.size.width - size.width) < 0)
        {
            scale.x = MAX(0, rect.getMaxX() / size.width - 0.5f);
            p_off.x *= scale.x;
        }
        
        if ((p_container.y + rect.size.height - size.height) < 0)
        {
            scale.y = MAX(0, rect.getMaxY() / size.height - 0.5f);
            p_off.y *= scale.y;
        }
    }
    
    p_container = ccpAdd(p_container, p_off);
    
    m_tPointOffset.push_back(p_off);

    if (m_tPointOffset.size() > 3)
    {
        m_tPointOffset.pop_front();
    }
    
    if (m_bBounces == false)
    {
        p_container = this->getScrollWindowNotOutPoint(p_container);
    }
    else
    {
        if (m_bBounceHorizontal == false)
        {
            p_container.x = this->getScrollWindowNotOutHorizontal(p_container.x);
        }
        
        if (m_bBounceVertical == false)
        {
            p_container.y = this->getScrollWindowNotOutVertical(p_container.y);
        }
    }
    
    if (p_container.equals(m_pContainer->getFrameOrigin()) == false)
    {
        this->setContainerFrame(p_container);
        this->showIndicator();
        
        if (m_bTracking == false)
        {
            if (m_pScrollViewDelegate)
            {
                m_pScrollViewDelegate->scrollViewWillBeginDragging(this);
            }
            m_bTracking = true;
        }
        
        if (m_pScrollViewDelegate)
        {
            m_pScrollViewDelegate->scrollViewDidScroll(this);
            m_pScrollViewDelegate->scrollViewDidMoved(this);
        }
    }
    
    this->changedFromPullToRefreshView();
}
Esempio n. 28
0
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);
}
CCSize getRectSize(const CCRect&rect){
    CCSize size=CCSize(rect.getMaxX()-rect.getMinX(),rect.getMaxY()-rect.getMinY());
    return size;
}