本文整理汇总了C++中Projectile::getPositionX方法的典型用法代码示例。如果您正苦于以下问题:C++ Projectile::getPositionX方法的具体用法?C++ Projectile::getPositionX怎么用?C++ Projectile::getPositionX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Projectile
的用法示例。
在下文中一共展示了Projectile::getPositionX方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateProjectiles
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
}
}
}
}
示例2: update
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();
}
}