Example #1
0
void CACollectionView::updateSectionHeaderAndFooterRects()
{
	CCRect rect = this->getBounds();
	rect.origin = getContentOffset();

	std::vector<CCRect>::iterator itr;
	for (itr = m_rSectionRects.begin(); itr != m_rSectionRects.end(); itr++)
	{
		CC_CONTINUE_IF(!rect.intersectsRect(*itr));
		int i = itr - m_rSectionRects.begin();
		CAView* header = NULL;
		CAView* footer = NULL;
		float headerHeight = 0;
		float footerHeight = 0;
		if (m_pSectionHeaderViews.find(i) != m_pSectionHeaderViews.end())
		{
			header = m_pSectionHeaderViews[i];
			headerHeight = m_pSectionHeaderViews[i]->getFrame().size.height;
		}
		if (m_pSectionFooterViews.find(i) != m_pSectionFooterViews.end())
		{
			footer = m_pSectionFooterViews[i];
			footerHeight = m_pSectionFooterViews[i]->getFrame().size.height;
		}
		if (header && m_bAlwaysTopSectionHeader)
		{
			CCPoint p1 = rect.origin;
			p1.y = MAX(p1.y, itr->origin.y);
			p1.y = MIN(p1.y, itr->origin.y + itr->size.height
				- headerHeight - footerHeight);
			header->setFrameOrigin(p1);
		}
		if (footer && m_bAlwaysBottomSectionFooter)
		{
			CCPoint p2 = CCPointZero;
			p2.y = MIN(rect.origin.y + this->getBounds().size.height - footerHeight,
				itr->origin.y + itr->size.height - footerHeight);
			p2.y = MAX(p2.y, itr->origin.y + headerHeight);
			footer->setFrameOrigin(p2);
		}
	}
}
Example #2
0
WXGrid* WXGridPanel::itemForTouch( cocos2d::CCTouch * touch )
{
	CCPoint touchLocation = touch->getLocation();
	std::vector<WXGrid*>::iterator itr = m_gridList->begin();
	for (;itr!=m_gridList->end();itr++)
	{
		if (*itr && (*itr)->isVisible())
		{
			CCPoint local = (*itr)->convertToNodeSpace(touchLocation);
			CCRect r = (*itr)->rect();
			r.origin = CCPoint::ZERO;

			if (r.containsPoint(local))
			{
				return (*itr);
			}
		}
	}
	return NULL;
}
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;
}
Example #4
0
bool Ossan::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){
    
    const float WEIGHT_TOUCH_AREA = 0.8f;
    
    // タッチ位置を取得
    CCPoint point = pTouch->getLocation();
    // スプライトの大きさ
    CCSize size = this->getTexture()->getContentSize();
    // スプライトの範囲
    CCRect rect = CCRectMake(this->getPositionX()-size.width/2, this->getPositionY()-size.height/2, size.width * WEIGHT_TOUCH_AREA, size.height * WEIGHT_TOUCH_AREA);
    
    
    
    // タッチ位置がスプライト内ならイベント処理するのでtrueを返す
    if(rect.containsPoint(point)){
        return true;
    }else{
        return false;
    }
}
bool DropDownListSprite:: ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
    if (!m_isShowMenu)
    {
        CCRect rect;
        rect.origin = CCPointZero;
        rect.size = getContentSize();
        CCPoint position = convertTouchToNodeSpace(pTouch);
        
        if (rect.containsPoint(position))
        {
           
            m_isShowMenu = true;
            
            addChild(m_mainMenu);
            
            for (int i = 0, j = (int) m_selectLabels.size(); i<j; ++i)
            {
                if (i == m_lastSelectedIndex)
                {
                    CCLOG("xxxx");
                    m_bgLayers[i]->setColor(DROPDOWNLIST_HIGHLIGHT_COLOR3);
                    m_showLabel->setString(m_selectLabels[i]->getString());
                }
                
                else
                {
                    CCLOG("xxxy");
                    m_bgLayers[i]->setColor(DROPDOWNLIST_NORMAL_COLOR3);
                }
                
            }
            
            return true;
            
        }
    }
    
    return false;
    
}
void HelloWorld::update(float time)
{
    
    if (!isEnemyAdded)
    {
        return;
    }
    
	CCArray *projectilesToDelete = CCArray::create();
    if (_projectiles->count())
    {
        CCObject *pObj = NULL;
        CCARRAY_FOREACH(_projectiles, pObj)
        {
            CCSprite *projectile = (CCSprite*)pObj;
            CCRect projectileRect = CCRectMake(projectile->getPosition().x - (projectile->getContentSize().width/2),
                                              projectile->getPosition().y - (projectile->getContentSize().height/2),
                                              projectile->getContentSize().width,
                                              projectile->getContentSize().height);
            
            CCArray *targetsToDelete = CCArray::create();
            
            CCObject *tObj = NULL;
            CCARRAY_FOREACH(_targets, tObj)
            {
                CCSprite *target = (CCSprite*)tObj;
                CCRect targetRect = CCRectMake(target->getPosition().x - (target->getContentSize().width/2),
                                               target->getPosition().y - (target->getContentSize().height/2),
                                               target->getContentSize().width,
                                               target->getContentSize().height);
                
                if (projectileRect.intersectsRect(targetRect))
                {
                    targetsToDelete->addObject(target);
                }
                else if(!targetsToDelete->containsObject(target) && player->boundingBox().intersectsRect(targetRect))
                {
                     targetsToDelete->addObject(target);
                }
                
            }
Example #7
0
void ArenaCreateRoom::ccTouchEnded( cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent )
{
	CCPoint endPos=pTouch->getLocation();

	float delta = 5.0f;
	if (::abs(endPos.x - m_beginPos.x) > delta
		|| ::abs(endPos.y - m_beginPos.y) > delta)
	{
		// not click
		m_beginPos.x = m_beginPos.y = -1;
		return;
	}

	CCPoint point = convertTouchToNodeSpace(pTouch);

	CCRect rect;
	rect.origin = m_RoomName->getPosition();
	rect.size = m_RoomName->getDimensions();
	rect.origin.x -= m_RoomName->getAnchorPointInPoints().x;
	rect.origin.y -= m_RoomName->getAnchorPointInPoints().y;

	CCRect rect1;
	rect1.origin = m_RoomPassword->getPosition();
	rect1.size = m_RoomPassword->getDimensions();
	rect1.origin.x -= m_RoomPassword->getAnchorPointInPoints().x;
	rect1.origin.y -= m_RoomPassword->getAnchorPointInPoints().y;

	if (rect.containsPoint(point))
	{
		m_RoomName->attachWithIME();
	}
	else if (rect1.containsPoint(point))
	{
		m_RoomPassword->attachWithIME();
	}
	else
	{
		m_RoomName->detachWithIME();
		m_RoomPassword->detachWithIME();
	}
}
void GameScene::updateBlocks() {
	for (int i = 0; i < m_activeballs->count(); i++) {
		BallSprite* ball =
				dynamic_cast<BallSprite*>(m_activeballs->objectAtIndex(i));
		if (!ball)
			return;

		CCRect ballRect = ball->boundingBox();

		CCObject* jt = NULL;
		CCArray* blocksToDelete = new CCArray;

		CCARRAY_FOREACH(m_blocks, jt) {
			CCSprite* block = dynamic_cast<CCSprite*>(jt);
			//            CCLOG("updateGame target.x: %f, target.y: %f, tag: %d",target->getContentSize().width, target->getContentSize().height, target->getTag());
			CCRect blockRect = block->boundingBox();

			//衝突判定
			if (ballRect.intersectsRect(blockRect)) {
				// ボールは跳ね返す
				ball->bounceBall(blockRect, kTagBlock);

				blocksToDelete->addObject(block);

				//スコア加算
				m_score += 100;
				showScore();

				//確率に従ってボーナスアイテムを生成する
				makeItem(block);
			}
		}

		// 当たったブロックを消す
		CCARRAY_FOREACH(blocksToDelete, jt) {
			CCSprite *block = dynamic_cast<CCSprite*>(jt);
			m_blocks->removeObject(block);
			this->removeChild(block, true);

			m_blocksDestroyed++;
		}
Example #9
0
bool TSSprite::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
    CCPoint sLocalPos = convertToNodeSpace(touch->getLocation());
    CCRect sRC = CCRect(getPositionX() - getContentSize().width * getAnchorPoint().x,
                           getPositionY() - getContentSize().height * getAnchorPoint().y,
                           getContentSize().width, getContentSize().height);
    
    
    sRC.origin = CCPointZero;
    bool isTouched = sRC.containsPoint(sLocalPos);
    if(isTouched)
    {
        CCLog("点中了!! x:%d y:%d", (int)sLocalPos.x, (int)sLocalPos.y);
        return true;
    }
    else
    {
        CCLog("没点中了!! x:%d y:%d", (int)sLocalPos.x, (int)sLocalPos.y);
        return false;
    }
}
Example #10
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 HistoryScr::checkMeteorCollision() {

	CCArray *meteorsToRemove = CCArray::create();

	for (int ii = 0; ii < meteors->count(); ii++) {
		CCRect meteorRect =
				((CCSprite*) meteors->objectAtIndex(ii))->boundingBox();
		CCRect shipRect = shipBoundingBox();

		if (meteorRect.intersectsRect(shipRect) == true) {
			meteorsToRemove->addObject(meteors->objectAtIndex(ii));
			generateFire(
					((CCSprite *) meteors->objectAtIndex(ii))->getPosition());
			this->removeChild((CCSprite *) meteors->objectAtIndex(ii), true);
		}
	}

	for (int j = 0; j < meteorsToRemove->count(); j++) {
		meteors->removeObject(meteorsToRemove->objectAtIndex(j), true);
	}
}
void HelloWorld::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
    do
    {
        if (mUserNameTextField) {
            CCPoint endPos = pTouch->getLocation();
            
            float delta = 5.f;
            if (::abs(mBeginPos.x - endPos.x) > delta
                || ::abs(mBeginPos.y - endPos.y) > delta) {
                break;
            }
            
            CCRect rect;
            rect = getRect(mUserNameTextField);
            this->onClickTrackNode(rect.containsPoint(endPos));
            
        }
    } while (0);
    
}
Example #13
0
bool CCSpriteButton::ccTouchBegan(CCTouch *touch, CCEvent *event)
{
    m_StartTouchPoint = convertToNodeSpace(touch->getLocation());

    CCRect rect;
    rect.origin = CCPointZero;
    rect.size = getContentSize();
    m_IsEmitTouchEvent= rect.containsPoint(m_StartTouchPoint);
    if(m_IsEmitTouchEvent)
    {
        if (m_pSelectedSprite)
        {
            setDisplayFrame(m_pSelectedSprite->displayFrame());
        }
        return true;
    }
    else  
    {
        return false;
    }
}
Example #14
0
 /** 
* 检查是否在区域里
*/
bool UILabel::touchDown(float x,float y)
{
	CCPoint pos = ccp(x,y);
	pos = this->convertToNodeSpace(pos);
	nowTouchPoint = ccp(x,y);
	_touchIn = false;
	if (text && _editable)
	{
		CCRect rect = CCRectMake(
			text->getPosition().x - (text->getContentSize().width/2),
			text->getPosition().y - (text->getContentSize().height/2),
			text->getContentSize().width,
			text->getContentSize().height);
		if (rect.containsPoint(pos))
		{
			_touchIn = true;
			return true;
		}
	}
	return false;
}
Example #15
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]));*/
}
Example #16
0
void CCEditBox::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
{
    // CCLOG("CCEditBox::keyboardWillShow");
    CCRect rectTracked = getRect(this);
    
    // 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);
    }
}
Example #17
0
bool Pause::ccTouchBegan(CCTouch* pTouch, CCEvent* pEvent)
{
    CCPoint location = pTouch->getLocation();
    
    CCRect* pHomeTextureRect = new CCRect(63, 25, 76.8, 32);
    CCRect* pGameTextureRect = new CCRect(200, 25, 76.8, 32);
    CCRect* pRestartTextureRect = new CCRect(339, 25, 76.8, 32);
    
    if (pHomeTextureRect->containsPoint(location)) {
        this->removeFromParentAndCleanup(true);
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("main.mp3", true);
        CCScene* pMainMenuScene = MainMenuScene::scene();
        CCDirector::sharedDirector()->replaceScene(pMainMenuScene);
        CCDirector::sharedDirector()->resume();
        CCLOG("Remove");
    } else if (pGameTextureRect->containsPoint(location)) {
        this->removeFromParentAndCleanup(true);
        CCDirector::sharedDirector()->resume();
        CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
        CCLOG("Resume");
    } else if (pRestartTextureRect->containsPoint(location)) {
//        this->dialog->setVisible(true);
        CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true);
        CCScene* pGameScene = NormalGameScene::scene();
        CCDirector::sharedDirector()->replaceScene(pGameScene);
        CCDirector::sharedDirector()->resume();
        CCLOG("Restart");
    } else if (this->dialog->isVisible()) {
        this->dialog->setVisible(false);
    }
    return true;
}
Example #18
0
void CATableView::loadTableCell()
{
    CCRect rect = this->getBounds();
	rect.origin = getContentOffset();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.size.height *= 1.2f;
    
    for (unsigned int i=0; i<(unsigned int)m_rTableCellRectss.size(); i++)
    {
        for (unsigned int j=0; j<(unsigned int)m_rTableCellRectss.at(i).size(); j++)
        {
            CAIndexPath2E indexPath = CAIndexPath2E(i, j);
            CC_CONTINUE_IF(m_pUsedTableCells.count(indexPath) && m_pUsedTableCells[indexPath]);
            CCRect cellRect = m_rTableCellRectss[i][j];
            CC_CONTINUE_IF(!rect.intersectsRect(cellRect));
            CATableViewCell* cell = m_pTableViewDataSource->tableCellAtIndex(this, m_rTableCellRectss[i][j].size, i, j);
            CC_CONTINUE_IF(cell == NULL);
            cell->m_nSection = i;
            cell->m_nRow = j;
            cell->updateDisplayedAlpha(this->getAlpha());
            m_pContainer->addSubview(cell);
            cell->setFrame(m_rTableCellRectss[i][j]);
            m_pUsedTableCells[indexPath] = cell;
            if (m_pSelectedTableCells.count(indexPath))
            {
                cell->setControlStateSelected();
            }
            
            CAView* view = this->dequeueReusableLine();
            CCRect lineRect = m_rLineRectss[i][j];
            if (view == NULL)
            {
                view = CAView::createWithFrame(lineRect, m_obSeparatorColor);
            }
            m_pUsedLines[indexPath] = view;
            this->insertSubview(view, 1);
            view->setFrame(lineRect);
        }
    }
}
void HelloWorld::update(float dt)
{
	CCArray *projectilesToDelete = new CCArray;
	CCArray* targetsToDelete =new CCArray;
	CCObject* it = NULL;
	CCObject* jt = NULL;

	CCARRAY_FOREACH(_projectiles, it)
	{
		CCSprite *projectile = dynamic_cast<CCSprite*>(it);
		CCRect projectileRect = CCRectMake(
			projectile->getPosition().x - (projectile->getContentSize().width/2),
			projectile->getPosition().y - (projectile->getContentSize().height/2),
			projectile->getContentSize().width,
			projectile->getContentSize().height);

		CCARRAY_FOREACH(_targets, jt)
		{
			CCSprite *target = dynamic_cast<CCSprite*>(jt);
			CCRect targetRect = CCRectMake(
				target->getPosition().x - (target->getContentSize().width/2),
				target->getPosition().y - (target->getContentSize().height/2),
				target->getContentSize().width,
				target->getContentSize().height);

			if (projectileRect.intersectsRect(targetRect))
			{
				targetsToDelete->addObject(target);
				projectilesToDelete->addObject(projectile);
				
				_projectilesDestroyed++;     

				if (_projectilesDestroyed >= 5)
				{
					GameOverScene *gameOverScene = GameOverScene::create();
					gameOverScene->getLayer()->getLabel()->setString("You Win!");
					CCDirector::sharedDirector()->replaceScene(gameOverScene);
				}
			}
		}
Example #20
0
bool CATextSelViewEx::ccTouchBegan(CATouch *pTouch, CAEvent *pEvent)
{
	CCPoint cTouchPoint = this->convertTouchToNodeSpace(pTouch);
    
	CCRect newRectL = m_pCursorMarkL->getFrame();
	newRectL.InflateRect(8);
	CCRect newRectR = m_pCursorMarkR->getFrame();
	newRectR.InflateRect(8);

	m_iSelViewTouchPos = 0;
	if (newRectL.containsPoint(cTouchPoint))
	{
		m_iSelViewTouchPos = 1;
	}
	else if (newRectR.containsPoint(cTouchPoint))
	{
		m_iSelViewTouchPos = 2;
	}
	else if (m_pControlView)
	{
		if (touchSelectText(pTouch))
		{
			CATextToolBarView *pToolBar = CATextToolBarView::create();
			pToolBar->addButton(UTF8("\u526a\u5207"), m_pControlView, callfunc_selector(CATextView::ccCutToClipboard));
			pToolBar->addButton(UTF8("\u590d\u5236"), m_pControlView, callfunc_selector(CATextView::ccCopyToClipboard));
			pToolBar->addButton(UTF8("\u7c98\u8d34"), m_pControlView, callfunc_selector(CATextView::ccPasteFromClipboard));
			pToolBar->show(m_pControlView);
			return false;
		}
	}
	return true;
}
Example #21
0
void CACollectionView::recoveryCollectionCell()
{
	CCRect rect = this->getBounds();
	rect.origin = getContentOffset();
	rect.origin.y -= rect.size.height * 0.1f;
	rect.size.height *= 1.2f;

	std::map<CAIndexPath3E, CACollectionViewCell*>::iterator itr;
	for (itr = m_pUsedCollectionCells.begin(); itr != m_pUsedCollectionCells.end(); itr++)
	{
		CACollectionViewCell* cell = itr->second;
		CC_CONTINUE_IF(cell == NULL);

		CCRect cellRect = cell->getFrame();
		CC_CONTINUE_IF(rect.intersectsRect(cellRect));

		m_pFreedCollectionCells[cell->getReuseIdentifier()].pushBack(cell);
		cell->removeFromSuperview();
		cell->resetCollectionViewCell();
		itr->second = NULL;
	}
}
Example #22
0
void MainLayer::update(float delta)
{
	if (!disappearing)
	{
		CCNode *left = this->getChildByTag(TAG_LEFT);
		CCNode *right = this->getChildByTag(TAG_RIGHT);
		if (left && right)
		{

			CCRect leftRect = left->boundingBox();
			CCRect rightRect = right->boundingBox();
			leftRect.size = leftRect.size * 0.85f;
			rightRect.size = rightRect.size * 0.8f;
			if (leftRect.intersectsRect(rightRect))
			{
				disappearing = true;
				/*爆炸*/
				playDropAnimation();
			}
			else if (left->getPosition().x > right->getPosition().x)
			{
				disappearing = true;
				leftJumping = false;
				rightJumping = false;
				//计分
				Counter *counter = Counter::sharedCounter();
				(*counter)++;
				this->reCreateNewRole();
//			left->runAction(CCFadeOut::create(0.8f));
//			right->runAction(
//					CCSequence::createWithTwoActions(CCFadeOut::create(0.8f),
//							CCCallFunc::create(this,
//									callfunc_selector(
//											MainLayer::reCreateNewRole))));
			}
		}
	}

}
Example #23
0
/** 
 * 检查是否在区域里
 */
bool UILineValue::touchDown(float x,float y)
{
	CCPoint pos = ccp(x,y);
	pos = this->convertToNodeSpace(pos);
	nowTouchPoint = ccp(x,y);
	if (_back)
	{
		float width = _back->getContentSize().width * _back->getScaleX();
		float height = _back->getContentSize().height * _back->getScaleY();
		CCRect rect = CCRectMake(
			_back->getPosition().x ,
			_back->getPosition().y,
			width,
			height);
		if (rect.containsPoint(pos))
		{
			_touchIn = true;
			return true;
		}
	}
	return false;
}
Example #24
0
void Jugar::empujarPelota(JugadorGolpeaEvent* jg) {
	
	Bola       & b     = jg->bola;
	Jugador    & j     = jg->jugador;
	GolpeEvent * golpe = jg->golpe;
	int          id    = jg->id;
	
	int direccion = id == 1 ?   1 :  -1;
	int dirbola = b.vx == 0 ? 0 : b.vx > 0 ? 1 :  -1;
	bool pelotaEsGolpeable = (direccion == 0) || (direccion != dirbola);
	
	CCRect  area    = j.getHitArea();
	CCPoint posBola = b.getPosicion();
	
	if (pelotaEsGolpeable && area.containsPoint(posBola)) {
		b.t1 *= 0.95;
		
		CCSize size = CCDirector::sharedDirector()->getWinSize();
		b.a = -3*size.height/(b.t1 * b.t1);
		float distancia = size.width*(0.05 +(golpe->power-5.0)/3.0 * 0.3);
//		fminf(size.width*0.4, fmaxf(golpe->power*10, size.width* 0.03));
		b.trg = size.width/2 + direccion * distancia;
		b.dy  = posBola.y - b.flr;
		b.xo = posBola.x;
		b.yo = posBola.y;
		b.golpear();
		
//		b.velocidad.x = velx * direccion;
//		float vely = 500; //algun valor para que caiga dentro de la cancha
//		b.velocidad.y = vely;
		float bd = (b.trg - b.xo)*direccion;
		float spin = size.width * 0.3 * golpe->spin; // El spin
		spin = fmaxf(size.width * 0.90, spin+bd*2)-bd*2;
		spin = fmaxf(size.width * 0.05, spin+bd)-bd;
		b.spin = spin * direccion; // El spin depende de donde se le pega
		
		SimpleAudioEngine::sharedEngine()->playEffect("tennisserve.wav");
	}
}
Example #25
0
void HelloWorld::updateGame(float dt)
{
	CCArray *projectilesToDelete = new CCArray;
    CCObject* it = NULL;
    CCObject* jt = NULL;

	// for (it = _projectiles->begin(); it != _projectiles->end(); it++)
    CCARRAY_FOREACH(_projectiles, it)
	{
		CCSprite *projectile = dynamic_cast<CCSprite*>(it);
		CCRect projectileRect = CCRectMake(
			projectile->getPosition().x - (projectile->getContentSize().width/2),
			projectile->getPosition().y - (projectile->getContentSize().height/2),
			projectile->getContentSize().width,
			projectile->getContentSize().height);

		CCArray* targetsToDelete =new CCArray;

		// for (jt = _targets->begin(); jt != _targets->end(); jt++)
        CCARRAY_FOREACH(_targets, jt)
		{
			CCSprite *target = dynamic_cast<CCSprite*>(jt);
			CCRect targetRect = CCRectMake(
				target->getPosition().x - (target->getContentSize().width/2),
				target->getPosition().y - (target->getContentSize().height/2),
				target->getContentSize().width,
				target->getContentSize().height);

			// if (CCRect::CCRectIntersectsRect(projectileRect, targetRect))
            if (projectileRect.intersectsRect(targetRect))
			{
                _score += 7 * target->getPosition().x;
                sprintf(_score_buffer,"%05d",_score);
                _label_score->setString(_score_buffer);
                CCLOG("_score = %d", _score);
				targetsToDelete->addObject(target);
			}
		}
Example #26
0
void HelloWorld::updateGame(float dt)
{
	CCArray *projectilesToDelete = new CCArray;
    CCObject* it = NULL;
    CCObject* jt = NULL;

	// for (it = _projectiles->begin(); it != _projectiles->end(); it++)
    CCARRAY_FOREACH(_projectiles, it)
	{
		CCSprite *projectile = dynamic_cast<CCSprite*>(it);
		CCRect projectileRect = CCRectMake(
			projectile->getPosition().x - (projectile->getContentSize().width/2),
			projectile->getPosition().y - (projectile->getContentSize().height/2),
			projectile->getContentSize().width,
			projectile->getContentSize().height);

		CCArray* targetsToDelete =new CCArray;

		// for (jt = _targets->begin(); jt != _targets->end(); jt++)
        CCARRAY_FOREACH(_targets, jt)
		{
			CCSprite *target = dynamic_cast<CCSprite*>(jt);
			CCRect targetRect = CCRectMake(
				target->getPosition().x - (target->getContentSize().width/2),
				target->getPosition().y - (target->getContentSize().height/2),
				target->getContentSize().width,
				target->getContentSize().height);


            // 弾と敵の当たり判定
            if (projectileRect.intersectsRect(targetRect))
			{
				targetsToDelete->addObject(target);
                score++;
                CCString* strScore = CCString::createWithFormat("Score : %d",score);
                scoreLabel->setString(strScore->getCString());
			}
		}
Example #27
0
bool AllyUnit::onMovingToTarget( float dt )
{
	// let enemy stop running 
	// note: the pos is not the center point of collision rect!
	// 1. get distance color(collision) rect of ally

	//CCRect targetCollisionRect = enemy->getCollisionRect();
	if (!mPreTargetCollisionRect.equals(mTargetCollisionRect) )
	{

		CCRect CollisionRect = this->getCollisionRect();

		CCPoint destColorRectLeftTop;
		if(mTargetCollisionRect.getMidX() > CollisionRect.getMidX())
		{
			// move to left of the target
			destColorRectLeftTop.x = mTargetCollisionRect.getMinX() - mDefualtColorRect.size.width;
		}
		else
		{
			// move to right of the target
			destColorRectLeftTop.x = mTargetCollisionRect.getMaxX();
		}
		destColorRectLeftTop.y = mTargetCollisionRect.getMinY() + mDefualtColorRect.size.height;

		CCPoint destSpriteRectLeftTop = CCPoint(
			destColorRectLeftTop.x - mDefualtColorRect.origin.x,
			destColorRectLeftTop.y + mDefualtColorRect.origin.y
			);
		CCSize size = this->getContentSize();
		mDestinationPos = CCPoint(
			destSpriteRectLeftTop.x + size.width / 2,
			destSpriteRectLeftTop.y - size.height / 2 + rangedRand(0, 5)
			);
	}

	return onMoving(dt, mDestinationPos);
}
Example #28
0
void CAPageControl::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent)
{
    if (getBounds().containsPoint(convertToNodeSpace(pTouch->getLocation()))) {

//        m_currentPage++;
//        if (m_currentPage == m_numberOfPages) {
//            m_currentPage = 0;
//        }
//        if (!m_bDefersCurrentPageDisplay) {
//            updateCurrentPageDisplay();
//        }
//        
//        if (m_pTarget[CAControlEventTouchValueChanged] && m_selTouch[CAControlEventTouchValueChanged]) {
//            (m_pTarget[CAControlEventTouchValueChanged]->*m_selTouch[CAControlEventTouchValueChanged])(this, CCPointZero);
//        }

        // find touched dot
        float width = getBounds().size.width/m_numberOfPages;
        CCRect rect = getBounds();
        for (int i=0; i<m_numberOfPages; i++) {
            rect.size.width = width * i + width;
            if (rect.containsPoint(convertToNodeSpace(pTouch->getLocation()))) {
                if (m_currentPage != i) {
                    m_currentPage = i;

                    if (!m_bDefersCurrentPageDisplay) {
                        updateCurrentPageDisplay();
                    }
                    
                    if (m_pTarget[CAControlEventTouchValueChanged] && m_selTouch[CAControlEventTouchValueChanged]) {
                        (m_pTarget[CAControlEventTouchValueChanged]->*m_selTouch[CAControlEventTouchValueChanged])(this, CCPointZero);
                    }
                }
                break;
            }
        }
    }
}
Example #29
0
void Game2Scene::update(float dt)
{
	/*CCLabelTTF* label = (CCLabelTTF*)this->getChildByTag(1);
	CCString* str = CCString::createWithFormat("%d", this->m_EnemyMax);
	label->setString(str->getCString());
	*/
	///	あたり判定のチェック
	for (int i = 0; i < 100; i++)
	{
		CCSprite* spr = (CCSprite*)this->getChildByTag(i + 10);
		if (spr != nullptr)
		{		
			CCSprite* player = (CCSprite*)this->getChildByTag(4);
			//プレイヤーのあたり範囲
			CCRect playerRect = CCRectMake(
				player->getPosition().x - (player->getContentSize().width / 2),
				player->getPosition().y - (player->getContentSize().height / 2),
				player->getContentSize().width,
				player->getContentSize().height);

			if (spr == NULL) return;
			//敵のあたり範囲
			CCRect EnemyRect = CCRectMake(
				spr->getPosition().x - (spr->getContentSize().width ),
				spr->getPosition().y - (spr->getContentSize().height),
				spr->getContentSize().width,
				spr->getContentSize().height);
			//playerとEnemyの衝突判定でどう動く
			if (playerRect.intersectsRect(EnemyRect))
			{
				this->removeChild(spr, true);
				player->setTexture(CCTextureCache::sharedTextureCache()->addImage("monkey02.png"));

				this->scheduleOnce(schedule_selector(Game2Scene::eat), 0.1f);
			}
		}
	}
}
Example #30
0
CCMenuItem* NewMenuDevice::itemForTouch(CCTouch *touch) {
    CCPoint touchLocation = touch->getLocationInView();
    touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);
    if (m_pChildren && m_pChildren->count() > 0)
    {
        CCObject* pObject = NULL;
        CCARRAY_FOREACH(m_pChildren, pObject)
        {
            CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject);
            if (pChild && pChild->isVisible() && ((CCMenuItem*)pChild)->isEnabled())
            {
                if (dynamic_cast<NewMenuSpriteItem*>(pChild) != NULL){
                    CCPoint posiT = parent->getMap()->transMapToTiled(this->getPosition());
                    
                    CCPoint tiled = parent->getMap()->transMapToTiled(parent->getMap()->convertToNodeSpace(touchLocation));
                    //                    CCLog("posiTx:%f,posiTy:%f", posiT.x,posiT.y);
                    //                    CCLog("tiledX:%f,tiledY:%f", tiled.x,tiled.y);
                    //                    CCLog("pChildTiledSizeW:%f,pChildTiledSizeH:%f",pChildTiledSize.width,pChildTiledSize.height);
                    if(Mathlib::inBound(tiled.x, posiT.x+contentSizeByTiled.width/2, posiT.x-contentSizeByTiled.width/2) &&
                       Mathlib::inBound(tiled.y, posiT.y+contentSizeByTiled.height/2, posiT.y-contentSizeByTiled.height/2)) {
                        isMoved = true;
                        cacheLoc = this->getPosition();
                        ((NewCreateMap*)parent->getMap())->initTip(this->getPosition(), contentSizeByTiled.width);
                        ((NewCreateMap*)parent->getMap())->moveTemp  = this;
                        ((NewCreateMap*)parent->getMap())->cancelAllBuilding();
                        return (CCMenuItem*)pChild;
                    }
                } else {
                    CCPoint local = pChild->convertToNodeSpace(touchLocation);
                    CCRect r = ((CCMenuItem*)pChild)->rect();
                    r.origin = CCPointZero;
                    if (r.containsPoint(local))
                    {
                        return (CCMenuItem*)pChild;
                    }
                }
            }
        }