本文整理汇总了C++中SpriteManager::GetNearestSprite方法的典型用法代码示例。如果您正苦于以下问题:C++ SpriteManager::GetNearestSprite方法的具体用法?C++ SpriteManager::GetNearestSprite怎么用?C++ SpriteManager::GetNearestSprite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpriteManager
的用法示例。
在下文中一共展示了SpriteManager::GetNearestSprite方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
/**\brief Update the Projectile
*
* Projectiles do all the normal Sprite things like moving.
* Projectiles check for collisions with nearby Ships, and if they collide,
* they deal damage to that ship. Note that since each projectile knows which ship fired it and will never collide with them.
*
* Projectiles have a life time limit (in milli-seconds). Each tick they need
* to check if they've lived to long and need to disappear.
*
* Projectiles have the ability to track down a specific target. This only
* means that they will turn slightly to head towards their target.
*/
void Projectile::Update( void ) {
Sprite::Update(); // update momentum and other generic sprite attributes
SpriteManager *sprites = SpriteManager::Instance();
// Check for projectile collisions
Sprite* impact = sprites->GetNearestSprite( (Sprite*)this, 100,DRAW_ORDER_SHIP|DRAW_ORDER_PLAYER );
if( (impact != NULL) && (impact->GetID() != ownerID) && ((this->GetWorldPosition() - impact->GetWorldPosition()).GetMagnitude() < impact->GetRadarSize() )) {
((Ship*)impact)->Damage( (weapon->GetPayload())*damageBoost );
sprites->Delete( (Sprite*)this );
// Create a fire burst where this projectile hit the ship's shields.
// TODO: This shows how much we need to improve our collision detection.
Effect* hit = new Effect(this->GetWorldPosition(), "Resources/Animations/shield.ani", 0);
hit->SetAngle( -this->GetAngle() );
hit->SetMomentum( impact->GetMomentum() );
sprites->Add( hit );
}
// Expire the projectile after a time period
if (( Timer::GetTicks() > secondsOfLife + start )) {
sprites->Delete( (Sprite*)this );
}
// Track the target
Sprite* target = sprites->GetSpriteByID( targetID );
float tracking = weapon->GetTracking();
if( target != NULL && tracking > 0.00000001f ) {
float angleTowards = normalizeAngle( ( target->GetWorldPosition() - this->GetWorldPosition() ).GetAngle() - GetAngle() );
SetMomentum( GetMomentum().RotateBy( angleTowards*tracking ) );
SetAngle( GetMomentum().GetAngle() );
}
}
示例2: Update
void Gate::Update() {
// The Bottom Gate doesn't do anything
if(!top) return;
SpriteManager *sprites = SpriteManager::Instance();
Sprite* ship = sprites->GetNearestSprite( (Sprite*)this, 50,DRAW_ORDER_SHIP|DRAW_ORDER_PLAYER );
if(ship!=NULL) {
if(exitID != 0) {
SendToExit(ship);
} else if(rand()&1) {
SendToRandomLocation(ship);
} else {
SendRandomDistance(ship);
}
}
}