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
/** 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 );
	}
}
예제 #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;
}
예제 #6
0
bool CCRect::intersectsRect(const CCRect& rect) const
{
    return !(     getMaxX() < rect.getMinX() ||
             rect.getMaxX() <      getMinX() ||
                  getMaxY() < rect.getMinY() ||
             rect.getMaxY() <      getMinY());
}
예제 #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 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;

}
예제 #10
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);
}
예제 #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
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;
}
예제 #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);
	
}
예제 #14
0
void JvSprite::updatePosToJvGame()
{
	CCRect boundingrect = boundingBox();
	float cocospointX = (float)boundingrect.getMinX();
	float cocospointY = (float)boundingrect.getMaxY();
	JvPoint cocospoint(cocospointX,cocospointY);
	JvPoint jvgamePoint = JvU::cocos2dPoint_to_JvGamePoint(cocospoint,JvG::stateP->getStateLayer()->getContentSize().height);
	mJvObject->x = jvgamePoint.x;
	mJvObject->y = jvgamePoint.y;
	mJvObject->width = boundingrect.size.width;
	mJvObject->height = boundingrect.size.height;
}
예제 #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
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);
	}

}
예제 #19
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);
        }
    }    
} 
예제 #20
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]));*/
}
예제 #21
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) );
		}
	}
}
예제 #23
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);
}
예제 #24
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);
}
예제 #25
0
bool Tank::command(enumOrder order) {
    
    float stepX = 0.0f;
    float stepY = 0.0f;
    float fRotation = getRotation();
    
    
   // CCRect srect = this->boundingBox();
   // printf("SSSSSSrect_pos: %f, %f",srect.getMinX(),srect.getMinY());
    
   //  printf("fro:%lf\n",fRotation);
    //  printf("thisOrder:%d\n",order);
    
    // printf("coomd:%lf\n",fRotation);
    // printf("whatorder:%d\n",cmdGoDown);
    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();
            //  break;
        default:
            break;
            
    }
   
    //setPositionX(getPositionX() + stepX);
    //setPositionY(getPositionY() + stepY);
    setRotation(fRotation);
    
    CCRect rect = this->boundingBox();
    
    //printf("rect: %f,%f\n",rect.size.width,rect.size.height);
    printf("minx %f,  %f\n",rect.getMinX(),rect.getMinY());
    
    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;
    
    
    /*
    if (!mTileMapInfo->collisionTest(CCRectMake(rect.getMinX() + stepX,
                                                rect.getMinY() + stepY, rect.size.width, rect.size.height)))
    {
        setPositionX(getPositionX() + stepX);
        setPositionY(getPositionY() + stepY);
        return true;  
    }
    */
    
    return false;
}
예제 #26
0
bool GameLayer::isCollisionLeft(CCRect roleBox, CCRect collisionBox) {
    
    CCPoint targetPoint = ccp(roleBox.getMinX(), roleBox.getMidY());
    return collisionBox.containsPoint(targetPoint);
}
예제 #27
0
CCRect CSystem::rectSetScale(CCRect rect, float scale)
{
	return CCRectMake(rect.getMinX() * scale, rect.getMinY() * scale, rect.size.width * scale, rect.size.height * scale);
}
예제 #28
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;
}
예제 #29
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();
}
CCSize getRectSize(const CCRect&rect){
    CCSize size=CCSize(rect.getMaxX()-rect.getMinX(),rect.getMaxY()-rect.getMinY());
    return size;
}