Exemplo n.º 1
0
void PBase::showStarAni(WJSprite *starSprite)
{
    if (WJUtils::equals(starSprite->getUserString(), "get"))
    {
        starSprite->setVisible(true);
    }
    else
    {
        Common::sound.play("Common:star");

        // 添加星星出现的粒子效果
        ParticleSystemQuad *starParticle = ParticleSystemQuad::create("particles/star.plist");
        starParticle->setPosition(Vec2(starSprite->getContentSize().width / 2, starSprite->getContentSize().height / 2));
        starSprite->addChild(starParticle);
        starParticle->setAutoRemoveOnFinish(true);

        starSprite->setUserString("get");
        starSprite->runAction(
            Sequence::create(
                ScaleTo::create(0.0f, 0.0f, 0.0f),
                Show::create(),
                Spawn::create(
                    ScaleTo::create(0.3f, 1.0f, 1.0f),
                    RotateBy::create(0.3f, 360.0f, 360.0f),
                    NULL),
                NULL));
    }
}
Exemplo n.º 2
0
bool GameScene::isCollisionWithCoin() //和金币的碰撞检测
{
    bool  aFlag = false;
    
    for (int i=0; i<coinArray.size(); i++) {
        Rect box =  coinArray.at(i)->boundingBox();
        if (player->boundingBox().intersectsRect(box))
        {
            //当金币可见的时候才放粒子效果和音效
            if ( coinArray.at(i)->isVisible() == true) {
            coinArray.at(i)->setVisible(false);
            //粒子效果
            ParticleSystemQuad *paritcle = ParticleSystemQuad::create("physic-con.plist");
            paritcle->setPosition(coinArray.at(i)->getPosition());
            paritcle->setAutoRemoveOnFinish(true);
            this->addChild(paritcle,8);
             
            this->progressUpdate();//调用进度条事件
                
            player->addScore(1);//加分

            if (isPlaySound) {
                SimpleAudioEngine::getInstance()->playEffect("eatcoin.caf");
                }
            } 
        }
    }
    return aFlag;
}
Exemplo n.º 3
0
//飞船加速效果
void SceneGame::ShipAccelerate(const Point& point)
{
	ParticleSystemQuad *emitter = ParticleSystemQuad::create("Image/Comet.plist");
	emitter->setPosition(point);
	emitter->setRotation(-45.0);
	this->addChild(emitter, 10);
}
Exemplo n.º 4
0
void StarNode::UI_addParticle(){
    
    Point delta = _starRef->getStartPoint() - _starRef->getEndPoint();
    
    //出一个星星试试
    ParticleSystemQuad *particle = CCParticleSystemQuad::create("Shoot.plist");
    this->addChild( particle );
    particle->setDuration( _starRef->getDuration() ); //持续时间
    particle->setPosition( Point() );
    
    //上270下90左0右180
    float x = delta.x;
    float y = delta.y;
    
    float angle ;
    
    if ( ( delta.x > -0.01 || delta.x < 0.01 ) ) {
        angle = 270;
    }else{
        angle = fabs( atanf( delta.y/delta.x ) *180/3.1415 );
    }

    if ( x >= 0 && y > 0) {
        
    }else if ( x < 0 && y >= 0 ){
        angle += 90;
    }else if ( x < 0 && y <= 0 ){
        angle += 180;
    }else if ( x >= 0 && y < 0 ){
        angle += 270;
    }
    
    particle->setAngle( angle );
    particle->setAngleVar( 0 );
}
Exemplo n.º 5
0
void Blocks::emittParticles(cocos2d::Layer *layer, cocos2d::Point point)
{
	ParticleSystemQuad *emitter = ParticleSystemQuad::create("Json/XXX.plist");
	emitter->retain();
	emitter->setPosition(point);
	layer->addChild(emitter, PARTICLE_ZORDER);
}
Exemplo n.º 6
0
bool GameScene::init(){
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();
    
    auto sprite = Sprite::create("bj2.jpg");
    sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(sprite, -4);
    
    auto bg1 = Sprite::create("b2.png");
    bg1->setAnchorPoint(Point(0, 0));
    bg1->setPosition(Point(0, 10));
    this->addChild(bg1, -3);
    
    auto bg2 = Sprite::create("b2.png");
    bg2->setAnchorPoint(Point(0, 0));
    bg2->setPosition(Point(bg1->getContentSize().width, 10));
    this->addChild(bg2, -3);
    
    distanceBg.pushBack(bg1);
    distanceBg.pushBack(bg2);
    
    auto bg3 = Sprite::create("b1.png");
    bg3->setAnchorPoint(Point(0, 0));
    bg3->setPosition(Point(0, 0));
    this->addChild(bg3, -2);
    
    auto bg4 = Sprite::create("b1.png");
    bg4->setAnchorPoint(Point(0, 0));
    bg4->setPosition(bg3->getContentSize().width, 0);
    this->addChild(bg4, -2);
    
    nearbyBg.pushBack(bg3);
    nearbyBg.pushBack(bg4);
    
    ParticleSystemQuad *emiter = ParticleSystemQuad::create("dirt.plist");
    emiter->setPosition(visibleSize.width/2, visibleSize.height/2);
    this->addChild(emiter, -3);
    
    map = TMXTiledMap::create("map.tmx");
    map->setAnchorPoint(Point(0, 0));
    map->setPosition(Point(0, 0));
    this->addChild(map, -1);

    addPlayer(map);
    addHeart(map);
    
    playFlyToScene();
    
    Node *ground = Node::create();
    float width = map->getContentSize().width;
    float height = map->getContentSize().height * 3 / 16;

    auto bottomBody = PhysicsBody::createEdgeSegment(Point(0, height), Point(width, height));
    ground->setPhysicsBody(bottomBody);
    this->addChild(ground);
    
    return true;
}
Exemplo n.º 7
0
void ShowStar::onDialogShown(LBModalDialog *dialog)
{
	const Size &size = Director::getInstance()->getWinSize();
	ParticleSystemQuad *particle = ParticleSystemQuad::create("particles/opennning.plist");
	particle->setPosition(dialog->convertToNodeSpace(Vec2(size.width / 2, size.height / 2)));
	particle->setPositionType(ParticleSystem::PositionType::RELATIVE);
	dialog->addChild(particle, 50);
}
Exemplo n.º 8
0
void Star::playParticle()
{
	const Size &size = this->getContentSize();
	ParticleSystemQuad *particle = ParticleSystemQuad::create("particles/heartui.plist");
	particle->setPosition(Vec2(size.width / 2, size.height / 2)+ Vec2(0, 0));
	particle->setPositionType(ParticleSystem::PositionType::RELATIVE);
	this->addChild(particle, 1000);
}
Exemplo n.º 9
0
void ShowStar::playStarParticle(WJSprite *sprite, const char * file)
{
	// 播放粒子效果
	ParticleSystemQuad *particle = ParticleSystemQuad::create(file);
	particle->setPosition(sprite->getPosition());
	particle->setPositionType(ParticleSystem::PositionType::RELATIVE);
	sprite->getParent()->addChild(particle, sprite->getLocalZOrder() + 10);
}
Exemplo n.º 10
0
bool Breakout::onConcactBegan(PhysicsContact& contact) {

	auto nodeA = contact.getShapeA()->getBody()->getNode();
	auto nodeB = contact.getShapeB()->getBody()->getNode();
	if (nodeA->getTag() == 1 || nodeB->getTag() == 1) {
		if(time > 0) dead();
	}
	else {
		//播放碰撞音效
		SimpleAudioEngine::getInstance()->playEffect("music/meet_stone.wav");

		//陨石爆炸并消失
		ParticleSystemQuad* fireWorks;
		if (nodeA->getTag() != 100) {
			nodeA->getPhysicsBody()->setName("isContact");
			if (nodeA->getTag() == 10) {
				blood -= 10;
				fireWorks = ParticleSystemQuad::create("fire1.plist");
			}
			else if (nodeA->getTag() / 10000 == 20) {
				blood -= 15;
				fireWorks = ParticleSystemQuad::create("fire2.plist");
			}
			else {
				blood -= 20;
				fireWorks = ParticleSystemQuad::create("fire3.plist");
			}
			fireWorks->setPosition(nodeA->getPosition());
			this->removeChild(nodeA);
		}
		else {
			nodeB->getPhysicsBody()->setName("isContact");
			if (nodeB->getTag() == 10) {
				blood -= 10;
				fireWorks = ParticleSystemQuad::create("fire1.plist");
			}
			else if (nodeB->getTag() == 20) {
				blood -= 15;
				fireWorks = ParticleSystemQuad::create("fire2.plist");
			}
			else {
				blood -= 20;
				fireWorks = ParticleSystemQuad::create("fire3.plist");
			}
			fireWorks->setPosition(nodeB->getPosition());
			this->removeChild(nodeB);
		}
		this->addChild(fireWorks, 1);
		for (int i = 0; i < enemys.size(); i++) {
			if (enemys.at(i)->getName() == "isContact") {
				enemys.erase(enemys.begin() + i);
			}
		}
		pT->setPercentage(blood);
		if (blood <= 0) dead();
	}
	return true;
}
Exemplo n.º 11
0
void World::addExplosion(const Vec2 &position)
{
	std::string filename = "particle/explosion.plist";
	
	ParticleSystemQuad *emitter = ParticleSystemQuad::create(filename);
	emitter->setPosition(position);
	emitter->setScale(0.4);
	
	addChild(emitter);
}
ParticleSystemQuad * ParticleSystemQuad::create() {
    ParticleSystemQuad *pParticleSystemQuad = new ParticleSystemQuad();
    if (pParticleSystemQuad && pParticleSystemQuad->init())
    {
        pParticleSystemQuad->autorelease();
        return pParticleSystemQuad;
    }
    CC_SAFE_DELETE(pParticleSystemQuad);
    return NULL;
}
ParticleSystemQuad * ParticleSystemQuad::create() {
    ParticleSystemQuad *particleSystemQuad = new (std::nothrow) ParticleSystemQuad();
    if (particleSystemQuad && particleSystemQuad->init())
    {
        particleSystemQuad->autorelease();
        return particleSystemQuad;
    }
    CC_SAFE_DELETE(particleSystemQuad);
    return nullptr;
}
ParticleSystemQuad * ParticleSystemQuad::createWithTotalParticles(int numberOfParticles) {
    ParticleSystemQuad *ret = new (std::nothrow) ParticleSystemQuad();
    if (ret && ret->initWithTotalParticles(numberOfParticles))
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_DELETE(ret);
    return ret;
}
ParticleSystemQuad * ParticleSystemQuad::createWithTotalParticles(unsigned int numberOfParticles) {
    ParticleSystemQuad *pRet = new ParticleSystemQuad();
    if (pRet && pRet->initWithTotalParticles(numberOfParticles))
    {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return pRet;
}
Exemplo n.º 16
0
void CreateRainEvent::run()
{
    this->setDone();
    
    Size size = Director::getInstance()->getVisibleSize();
    ParticleSystemQuad* rain = ParticleSystemQuad::create("img/rain.plist");
    rain->setPosition(Vec2(size.width/2,size.height));

    DungeonSceneManager::getInstance()->getScene()->addChild(rain);
}
ParticleSystemQuad * ParticleSystemQuad::create(const char *plistFile)
{
    ParticleSystemQuad *pRet = new ParticleSystemQuad();
    if (pRet && pRet->initWithFile(plistFile))
    {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return pRet;
}
Exemplo n.º 18
0
void BattleScene::addExplosionEffect(Vec2 point)
{
    std::string fileName="boxBreak.plist";
    ParticleSystemQuad *effect = ParticleSystemQuad::create(fileName);
    auto scene =Director::getInstance()->getRunningScene();
    if (scene) {
        scene->addChild(effect,1000);
    }
    effect->setAutoRemoveOnFinish(true);
    effect->setPosition(point);
}
ParticleSystemQuad * ParticleSystemQuad::create(ValueMap &dictionary)
{
    ParticleSystemQuad *ret = new (std::nothrow) ParticleSystemQuad();
    if (ret && ret->initWithDictionary(dictionary))
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_DELETE(ret);
    return ret;
}
ParticleSystemQuad * ParticleSystemQuad::create(const std::string& filename)
{
    ParticleSystemQuad *ret = new (std::nothrow) ParticleSystemQuad();
    if (ret && ret->initWithFile(filename))
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_DELETE(ret);
    return ret;
}
Exemplo n.º 21
0
void Breakout::removeAllEnemys() {
	if (!flag) {
		for (int i = 0; i < enemys.size(); i++) {
			Vec2 p = enemys.at(i)->getPosition();
			ParticleSystemQuad* fireWorks = ParticleSystemQuad::create("fire3.plist");
			fireWorks->setPosition(p);
			this->addChild(fireWorks);
			this->removeChild(enemys.at(i)->getNode());
		}
		enemys.clear();
		flag = true;
	}
}
Exemplo n.º 22
0
Node* NodeReader::loadParticle(const rapidjson::Value& json)
{
    const char* filePath = DICTOOL->getStringValue_json(json, PLIST_FILE);
    int num = DICTOOL->getIntValue_json(json, PARTICLE_NUM);

    ParticleSystemQuad* particle = ParticleSystemQuad::create(filePath);
    particle->setTotalParticles(num);
    particle->retain();

    initNode(particle, json);

    return particle;
}
 Node* ParticleReader::createNodeWithFlatBuffers(const flatbuffers::Table *particleOptions)
 {
     ParticleSystemQuad* particle = nullptr;
     
     auto options = (ParticleSystemOptions*)particleOptions;
     auto fileNameData = options->fileNameData();
     
     bool fileExist = false;
     std::string errorFilePath = "";
     std::string path = fileNameData->path()->c_str();
     int resourceType = fileNameData->resourceType();
     switch (resourceType)
     {
         case 0:
         {
             if (FileUtils::getInstance()->isFileExist(path))
             {
                 fileExist = true;
             }
             else
             {
                 errorFilePath = path;
                 fileExist = false;
             }
             break;
         }
             
         default:
             break;
     }
     if (fileExist)
     {
         particle = ParticleSystemQuad::create(path);
         if (particle)
         {
             setPropsWithFlatBuffers(particle, (Table*)particleOptions);
             particle->setPositionType(ParticleSystem::PositionType::GROUPED);
         }
     }
     else
     {
         Node* node = Node::create();
         setPropsWithFlatBuffers(node, (Table*)particleOptions);
         auto label = Label::create();
         label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString());
         node->addChild(label);
         return node;
     }
     
     return particle;
 }
Exemplo n.º 24
0
//游戏失败
void Breakout::dead() {
	blood = 0;
	pT->setPercentage(blood);
	unschedule(schedule_selector(Breakout::update));
	unschedule(schedule_selector(Breakout::showTime));
	ParticleSystemQuad* fireWorks = ParticleSystemQuad::create("fire.plist");
	fireWorks->setPosition(player->getPosition());
	this->addChild(fireWorks);

	this->removeChild(player);
	LayerColor* gameOverLayer = LayerColor::create(Color4B(128, 128, 128, 128));
	Label* over = Label::createWithSystemFont("Game Over", "Arial", 80);
	over->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
	gameOverLayer->addChild(over);
	this->addChild(gameOverLayer, 5);
}
Exemplo n.º 25
0
void Entity::die()
{
    if (this->stateMachine->isDead()) {
        return;
    }

    this->stateMachine->dead();
    Sprite* body = this->getBody();

    ParticleSystemQuad* particle = ParticleSystemQuad::create("Particles/Die.plist");
    particle->setStartColor(Color4F(body->getColor()));
    particle->setEndColor(Color4F(body->getColor()));
    this->addChild(particle);

    this->deactivate();
}
Exemplo n.º 26
0
//碰撞检测
void StartGame::testCollin(float dt){
    auto visibleSize=Director::getInstance()->getWinSize();
    __Array *tempItemArray=__Array::create();
    tempItemArray->retain();
    Item *item;
    for (int i=0; i<itemArray->count(); i++) {
        item=(Item*)itemArray->getObjectAtIndex(i);
        if (Tools::isCollision(hook, item)&&!hook->hookAction&&!item->itemAction) {
            hook->stopAllActions();
            miner->MinerAction();
            tempItemArray->addObject(item);
            hook->hookAction = true;
            item->itemAction=true;
            if (toggle->getSelectedIndex()==1) {
                dt=0.5;
            }else{
                dt=2.0;
            }
            auto move=MoveTo::create(dt, Vec2(visibleSize.width/2-5,visibleSize.height/2-20));
            auto call=CallFunc::create(CC_CALLBACK_0(StartGame::move, this));
            auto sequence=Sequence::create(move,call, NULL);
            hook->runAction(sequence);
            if (item->itemAction) {
                item->setRotation(hook->getRotation());
                item->setAnchorPoint(Point(0.5, 1));
                hook->setAnchorPoint(Point(0.5, 0.7));
                item->setPosition(hook->getPosition());
                hook->setAnchorPoint(Point(0.5, 1));
            }
            if (item->_type==diamond||item->_type==secret) {
                ParticleSystemQuad* quad = ParticleSystemQuad::create("Boom.plist");
                quad->setBlendAdditive(true);
                quad->setAutoRemoveOnFinish(true);
                quad->setPosition(item->getPosition());
                quad->setDuration(0.2);
                this->addChild(quad);
            }
            auto move1=MoveTo::create(dt, Vec2(visibleSize.width/2-5,visibleSize.height/2-20));
            auto call1=CallFuncN::create(CC_CALLBACK_1(StartGame::removeItem, this));
            auto sequence1=Sequence::create(move1,call1, NULL);
            item->runAction(sequence1);
        }
    }
    itemArray->removeObjectsInArray(tempItemArray);
    tempItemArray->release();
}
Exemplo n.º 27
0
void Result::StageEffect(float dt){
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    
    ParticleSystemQuad* particle = CCParticleSystemQuad::create("highscoretexture.plist");
    particle->setAutoRemoveOnFinish(true);
    
    int px=arc4random()%500;
    int py=arc4random()%400+80;
    // パーティクルを表示する場所の設定
    particle->setPosition(Point((visibleSize.width-px)/2+px,visibleSize.height-py));
    particle->setPositionZ(-3);
    
    CCLOG("px=%d,py=%d",px,py);
    // パーティクルを配置
    this->addChild(particle);
}
void Portal::initParticle(Node * gameWorld)
{
    ParticleSystemQuad * emitterUnder = nullptr;
    
    emitterUnder = ParticleSystemQuad::create(portalDefs::PARTICLE_FILE);
    emitterUnder->setPosition(Vec2(this->getContentSize().width/2, this->getContentSize().height/2));
    emitterUnder->setPositionType(ParticleSystem::PositionType::RELATIVE);
    this->addChild(emitterUnder, 1, portalDefs::PARTICLE_UNDER_NAME);
    
    _originalEmitterStartColor = emitterUnder->getStartColor();
    _originalEmitterStartColorVar = emitterUnder->getStartColorVar();
    _originalEmitterEndColor = emitterUnder->getEndColor();
    _originalEmitterEndColorVar = emitterUnder->getEndColorVar();
    
    if (gameWorld)
    {
        _emitterTop = ParticleSystemQuad::create(portalDefs::PARTICLE_FILE);
        
        Point screenPosition = this->convertToWorldSpace(Point(this->getContentSize()/2.0f));
        Point localPosition = gameWorld->convertToNodeSpace(screenPosition);
        _emitterTop->setPosition(localPosition);
        
        _emitterTop->setPositionType(ParticleSystem::PositionType::RELATIVE);
        gameWorld->addChild(_emitterTop, portalDefs::PARTICLE_TOP_Z_ORDER);
    }
    
    this->setActiveParticle(false);
}
Exemplo n.º 29
0
void Entity::receiveDamage(int damage, Vec2 enemyPosition)
{
    if (this->stateMachine->isDead()) {
        return;
    }

    this->setHp(this->hp - damage);

    Sprite* body = this->getBody();

    ParticleSystemQuad* particle = ParticleSystemQuad::create("Particles/Damage.plist");
    particle->setStartColor(Color4F(body->getColor()));
    particle->setEndColor(Color4F(body->getColor()));
    this->addChild(particle);

    EntityDirection knockbackDirection = EntityHelper::directionFromStartPositionAndEndPosition(enemyPosition, this->getPosition());
    this->knockback(knockbackDirection, ENTITY_KNOCKBACK_DISTANCE_PER_SEC, ENTITY_KNOCKBACK_CANCEL_ATTACK);
}
Exemplo n.º 30
0
void LockHelper::playLookGetfreeVideoAfterAni(Node* pItemNode)
{
	Node* pGetfreeNode = pItemNode->getChildByTag(GETFREE_SPRITE_TAG);
	if (pGetfreeNode)
	{
		pItemNode->runAction(Sequence::create(
			ScaleTo::create(0.15f, pItemNode->getScale() * 1.15f),
			ScaleTo::create(0.15f, pItemNode->getScale() * 1.0f),
			ScaleTo::create(0.15f, pItemNode->getScale() * 1.1f),
			ScaleTo::create(0.15f, pItemNode->getScale() * 1.0f),
			CCCallFunc::create([=]() {
				// 播放音效
				Common::sound.play("Common:0071");
				// 播放粒子效果
				ParticleSystemQuad *particle = ParticleSystemQuad::create("particles/unlock.plist");
				particle->setPosition(pItemNode->getPosition());
				pItemNode->getParent()->addChild(particle, pItemNode->getLocalZOrder() + 1);
			}),
			CCCallFunc::create([=]() {
				Node* getfreeNode = pItemNode->getChildByTag(GETFREE_SPRITE_TAG);
				if (getfreeNode)
				{
					getfreeNode->runAction(Sequence::create(
						MoveBy::create(0.1f, Vec2(0, 30)),
						Spawn::create(
						MoveBy::create(0.3f, Vec2(50, -60)),
						FadeOut::create(0.3f),
						NULL),
						CCCallFunc::create([=](){
							Common::sound.play("Common:0072");
							// 播放粒子效果
							ParticleSystemQuad *particle = ParticleSystemQuad::create("particles/unlockend.plist");
							particle->setPosition(pItemNode->getPosition());
							pItemNode->getParent()->addChild(particle, pItemNode->getLocalZOrder() + 1);
					}),
						Hide::create(),
						RemoveSelf::create(),
					NULL));
				}
			}),
			NULL));
	}
}