本文整理汇总了C++中Projectile::getDamage方法的典型用法代码示例。如果您正苦于以下问题:C++ Projectile::getDamage方法的具体用法?C++ Projectile::getDamage怎么用?C++ Projectile::getDamage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Projectile
的用法示例。
在下文中一共展示了Projectile::getDamage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Collide
/**
* Handles collision logic between a ship and a projectile
*/
void System::Collide(Ship& ship, Projectile& proj) {
if(proj.getMass() == 0 || ship.getMass() == 0) return;
double dx = proj.getPosition().x-ship.getPosition().x;
double dy = proj.getPosition().y-ship.getPosition().y;
double separationSquared = dx*dx+dy*dy;
//May be inaccurate with verlet
double totalDamageRange = proj.getCollisionRange() + ship.getCollisionRange();
if(separationSquared < (totalDamageRange * totalDamageRange))
{
ship.Damage(proj.getDamage());
proj.Destroy();
}
}
示例2: collide
bool Projectile::collide(Entity * other, b2Contact& contact, std::string tag)
{
bool handled = false;
//Get fixture string
std::string tig = std::string(static_cast<char*>(contact.GetFixtureA()->GetUserData()));
//If it's the other, get what we are in contact
if (tig == tag)
tig = std::string(static_cast<char*>(contact.GetFixtureB()->GetUserData()));
//If it's our tracking, don't bother
if (tig == "projtracking")
{
handled = true;
}
else if (tag == "player" || tag == "enemy" || tag == "shape")////
{
Shape* shape = static_cast<Shape*>(other);
//Projectiles do get hurt by their friends
if (faction_ != shape->getFaction() && shape->getFaction() != GOD)
{
//Onehit projectiles die on hit, precedence over all
if (oneHit_)
{
alive_ = false;
}
//If we can't penetrate
if (penetration_-- <= 0)
{
takeDamage(1);
if (size_.y > 0)
{
//b2Vec2 vel = body_->GetLinearVelocity();
//vel *= (0.1* size_.x * size_.y);
//
//body_->SetLinearVelocity(vel);
}
}
//Do our force on penetration
else
{
lastPen_ = b2Vec3(body_->GetPosition().x, body_->GetPosition().y, 1);
}
if (alive_ == false)
contact.SetEnabled(false);
}
else contact.SetEnabled(false);
handled = true;
}
else if (tag == "projectile")
{
Projectile* proj = static_cast<Projectile*>(other);
//If we're not friends
if (faction_ != proj->getFaction())
{
//If we can't penetrate
if (--penetration_ < 0)
{
takeDamage(proj->getDamage());
if (alive_ == false)
contact.SetEnabled(false);
}
//Do our force on penetration
else
{
lastPen_ = b2Vec3(body_->GetPosition().x, body_->GetPosition().y, 1);
}
//Maybe set contact to false so stronger proj continues?
}
//Else we must have same owner, do not interact
else contact.SetEnabled(false);
handled = true;
}
else if (tag == "pickup")
{
contact.SetEnabled(false);
handled = true;
}
else if (tag == "shield")
{
Pickup::Shield* shield = static_cast<Pickup::Shield*>(other);
//If we don't own the shield
if (shield->getOwner() != owner_)
{
//Penetrate if we can
//.........这里部分代码省略.........