Beispiel #1
0
void GameScene::updateProjectiles(float dt)
{
	if (m_bullets->count() > 0)
	{
		CCObject* ob = NULL;
		CCARRAY_FOREACH(m_bullets, ob)
		{
			Projectile* proj = dynamic_cast<Projectile*>(ob);
			proj->update(dt);

			if (proj->getPositionX() < 0.f - proj->getContentSize().width || proj->getPositionX() > m_visibleSize.width + proj->getContentSize().width)
				m_removableBullets->addObject(proj);
			else if (checkCollisions(m_hero, proj) && proj->getType() == Projectile::Bullet)
			{
				m_removableBullets->addObject(proj);
				updateHealth(10); // dmg value here
			}
			else
			{
				for (uint i = 0; i < m_enemies->count(); ++i)
				{
					Enemy* en = dynamic_cast<Enemy*>(m_enemies->objectAtIndex(i));
					if (checkCollisions(en, proj) && proj->getType() == Projectile::Rocket)
					{
						m_removableBullets->addObject(proj);
						m_removables->addObject(m_enemies->objectAtIndex(i));
						
						CCParticleSystemQuad * smokeParticle = CCParticleSystemQuad::create("textures/smoke.plist"); 
						smokeParticle->setPosition(en->getPosition());
						this->addChild(smokeParticle);
						smokeParticle->setAutoRemoveOnFinish(true);
						
						CCParticleSystemQuad * dustParticle = CCParticleSystemQuad::create("textures/dusts.plist");
						dustParticle->setPosition(en->getPosition());
						this->addChild(dustParticle);
						dustParticle->setAutoRemoveOnFinish(true);
						CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("audio/rocketExplode.wav", false);
						CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("audio/enemyKill.wav", false);

						updateScore(); //score value here
					}
				}
			}
		}
Beispiel #2
0
void StartScene::update(float dt)
{
    DataModel *m = DataModel::getModel();
    Vector<Projectile*> projectilesToDelete;

    for (int i = 0; i < m->projectiles.size(); i++)
    {
        Projectile* projectile = (Projectile*)(m->projectiles.at(i));
        Rect projectileRect = Rect(projectile->getPositionX() - (projectile->getContentSize().width / 2),
                                   projectile->getPositionY() - (projectile->getContentSize().height / 2),
                                   projectile->getContentSize().width,
                                   projectile->getContentSize().height);
        for (int i = 0; i < m->targets.size(); i++)
        {
            Creep* target = (Creep*)(m->targets.at(i));
            Rect targetRect = Rect(target->getPositionX() - (target->sprite->getContentSize().width / 2),
                                   target->getPositionY() - (target->sprite->getContentSize().height / 2),
                                   target->sprite->getContentSize().width,
                                   target->sprite->getContentSize().height);
            if (projectileRect.intersectsRect(targetRect))
            {
                projectilesToDelete.pushBack(projectile);
                Creep *creep = target;
                creep->curHp -= projectile->power;
                creep->lifeBar->setPercentage(static_cast<float>(creep->curHp*100)/creep->maxHp);
                CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("hit.wav");
                if (creep->curHp <= 0)
                {
//					targetsToDelete.pushBack(creep);
                    m->targets.eraseObject(creep);
                    CCParticleSystem* particleSystem = CCParticleExplosion::create();
                    particleSystem->setTexture(CCTextureCache::sharedTextureCache()->addImage("bullet2.png"));
                    particleSystem->setPosition(creep->getPosition());
                    particleSystem->setScale(0.15);
                    particleSystem->setLife(1);
                    this->addChild(particleSystem);
//                    creep->removeAllChildren();
//                    creep->sprite = Sprite::create("blast7.png");
//                    creep->addChild(creep->sprite,0);
                    this->removeChild(creep,true);
                    CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("blast.wav");
                    m->currentMoney += creep->bonusMoney;
                    money->setText(to_string(m->currentMoney));
                }
//                for (int i = 0; i < targetsToDelete.size(); i++)
//                {
//                    Creep *target = (Creep*)(targetsToDelete.at(i));
//                    m->targets.eraseObject(target);
//                    this->removeChild(target, true);
//                    CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("blast.wav");
//                }
                break;
            }
        }
    }



    for (int i =0; i < projectilesToDelete.size(); i++)
    {
        Projectile *projectile = (Projectile*)(projectilesToDelete.at(i));
        m->projectiles.eraseObject(projectile);
        this->removeChild(projectile,true);
    }

    if (this->currentLevel==-1&&m->targets.size()==0) {
        //win
        Size visibleSize = Director::getInstance()->getVisibleSize();
        Point origin = Director::getInstance()->getVisibleOrigin();
//        auto winPic = Sprite::create("win.png");
//        winPic->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
////        winPic->setScale(2);
//        this->addChild(winPic,2);
        widget = dynamic_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("OverUi_1/WinUi_1.json"));
        widget->setPosition(Point(visibleSize.width/2 + origin.x -widget->getContentSize().width/2, visibleSize.height/2 + origin.y - widget->getContentSize().height/2));
        this->addChild(widget,2);
        auto star1 = dynamic_cast<ImageView*>(widget->getChildByName("Star_1"));
        auto star2 = dynamic_cast<ImageView*>(widget->getChildByName("Star_2"));
        auto star3 = dynamic_cast<ImageView*>(widget->getChildByName("Star_3"));
        auto restartButton = dynamic_cast<Button*>(widget->getChildByName("RestartBTN"));
        auto continueButton = dynamic_cast<Button*>(widget->getChildByName("ContinueBTN"));
        restartButton->addTouchEventListener(this, toucheventselector(StartScene::restartEvent));
        continueButton->addTouchEventListener(this, toucheventselector(StartScene::continueEvent));
        if (m->home->homeHP>=1&& m->home->homeHP<=3) {
            star2->setVisible(false);
            star3->setVisible(false);
        } else if (m->home->homeHP>=4&&m->home->homeHP<=9) {
            star3->setVisible(false);
        }
        this->cleanup();
    }

}