本文整理汇总了C++中Projectile::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ Projectile::getType方法的具体用法?C++ Projectile::getType怎么用?C++ Projectile::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Projectile
的用法示例。
在下文中一共展示了Projectile::getType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: writeProjectile
void RemoteProcessClient::writeProjectile(const Projectile& projectile) {
writeBoolean(true);
writeLong(projectile.getId());
writeDouble(projectile.getMass());
writeDouble(projectile.getX());
writeDouble(projectile.getY());
writeDouble(projectile.getSpeedX());
writeDouble(projectile.getSpeedY());
writeDouble(projectile.getAngle());
writeDouble(projectile.getAngularSpeed());
writeDouble(projectile.getRadius());
writeLong(projectile.getCarId());
writeLong(projectile.getPlayerId());
writeEnum<ProjectileType>(projectile.getType());
}
示例3: handlePlayerShooting
void ServerWorldModel::handlePlayerShooting(PlayerId playerId, ServerPlayers &players)
{
int currentTick = getTimeHandler()->getTick();
Tickf currentTickf = static_cast<Tickf>(currentTick);
PlayerObj *playerObj = getPlayerObjs()[playerId];
// Copy userCmd, we must have a seperate copy to alter while original is intact.
UserCmd userCmd(playerObj->getUserCmd());
ClientIdGenerator *clientIdGenerator = players[playerId]->getIdGenerator();
int clientNShots = userCmd.nShots;
assert(userCmd.firstShotTick >= currentTickf);
assert(playerObj->getNextShootTick() >= currentTickf);
// remove projectiles if client created projectiles which we did't notice before
while (userCmd.firstProjectileId > clientIdGenerator->getNextId())
{
RemoveProjectile removeProjectile(clientIdGenerator->generateGameObjId());
players[playerId]->link.pushMessage(removeProjectile, getTimeHandler()->getTime(), getTimeHandler()->getTick());
}
assert(userCmd.firstProjectileId == clientIdGenerator->getNextId());
if (clientNShots > 0)
{
assert(userCmd.firstShotTick >= playerObj->getNextShootTick());
// Do any shooting
int serverNShots = 0;
Tickf shotTick;
Projectile::Type weapon = userCmd.weapon;
for(int i=0; i<clientNShots; ++i)
{
GameObjId projectileId = clientIdGenerator->generateGameObjId();
if (playerTryShoot(playerId, currentTick, i, projectileId, shotTick))
{
if (serverNShots == 0) userCmd.firstShotTick = shotTick;
Projectile *projectile = (getProjectiles())[projectileId];
std::cout << "server tick: " << getTimeHandler()->getTick() << " projectile shot, objLag = " << projectile->getObjLag() << std::endl;
// send projectile to all clients
AddProjectile addProjectile(projectileId, projectile->getType(), projectile->getPos(),
projectile->getAngle().getFloat(), projectile->getShooterId(),
projectile->getShootTick(), projectile->getObjLag());
pushMessageToAll(players, addProjectile, getTimeHandler()->getTime(), getTimeHandler()->getTick());
++serverNShots;
}
else
{
RemoveProjectile removeProjectile(projectileId);
players[playerId]->link.pushMessage(removeProjectile, getTimeHandler()->getTime(), getTimeHandler()->getTick());
}
}
userCmd.nShots = serverNShots;
// Safe to overwrite PlayerObj.userCmd now, write changes
playerObj->setUserCmd(&userCmd);
}
}
示例4: BeginContact
void ContactListener::BeginContact(b2Contact* contact)
{
SceneNode* A = static_cast<SceneNode*> (contact -> GetFixtureA() -> GetBody() -> GetUserData() );
SceneNode* B = static_cast<SceneNode*> (contact -> GetFixtureB() -> GetBody() -> GetUserData() );
if (A -> getCategory() == Category::Projectile && contact->IsTouching())
{
Projectile* proj = static_cast<Projectile*>(A);
proj->isDead = true;
}
if (B -> getCategory() == Category::Projectile && contact->IsTouching())
{
Projectile* proj = static_cast<Projectile*>(B);
proj->isDead = true;
}
if (contact->IsTouching() && //projectile - ground
(A -> getCategory() == Category::Projectile || B -> getCategory() == Category::Projectile) &&
(A -> getCategory() == Category::Ground || B -> getCategory() == Category::Ground))
{
Ground* ground = static_cast<Ground*>( (A -> getCategory() == Category::Ground) ? A : B);
Projectile* proj = static_cast<Projectile*>( (A -> getCategory() == Category::Ground) ? B : A );
if (proj->getType() == Projectile::Type::Missle)
ground->explosion(proj->position, 3);
}
if (contact->IsTouching() && //player - ground
(A -> getCategory() == Category::Player || B -> getCategory() == Category::Player) &&
(A -> getCategory() == Category::Ground || B -> getCategory() == Category::Ground))
{
Player* player = static_cast<Player*>( (A -> getCategory() == Category::Ground) ? B : A );
player -> onFloor++;
}
if (contact->IsTouching() && //player - wreck
(A -> getCategory() == Category::Player || B -> getCategory() == Category::Player) &&
(A -> getCategory() == Category::Wreck || B -> getCategory() == Category::Wreck))
{
Player* player = static_cast<Player*>( (A -> getCategory() == Category::Wreck) ? B : A );
player -> onFloor++;
}
if (contact->IsTouching() && //projectile - enemy
(A -> getCategory() == Category::Projectile || B -> getCategory() == Category::Projectile) &&
(A -> getCategory() == Category::Enemy || B -> getCategory() == Category::Enemy))
{
Enemy* enemy = static_cast<Enemy*>( (A -> getCategory() == Category::Enemy) ? A : B);
Projectile* proj = static_cast<Projectile*>( (A -> getCategory() == Category::Enemy) ? B : A );
enemy->hp -= proj->Table[proj->getType()].Damage;
if (enemy->hp <= 0)
{
enemy -> isDead = true;
}
}
if (contact->IsTouching() && //player - enemy
(A -> getCategory() == Category::Player || B -> getCategory() == Category::Player) &&
(A -> getCategory() == Category::Enemy || B -> getCategory() == Category::Enemy))
{
Player* player = static_cast<Player*>( (A -> getCategory() == Category::Enemy) ? B : A );
player->isHurting = true;
}
}