Ejemplo n.º 1
0
CCSprite* LevelScene::addMapBtnWith(int no, cocos2d::CCPoint pos, CCSpriteBatchNode* batch)
{
    CCSprite *map = NULL;
    CCSprite *lockSprite = NULL;
    CCLabelAtlas *mapNo = CCLabelAtlas::create("0123456789", "fonts_score_002-hd.png", 38, 44, '0');

    if (FruitCrush::shareSingleton()->canPlayMap(no)) {
        map = CCSprite::createWithTexture(batch->getTexture());
        map->setTag(no);
        //map->setScale(0.6);
        CCString* num = CCString::createWithFormat("%u", no);
        mapNo->setString(num->getCString());
        //mapNo->setColor(ccc3(242, 247, 240));
        mapNo->setAnchorPoint(ccp(0.5f,0.5f));
        mapNo->setPosition(ccp(map->boundingBox().size.width/2, map->boundingBox().size.height/2));
        map->addChild(mapNo);
        //this->addChild(mapNo);
    }
    else
    {
        
    }
    
    map->setPosition(pos);
    map->setScale(0.8);
    this->addChild(map);
    return map;
    
}
Ejemplo n.º 2
0
CCSprite* Objects2dFactory::image(CCNode* scene, string imagePath, float positionX, float positionY, float width, float height, AlignX alignX, 
	AlignY alignY, int zOrder, void* argument)
{
	// Check arguments validity
	if(scene == NULL)
		return NULL;

	// Create an image
	CCSprite* image = CCSprite::create(imagePath.c_str());
    if(!image)
		return NULL;

    // Place the image in the given position
    image->setPosition(ccp(positionX, positionY));
	
	// Set anchor
	image->setAnchorPoint(ccp(Constants::getAnchorValue(alignX), Constants::getAnchorValue(alignY)));
	
	// Set size
	float imageWidth = image->boundingBox().size.width;
    image->setScaleX(width / imageWidth);
	float imageHeight = image->boundingBox().size.height;
    image->setScaleY(height / imageHeight);

	// Set argument as user data
	if (argument != NULL)
		image->setUserData(argument);

	// Add menu to the scene
	scene->addChild(image, zOrder);

	return image;
}
Ejemplo n.º 3
0
bool OptionLayer::init() {
    if (!CCLayer::init()) {
        return false;
    }

    _back = CCSprite::create("back.png");
    _back->setPosition(ccp(24 + 40, 800 - 56.5 + 15));
    this->addChild(_back);

    CCSprite * mode = CCSprite::create("mode.png");
    mode->setPosition(ccp(132 + 111, 800 - 103 - 19.5));
    this->addChild(mode);

    CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create("dotted_line.png");
    int dottedLineY[3] = {313, 420, 539};
    for (int i = 0; i < 3; i++) {
        CCSprite * dotLine = CCSprite::createWithTexture(batchNode->getTexture());
        dotLine->setPosition(ccp(27 + 210.5, 800 - dottedLineY[i] - 1.5));
        this->addChild(dotLine);
    }

    _switchIndex = -1;
    _switches[0] = &Settings::showConflictedDigit;
    _switches[1] = &Settings::musicEnabled;
    _switches[2] = &Settings::soundEnabled;
    _switches[3] = &Settings::preventSleeping;
    _switches[4] = &Settings::showTimer;
    _switches[5] = &Settings::autoHighLight;
    _switches[6] = &Settings::autoRemoveNotes;
    _switches[7] = &Settings::removeCompleteDigits;

    CCSpriteBatchNode* maskBatchNode = CCSpriteBatchNode::create("mask.png");
    CCSpriteBatchNode* switchBatch = CCSpriteBatchNode::create("switch.png");
    _switchButtons = CCArray::createWithCapacity(7);
    _switchButtons->retain();
    char opLabel[10];
    int opLabelY[8] = {271, 332, 379, 445, 492, 566, 612, 657};
    for(int i = 0; i < 8; i++) {
        sprintf(opLabel, "op%d.png", i);
        CCSprite * label = CCSprite::create(opLabel);
        label->setPosition(ccp(25 + label->boundingBox().size.width / 2,
                               800 - opLabelY[i] - label->boundingBox().size.height / 2));
        this->addChild(label);

        CCSprite * stencil = CCSprite::createWithTexture(maskBatchNode->getTexture());
        stencil->setPosition(ccp(380 + 39, 800 - opLabelY[i] - label->boundingBox().size.height / 2));
        CCClippingNode * cliper = CCClippingNode::create(stencil);
        cliper->setAlphaThreshold(0);
        CCSprite * switchButton = CCSprite::createWithTexture(switchBatch->getTexture());
        switchButton->setPosition(ccp(*(_switches[i]) ? 394 + 49 : 394, 800 - opLabelY[i] - label->boundingBox().size.height / 2));
        _switchButtons->addObject(switchButton);
        cliper->addChild(switchButton);
        this->addChild(cliper);
    }

    this->setTouchEnabled(true);
    this->setKeypadEnabled(true);

    return true;
}
Ejemplo n.º 4
0
void NovelScene::makeActorImage(const char* imageFilePath, int dict)
{
    int dictTag = dict + kTag_ActorDict;
        
    CCSprite* actor = CCSprite::create(imageFilePath);
    actor->setScale(0.75);
        
    removeActorImage(dict);
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCPoint point = CCPointZero;
    if (dictTag == kTag_ActorDictLeft)
    {
        point = ccp(actor->boundingBox().size.width * 0.5, actor->boundingBox().size.height * 0.5);
        actor->setFlipX(true);
    }
    else if (dictTag == kTag_ActorDictCenter)
    {     
    }
    else if (dictTag == kTag_ActorDictRight)
    {
        point = ccp(winSize.width - actor->boundingBox().size.width * 0.5, actor->boundingBox().size.height * 0.5);
    }
    actor->setPosition(point);    
    this->addChild(actor, kZOrder_Actor, dictTag);
}
void TextureAtlasEncryptionDemo::onEnter()
{
    CCLayer::onEnter();
    
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 28);
    label->setPosition( ccp(s.width/2, s.height * 0.75f) );
    this->addChild(label, 1);
    
    std::string strSubtitle = subtitle();
    if(strSubtitle.empty() == false)
    {
        CCLabelTTF* subLabel = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16);
        subLabel->setPosition( ccp(s.width/2, s.height-80) );
        this->addChild(subLabel, 1);
    }
    
    // Load the non-encrypted atlas
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Images/nonencryptedAtlas.plist", "Images/nonencryptedAtlas.pvr.ccz");
    
    // Create a sprite from the non-encrypted atlas
    CCSprite *nonencryptedSprite = CCSprite::createWithSpriteFrameName("Icon.png");
    nonencryptedSprite->setPosition(ccp(s.width * 0.25f, s.height * 0.5f));
    this->addChild(nonencryptedSprite);
    
    CCLabelTTF* nonencryptedSpriteLabel = CCLabelTTF::create("non-encrypted", "Arial", 28);
    nonencryptedSpriteLabel->setPosition(ccp(s.width * 0.25f, nonencryptedSprite->boundingBox().getMinY() - nonencryptedSprite->getContentSize().height/2));
    this->addChild(nonencryptedSpriteLabel, 1);
    
    // Load the encrypted atlas
    // 1) Set the encryption keys or step 2 will fail
    // In this case the encryption key 0xaaaaaaaabbbbbbbbccccccccdddddddd is
    // split into four parts. See the header docs for more information.
    ZipUtils::ccSetPvrEncryptionKeyPart(0, 0xaaaaaaaa);
    ZipUtils::ccSetPvrEncryptionKeyPart(1, 0xbbbbbbbb);
    ZipUtils::ccSetPvrEncryptionKeyPart(2, 0xcccccccc);
    ZipUtils::ccSetPvrEncryptionKeyPart(3, 0xdddddddd);
    
    // Alternatively, you can call the function that accepts the key in a single
    // function call.
    // This is slightly less secure because the entire key is more easily
    // found in the compiled source. See the header docs for more information.
    // ZipUtils::ccSetPvrEncryptionKey(0xaaaaaaaa, 0xbbbbbbbb, 0xcccccccc, 0xdddddddd);

    // 2) Load the encrypted atlas
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Images/encryptedAtlas.plist", "Images/encryptedAtlas.pvr.ccz");
    
    // 3) Create a sprite from the encrypted atlas
    CCSprite *encryptedSprite = CCSprite::createWithSpriteFrameName("powered.png");
    encryptedSprite->setPosition(ccp(s.width * 0.75f, s.height * 0.5f));
    this->addChild(encryptedSprite);
    
    CCLabelTTF* encryptedSpriteLabel = CCLabelTTF::create("encrypted", "Arial", 28);
    encryptedSpriteLabel->setPosition(ccp(s.width * 0.75f, encryptedSprite->boundingBox().getMinY() - encryptedSpriteLabel->getContentSize().height/2));
    this->addChild(encryptedSpriteLabel, 1);
}
Ejemplo n.º 6
0
void StoreAScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img) {
	GameMenuItem *pChooseItem = GameMenuItem::itemWithLabel(
		CCSprite::create("button.png"),
					this,
					menu_selector(StoreAScene::menuChooseCallback));

	string itemId = itemIdFromTag(tag);
	
	// TODO: exception handling ..
    string nameS = cocos2dx_StoreInfo::getGoodName(itemId.c_str());
	string infoS = cocos2dx_StoreInfo::getGoodDescription(itemId.c_str());
	int price = cocos2dx_StoreInfo::getGoodPriceForCurrency(itemId.c_str(), "currency_muffin");
	int balance = 0;
	const char * name = nameS.c_str();
	const char * info = infoS.c_str();
	
	float yOffset = - 200;

	pChooseItem->setPosition(ccp(origin.x + visibleSize.width/2, yOffset + origin.y + visibleSize.height - 100 - (tag * pChooseItem->boundingBox().size.height)));
	pChooseItem->setTag(tag);


	CCSprite* pSpritePic = CCSprite::create(img);
	pSpritePic->setPosition(ccp(pSpritePic->boundingBox().size.width/2 + 20, pChooseItem->boundingBox().size.height/2));
	pChooseItem->addChild(pSpritePic, 0);


	CCLabelTTF* pLabelName = CCLabelTTF::create(name, "GoodDog.otf", 44);
	pLabelName->setColor(ccc3(0,0,0));
	pLabelName->setPosition(ccp(pSpritePic->getPositionX() + (pSpritePic->boundingBox().size.width / 2) + (pLabelName->boundingBox().size.width / 2) + 20 , pChooseItem->boundingBox().size.height/2));
	pChooseItem->addChild(pLabelName);


	CCLabelTTF* pLabelInfo = CCLabelTTF::create(info, "GoodDog.otf", 20);
	pLabelInfo->setColor(ccc3(50,50,50));
	pLabelInfo->setPosition(ccp(pSpritePic->getPositionX() + (pSpritePic->boundingBox().size.width / 2) + (pLabelInfo->boundingBox().size.width / 2) + 20 , -50 + (pChooseItem->boundingBox().size.height/2)));
	pChooseItem->addChild(pLabelInfo);


	CCLabelTTF* pLabelClickToBuy = CCLabelTTF::create("Click to Buy", "GoodDog.otf", 24);
	pLabelClickToBuy->setColor(ccc3(0,255,255));
	pLabelClickToBuy->setPosition(ccp(pChooseItem->boundingBox().size.width - (pLabelClickToBuy->boundingBox().size.width / 2) - 20 , 60 + pChooseItem->boundingBox().size.height/2));
	pChooseItem->addChild(pLabelClickToBuy);

	char buffer[512];

	snprintf(buffer, sizeof(buffer), "price: %d blanace: %d",  price, balance);

	goodsPriceBalanceLabels[tag] = CCLabelTTF::create(buffer, "GoodDog.otf", 24);
	goodsPriceBalanceLabels[tag]->setColor(ccc3(0,255,255));
	goodsPriceBalanceLabels[tag]->setPosition(ccp(pChooseItem->boundingBox().size.width - (goodsPriceBalanceLabels[tag]->boundingBox().size.width / 2) - 20 , 60));
	pChooseItem->addChild(goodsPriceBalanceLabels[tag]);

	menu->addChild(pChooseItem, 1);
	
	setPriceBalanceLabel(itemId.c_str());
}
Ejemplo n.º 7
0
void HoldOnGame::checkCollision(){
    //小球与障碍物
    CCRect ballRect = playerBall->boundingBox();
    CCRect rect = CCRect(ballRect.origin.x + KBallOffset, ballRect.origin.y + KBallOffset,
                         ballRect.size.width - KBallOffset * 2, ballRect.size.height - KBallOffset * 2);
    for (int i = KBodyTypeRectangleVer; i <= KBodyTypeSquare; i++) {
        CCSprite* sprite = (CCSprite*)gameLayer->getChildByTag(i);
        if (rect.intersectsRect(sprite->boundingBox())) {
            bool over = true;
            
            if (sprite->getTag() == KBodyTypeTriangle) {
                CCRect sRect = sprite->boundingBox();
                CCRect rect1 = CCRect(sRect.origin.x + (sRect.size.width * 0.25) / 2 + KBallOffset, sRect.origin.y,
                                      sRect.size.width * 0.75 - KBallOffset * 2, sRect.size.height * 0.25);
                if (!rect.intersectsRect(rect1)) {
                    rect1 = CCRect(sRect.origin.x + sRect.size.width * 0.25 + KBallOffset, sRect.origin.y + sRect.size.height * 0.25,
                                   sRect.size.width * 0.5 - KBallOffset * 2, sRect.size.height * 0.25);
                    if (!rect.intersectsRect(rect1)) {
                        rect1 = CCRect(sRect.origin.x + sRect.size.width * 3 / 8 + KBallOffset, sRect.origin.y + sRect.size.height * 0.5,
                                       sRect.size.width * 0.25 - KBallOffset* 2, sRect.size.height * 0.25);
                        if (!rect.intersectsRect(rect1)) {
                            rect1 = CCRect(sRect.origin.x + sRect.size.width * 0.45, sRect.origin.y + sRect.size.height * 0.75,
                                           sRect.size.width * 0.1, sRect.size.height * 0.15);
                            if (!rect.intersectsRect(rect1)) {
                                over = false;
                            } else {
                                CCLOG("44444 rect1 = (%.1f, %.1f, %.1f, %.1f)", rect1.origin.x, rect1.origin.y, rect1.size.width, rect1.size.height);
                            }
                        } else {
                            CCLOG("333333 rect1 = (%.1f, %.1f, %.1f, %.1f)", rect1.origin.x, rect1.origin.y, rect1.size.width, rect1.size.height);
                        }
                    } else {
                        CCLOG("22222222 rect1 = (%.1f, %.1f, %.1f, %.1f)", rect1.origin.x, rect1.origin.y, rect1.size.width, rect1.size.height);
                    }
                } else {
                    CCLOG("1111111 rect1 = (%.1f, %.1f, %.1f, %.1f)", rect1.origin.x, rect1.origin.y, rect1.size.width, rect1.size.height);
                }
                
//                if (over) {
//                    CCLOG("rect = (%.1f, %.1f, %.1f, %.1f)", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
//                    CCLOG("sRect = (%.1f, %.1f, %.1f, %.1f)", sRect.origin.x, sRect.origin.y, sRect.size.width, sRect.size.height);
//                    CCLOG("game over");
////                    this->gameOver();
//                    break;
//                }
            }
            
            if (over) {
                this->gameOver();
                break;
            }
        }
    }
}
Ejemplo n.º 8
0
void HelloWorld::update(float dt) {

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	float maxX = winSize.width - _ship->getContentSize().width / 2;
	float minX = _ship->getContentSize().width / 2;

	float diff = (_shipPointsPerSecX * dt);
	float newX = _ship->getPosition().x + diff;

	if (_iEnemies == 0) {
		endScene(NEXT);
	}

	newX = MIN(MAX(newX, _minX), _maxX);
	_ship->setPosition(ccp(newX, _ship->getPosition().y));

	// Enemies collision
	CCArray * itAster, itLaser;
	CCObject* item = NULL;
	CCObject* laser_item = NULL;
	CCObject* enemy_laser_item = NULL;
	CCARRAY_FOREACH(_aliens, item)
	{
		CCSprite *enemy = dynamic_cast<CCSprite *>(item);
		if (!enemy->isVisible())
			continue;

		CCARRAY_FOREACH(_shipLasers, laser_item)
		{
			CCSprite *laser = dynamic_cast<CCSprite *>(laser_item);
			if (!laser->isVisible())
				continue;
			CCRect rect = laser->boundingBox();
			if (rect.intersectsRect(enemy->boundingBox())) {
				laser->setVisible(false);
				enemy->setVisible(false);
				_iEnemies--;
				score += level * 10;
				sprintf(points, "Lives: %d Level: %d Score: %d", lives, level,
						score);
				pScoreLabel->setString(points);
				SimpleAudioEngine::sharedEngine()->playEffect(
						"explosion_large.wav");
				//_aliens->removeObject(enemy, false);
				continue;
			}

		}
Ejemplo n.º 9
0
void TargetLayer::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
    CCLog("Game State : %d", ((GameScene*)this->getParent())->gameState);
    if ((((GameScene*)this->getParent())->gameState == GAME_ANNOUNCE_LETTER) || ((GameScene*)this->getParent())->gameState == GAME_HIDE) {
        CCTouch* fingerOne = (CCTouch*)pTouches->anyObject();
        CCPoint pointOne = CCDirector::sharedDirector()->convertToUI(fingerOne->getLocationInView());
        CCPoint location = this->convertToNodeSpace(pointOne);
        
        for (int index = 0; index < targets->count(); index++) {
            CCSprite* target = (CCSprite*)targets->objectAtIndex(index);
            
            // Get the Box of the sprite
            CCRect rect = target->boundingBox();
            
            if (rect.containsPoint(location)) {
                
                if (((GameScene*)this->getParent())->gameState == GAME_HIDE) {
                    this->showLetters();
                }
                
                CCLog("Shooted %d", index);
                this->doShoot(target);
                break;
            }
        }
    }
}
Ejemplo n.º 10
0
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;

}
Ejemplo n.º 11
0
void GameLayer::ccTouchesBegan(CCSet* touches, CCEvent* event) {
    
    
    
    CCTouch *touch = (CCTouch *)touches->anyObject();
    
    if (touch) {
        
	    CCPoint tap = touch->getLocation();
        CCRect boundary;
        //handle button touches
        CCSprite * button;
        CCSprite * buttonPress;
        
        for (int i = 0; i < 5; i++) {
            button = (CCSprite *) _buttons->objectAtIndex(i);
            if (!button->isVisible()) continue;
            boundary = button->boundingBox();
            
            if (boundary.containsPoint(tap)) {
                buttonPress = (CCSprite *) button->getChildByTag(kSpriteBtnOn);
                buttonPress->setVisible(true);
                return;
            }
        }
    }
    
}
Ejemplo n.º 12
0
int TombLayer::deleteSpriteFunc(CCPoint tpoint) {
    // イテレータの取得
	std::list <CCSprite *>::iterator it = enemySpList.begin();
	while (it != enemySpList.end()) {
		// spriteの取得
		CCSprite *pSprite = *it;

        bool isHit=false;
        //タッチ座標の下にspがいるか
        CCRect _rect = pSprite->boundingBox();
        if(_rect.containsPoint(tpoint)){
            isHit=true;
        }
        
        if (isHit) {
            int size=enemySpList.size();
            i_enemyCnt=size-1;
            
            CCLOG("deleteEnemy i_enemyCnt=%d",i_enemyCnt);
            pSprite->stopAllActions();
            // spriteのリストから削除&削除した要素以降のイテレータの取得
			it = enemySpList.erase(it);
            
            //敵の種類によって消すアニメーション
            createEnemydied(pSprite);
            return PT_ENEMY;
            break;
        }else{
            it++;
        }
        
    }//end while

    return 0;
}
Ejemplo n.º 13
0
bool HSPlayCard::init()
{
    if (!CCNodeRGBA::init()) return false;
    
    // Create frame.
    CCSprite *frame = HS_CREATE_SPRITE(HS_RES_IMG("card_frame"));
    frame->setScale(1.05f);
    frame->setColor(ccc3(200, 200, 200));
    frame->setOpacity(226);
    frame->setTag(TAG_FRAME);
    this->addChild(frame);
    
    // Create text.
    CCLabelTTF *text = CCLabelTTF::create("Now Loading...", "Helvetica", 24.0f,
                                          CCSizeMake(frame->getContentSize().width * 0.95f,
                                                     frame->getContentSize().height * 0.95f),
                                          kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop);
    text->setTag(TAG_MSG);
    this->addChild(text);
    
    // Setup properties.
    this->setContentSize(frame->boundingBox().size);
    
    m_isCompleted = false;
    m_isUpdated = false;
    
    return true;
}
bool UIWidgetAddNodeTest::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Widget Add Node");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the ui node container
        UIWidget* widget = UIWidget::create();
        widget->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(widget);
        
        CCSprite* sprite = CCSprite::create("cocosui/ccicon.png");
        sprite->setPosition(ccp(0, sprite->boundingBox().size.height / 4));
        widget->addNode(sprite);
        
        return true;
    }
    return false;
}
Ejemplo n.º 15
0
//use a new meteor from the pool
void GameLayer::resetMeteor(void) {
    if (_fallingObjects->count() > 30) {
        return;
    }
    
    CCSprite * meteor = (CCSprite *) _meteorPool->objectAtIndex(_meteorPoolIndex);
    _meteorPoolIndex++;
    if (_meteorPoolIndex == _meteorPool->count()) {
        _meteorPoolIndex = 0;
    }
    
    int meteor_x = rand() % (int) (_screenSize.width * 0.8f) + _screenSize.width * 0.1f;
    int meteor_target_x = rand() % (int) (_screenSize.width * 0.8f) + _screenSize.width * 0.1f;
    
    meteor->stopAllActions();
    meteor->setPosition(ccp(meteor_x, _screenSize.height + meteor->boundingBox().size.height * 0.5));
    
    CCActionInterval * rotate = CCRotateBy::create(0.5f, -90);
    CCAction * repeatRotate = CCRepeatForever::create(rotate);
    CCFiniteTimeAction * sequence = CCSequence::create(CCMoveTo::create(_meteorSpeed, ccp(meteor_target_x, _screenSize.height * 0.15f)), CCCallFuncN::create(this, callfuncN_selector(GameLayer::fallingObjectDone)), NULL);
    
    meteor->setVisible(true);
    meteor->runAction(repeatRotate);
    meteor->runAction(sequence);
    _fallingObjects->addObject(meteor);
}
Ejemplo n.º 16
0
void HelloWorld::update( float dt )
{
    CCArray* projectilesToDelete = CCArray::create();

    CCObject* pObject = NULL;
    CCObject* pObject2 = NULL;

    CCARRAY_FOREACH(_projectiles, pObject)
    {
        CCSprite* projectile = (CCSprite*)pObject;

        bool monsterHit = false;
        CCArray* monstersToDelete = CCArray::create();

        CCARRAY_FOREACH(_monsters, pObject2)
        {
            Monster* monster = (Monster*)pObject2;
            if (CCRect::CCRectIntersectsRect(projectile->boundingBox(), monster->boundingBox()))
            {
                monsterHit = true;
                monster->setHp(monster->getHp() - 1);
                if (monster->getHp() <= 0)
                {
                    monstersToDelete->addObject(monster);
                }
                break;
            }
        }
Ejemplo n.º 17
0
bool
WSGameBackGroundLayer::initWithScene(WSGameScene *scene)
{
    if (CCLayer::init())
    {
        
        CCLayerColor* whiteBg = CCLayerColor::create(ccc4(255, 255, 255, 255), 500, 350);
        whiteBg->setAnchorPoint(ccp(0, 0));
        whiteBg->setPosition(ccp(320, 170));
        this->addChild(whiteBg);
        
        WSMap* map = scene->getGameCore()->getGameMap();
        
        for (int i=0; i<map->getHeight(); i++) {
            for (int j=0; j<map->getWidth(); j++) {
                if (map->getMapNodeByXY(j, i) == kEdge)
                {
                    CCSprite* sprite = CCSprite::create("edge.png");
                    sprite->setAnchorPoint(ccp(0, 0));
                    sprite->setPosition(ccp(320+ j*sprite->boundingBox().size.width, 170 + (map->getHeight()-i-1)*sprite->boundingBox().size.height));
                    this->addChild(sprite);
                }
            }
        }

        return true;
    }
    return false;
}
Ejemplo n.º 18
0
void OptionLayer::ccTouchesBegan(CCSet* pTouches, CCEvent* event) {
    CCSetIterator i;
    CCTouch * touch;
    CCPoint tap;

    for (i = pTouches->begin(); i != pTouches->end(); i++) {
        touch = (CCTouch *) (*i);

        if (touch) {
            tap = touch->getLocation();

            if (_back->boundingBox().containsPoint(tap)) {
                _back->setPositionY(800 - 56.5);
            } else {
                for(int i = 0; i < 7; i++) {
                    CCSprite * button = (CCSprite *)_switchButtons->objectAtIndex(i);
                    if(button->boundingBox().containsPoint(tap)) {
                        _switchIndex = i;
                        _tapX = tap.x;
                        break;
                    }
                }
            }
        }
    }
}
Ejemplo n.º 19
0
//抬起事件
bool HRocker::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
	CCPoint point = pTouch->getLocation();
	CCSprite *rocker = (CCSprite *)this->getChildByTag(tag_rocker);
	if (rocker->boundingBox().containsPoint(point))
		isCanMove = true;
	return true;
}
Ejemplo n.º 20
0
CCSprite* MessageLayer::hitTest(const cocos2d::CCPoint &localPos) {
    CCSprite* node = NULL;
    if(cancelButtonVisibled_) {
        CCSprite* cancelButton = static_cast<CCSprite*>(getChildByTag(kTagCancelButton)); 
        if(CCRect::CCRectContainsPoint(cancelButton->boundingBox(), localPos))
            node = cancelButton;
    }
    return node;
}
Ejemplo n.º 21
0
CCTableViewCell * equipmentRoom:: tableCellAtIndex (CCTableView * table, unsigned int idx)
{
    CCString* string;
    char tc_label[30];
    int contentID = 0;
    
        sprintf(tc_label,"%s", equipmentList[idx]->m_name.c_str());
        //string = CCString::create(m_buttons[idx].label);
        string = CCString::create(tc_label);
        
        //cout << idx << "script name = " << string->getCString() << endl;
       //cout << "author1 = " << scriptVector[idx]->authorNames[0] << endl;
    
   
    CCTableViewCell *cell;// = table->dequeueCell();
    //if (!cell) {
        cell = new CustomTableViewCell();
        cell->autorelease();
        CCSprite *sprite = CCSprite::create("grey_cell.png");
        sprite->setAnchorPoint(CCPointZero);
        sprite->setPosition(ccp(0, 0));
        sprite->setScaleX(sfx);
        sprite->setScaleY(sfy);
        sprite->setTag(4);
        cell->addChild(sprite);
        cell->setObjectID(idx);
        CCLabelTTF *label = CCLabelTTF::create(string->getCString(), "Helvetica", 12.0);
        label->setPosition(ccp(sprite->boundingBox().size.width/2, sprite->boundingBox().size.height/2));
		label->setAnchorPoint(ccp(0.5, 0.5));
        //label->setPosition(CCPointZero);
		//label->setAnchorPoint(CCPointZero);
        label->setTag(123);
        cell->addChild(label);
    //}
    /*else
    {
        CCLabelTTF *label = (CCLabelTTF*)cell->getChildByTag(123);
        label->setString(string->getCString());
    }*/
    cout << "cell # " << idx << "title = " << string->getCString() << endl;
    return cell;
    
    
}
Ejemplo n.º 22
0
void LayerProp::createBomb(float dt)
{
	CCSprite *prop = CCSprite::createWithSpriteFrameName("ufo2.png");
	prop->setTag(12);
	float randX = rand()%(int)(getSize().width
		- prop->getContentSize().width) + prop->boundingBox().size.width/2;
	prop->setPosition(ccp(randX, 800));
	propBatch->addChild(prop);
	propArray->addObject(prop);
}
Ejemplo n.º 23
0
// Initialize the menu items, background, and overall setup of the main menu
//
// return - false if there was an error in initializing, true otherwise
bool MainMenu::init()
{
    CCLabelTTF*      labelSinglePlayer; // the text for single player menu item
    CCLabelTTF*      labelMultiplayer;  // the text for multiplayer menu item
    CCLabelTTF*      labelOptions;      // the text for options menu item
    CCMenuItemLabel* itemSinglePlayer;  // menu item for starting single player game
    CCMenuItemLabel* itemMultiplayer;   // menu item for starting multiplayer game
    CCMenuItemLabel* itemOptions;       // menu item for opening up options
    CCMenu*          menu;              // menu to contain the menu items

    CCSize           size;              // the size of the window
    CCSprite*        background;        // the background splashscreen

    if(!CCLayer::init())
    {
        return false;
    }

    // get the window size from the director
    size = CCDirector::sharedDirector()->getWinSize();

    // create the text for the menu items
    labelSinglePlayer = CCLabelTTF::create("Start Single Player", FONT_STYLE, Font_Size_Default);
    labelMultiplayer  = CCLabelTTF::create("Start Multiplayer", FONT_STYLE, Font_Size_Default);
    labelOptions      = CCLabelTTF::create("Options", FONT_STYLE, Font_Size_Default);

    // add shadows to the labels, so they will be easier to read against the background
    labelSinglePlayer->enableShadow(FONT_SHADOW_OFFSET, FONT_SHADOW_OPACITY, FONT_SHADOW_BLUR);
    labelMultiplayer->enableShadow(FONT_SHADOW_OFFSET, FONT_SHADOW_OPACITY, FONT_SHADOW_BLUR);
    labelOptions->enableShadow(FONT_SHADOW_OFFSET, FONT_SHADOW_OPACITY, FONT_SHADOW_BLUR);

    // create the items for the menu
    itemSinglePlayer = CCMenuItemLabel::create(labelSinglePlayer, this, menu_selector(MainMenu::HandleSinglePlayerPressed));
    itemMultiplayer  = CCMenuItemLabel::create(labelMultiplayer, this, menu_selector(MainMenu::HandleMultiplayerPressed));
    itemOptions      = CCMenuItemLabel::create(labelOptions, this, menu_selector(MainMenu::HandleOptionsPressed));

    // set the color of the menu items
    itemSinglePlayer->setColor(MENU_COLOR);
    itemMultiplayer->setColor(MENU_COLOR);
    itemOptions->setColor(MENU_COLOR);

    // create menu to contain the menu items
    menu = CCMenu::create(itemSinglePlayer, itemMultiplayer, itemOptions, NULL);
    menu->alignItemsVerticallyWithPadding(MENU_ITEM_PADDING);
    menu->setPosition(size.width * POS_HALF_SCREEN, size.height * POS_HALF_SCREEN);
    addChild(menu, 1);

    // add splash screen as a sprite on the center of the screen
    background = CCSprite::create(BACKGROUND_IMAGE);
    background->setScale(size.height / background->boundingBox().size.height);
    background->setPosition( ccp(size.width * POS_HALF_SCREEN, size.height * POS_HALF_SCREEN) );
    addChild(background, 0);

    return true;
}
Ejemplo n.º 24
0
void HelloWorld::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){
    
    // to find witch sprite is choosed 
    CCSprite *pget = (CCSprite*)this->getChildByTag(GETTAG);
    CCSprite *pok  = (CCSprite*)this->getChildByTag(OKTAG);
    
    CCPoint touchPoint=convertTouchToNodeSpace(pTouch);
    
    
    if (pget->boundingBox().containsPoint(touchPoint)) {
        printf("get touch!\n");
        this->getNetworks();
    }
    
    if (pok->boundingBox().containsPoint(touchPoint)) {
        printf("ok touch!\n");
        this->okNetworks();
    }
    
}
Ejemplo n.º 25
0
	// draw
	void CCSpriteBatchNode::draw(void)
	{
		// Optimization: Fast Dispatch	
		if (m_pobTextureAtlas->getTotalQuads() == 0)
		{
			return;
		}

		if (m_pobDescendants && m_pobDescendants->count() > 0)
		{
			CCSprite *pSprite;
			NSMutableArray<CCSprite*>::NSMutableArrayIterator iter;
			for (iter = m_pobDescendants->begin(); iter != m_pobDescendants->end(); ++iter)
			{
				pSprite = *iter;

				if (! pSprite)
				{
					break;
				}

                // fast dispatch
				pSprite->updateTransform();


#if CC_SPRITESHEET_DEBUG_DRAW
				// issue #528
				CGRect rect = pSprite->boundingBox();
				CGPoint vertices[4]={
					ccp(rect.origin.x,rect.origin.y),
					ccp(rect.origin.x+rect.size.width,rect.origin.y),
					ccp(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height),
					ccp(rect.origin.x,rect.origin.y+rect.size.height),
				};
				ccDrawPoly(vertices, 4, true);
#endif // CC_SPRITESHEET_DEBUG_DRAW
			}
		}

		// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
		// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
		// Unneeded states: -
		bool newBlend = m_blendFunc.src != CC_BLEND_SRC || m_blendFunc.dst != CC_BLEND_DST;
		if (newBlend)
		{
			glBlendFunc(m_blendFunc.src, m_blendFunc.dst);
		}

		m_pobTextureAtlas->drawQuads();
		if (newBlend)
		{
			glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
		}
	}
Ejemplo n.º 26
0
void GameRoot::collisionCheck() {
	// keep array safe
	cleanupArray->removeAllObjects();

	const CCRect &rect = figure->boundingBox();
	CCObject *obj;
	CCSprite *child;

	CCARRAY_FOREACH(getChildren(), obj) {
		child = dynamic_cast<CCSprite *> (obj);
		if (child && child != figure) {
			if (child->getPositionX() < -child->boundingBox().size.width / 2) {
				cleanupArray->addObject(child);
			} else {
				// check for collision
				if (rect.intersectsRect(child->boundingBox())) {
					processCollision(figure, child);
				}
			}
		}
	}
Ejemplo n.º 27
0
CCSprite* RegisterLayer::hitTestWithButton(const cocos2d::CCPoint &localPos)
{
    CCSprite* node = NULL;
    
    CCSprite* startButton = static_cast<CCSprite*>(getChildByTag(kTagStartButton));
    CC_ASSERT(startButton);
    
    if(CCRect::CCRectContainsPoint(startButton->boundingBox(), localPos))
        node = startButton;
    
    return node;
}
Ejemplo n.º 28
0
CCSprite* Objects2dFactory::rectangle(CCNode* scene, ccColor3B color, float positionX, float positionY, float width, float height, AlignX alignX, AlignY alignY, 
	GLubyte opacity, int zOrder, void* argument)
{
	// Check arguments validity
	if(scene == NULL)
		return NULL;

	// Create an image
	CCSprite* image = CCSprite::create("TopQXResources/white.png");
    if(!image)
		return NULL;

	// Set color
	image->setColor(color);

	// Set opacity
	image->setOpacity(opacity);

    // Place the image in the given position
    image->setPosition(ccp(positionX, positionY));
	
	// Set anchor
	image->setAnchorPoint(ccp(Constants::getAnchorValue(alignX), Constants::getAnchorValue(alignY)));
	
	// Set size
	float imageWidth = image->boundingBox().size.width;
    image->setScaleX(width / imageWidth);
	float imageHeight = image->boundingBox().size.height;
    image->setScaleY(height / imageHeight);

	// Set argument as user data
	if (argument != NULL)
		image->setUserData(argument);

	// Add menu to the scene
	scene->addChild(image, zOrder);

	return image;
}
Ejemplo n.º 29
0
// 碰撞检测
void GameScene::checkCollision()
{
    CCSprite *bird =(CCSprite*)this->getChildByTag(TAG_BIRD);
    CCRect birdRect =bird->boundingBox();
    if (bird->getPositionY()<ground1->boundingBox().size.height)
    {
        gameState=GameOver;
        score=0;
        this->birdFallAction();
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/lh_hit.ogg");
        return;
    }
    for(int i=0;i<hose->hoseList->count();i++)
    {
        CCSprite *hoseSprite =(CCSprite*)hose->hoseList->objectAtIndex(i);
        CCRect hoseRect =hoseSprite->boundingBox();
        if (birdRect.intersectsRect(hoseRect))
        {
            gameState=GameOver;
            score=0;
            this->birdFallAction();
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/lh_hit.ogg");
            break;
        }
        // 更新分数
        int pPosX =hoseSprite->getPositionX()+hoseSprite->getContentSize().width*hoseSprite->getScaleX();
        int birdX =bird->getPositionX()-bird->getContentSize().width*bird->getScaleX();
        if (pPosX==birdX)
        {
            score++;
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/lh_point.ogg");
            CCLabelBMFont* scoreSprite =(CCLabelBMFont*)this->getChildByTag(TAG_SCORE);
            CCString *strScore =CCString::createWithFormat("%d",score/2);
            scoreSprite->setString(strScore->m_sString.c_str());
        }
    }
    updatehightestRecord();
}
Ejemplo n.º 30
0
void World::showLevel()
{
    /*添加显示板*/
    CCSprite* sprite = CCSprite::create("displayLevel.png");
    addChild(sprite);
    CCLabelBMFont* label = CCLabelBMFont::create("Level", "testChinese.fnt");
    sprite->addChild(label);
    
    CCString* string;
    if (CCUserDefault::sharedUserDefault()->getBoolForKey("ifEndlessMode")) {
        string = CCString::createWithFormat("Level %d", Interface::sharedInterface()->level);
    }
    else {
        string = CCString::createWithFormat("Level %d", Interface::sharedInterface()->level1);
    }
    
    label->setString(string->getCString());
    label->setPosition(ccp(sprite->boundingBox().size.width * 0.5, sprite->boundingBox().size.height * 0.5));
    
    sprite->setPosition(ccp(size.width * 0.5, size.height - sprite->boundingBox().size.height * 0.3));
    sprite->setScale(0.5);
    sprite->setTag(tag_sprite);
}