本文整理汇总了C++中Enemy::Die方法的典型用法代码示例。如果您正苦于以下问题:C++ Enemy::Die方法的具体用法?C++ Enemy::Die怎么用?C++ Enemy::Die使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Enemy
的用法示例。
在下文中一共展示了Enemy::Die方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkForCollisions
//Checks for collision between character, enemies and projectiles
void CharacterManager::checkForCollisions(){
std::list<Projectile *>::iterator project;
std::list<Enemy *>::iterator enemy;
for(enemy = monsters.begin(); enemy != monsters.end(); ++enemy){
if(Viewport::getInstance().onScreen((*enemy)->getPosition())){
Enemy *opponent = *enemy;
if(collisionCheck.execute((*player), *opponent)){
//Damage character
if(opponent->isAttacking()){
int damage = opponent->getAttack() - player->getDefense();
player->takeAHit(damage);
if(player->isDead())
player->Die();
}
//Damage enemy
if(player->isAttacking()){
int damage = player->getAttack() - opponent->getDefense();
opponent->takeAHit(damage);
}
}
//check for enemy collision with projectiles
for(project = projectiles.begin(); project != projectiles.end(); ++project){
if(collisionCheck.execute(*(*project), *opponent)){
int damage = player->getAttack() - opponent->getDefense();
opponent->takeAHit(damage);
const Frame* frame = (*project)->getFrame();
Sprite sprite((*project)->getPosition(), (*project)->getVelocity(), (*project)->getName(), frame);
explosions.push_back(new ExplodingSprite(sprite));
project = projectiles.erase(project);
}
}
//check is enemy is dead
if(opponent->isDead()){
opponent->Die();
enemy = monsters.erase(enemy);
dieing.push_back(opponent);
player->updateXP(opponent->getxp());
}
}
}
}
示例2: UpdateData
void MainScene::UpdateData(const float& delta)
{
// 关卡数据更新
StageManager::getInstance()->Update(delta);
vector<Element*> list = GetElementList();
for (int i = 0; i < list.size(); ++i)
{
list.at(i)->SetPositionZ(-list.at(i)->GetOrder() * 2);
if (list.at(i)->GetOrder() == LAYER_PLAYER_BULLET ||
list.at(i)->GetOrder() == LAYER_ENEMY_BULLET)
{
RECT viewRect = Director::getInstance()->GetViewRect();
D3DXVECTOR3 viewPos = Camera::getInstance()->GetViewPosition();
if (Tools::CheckHit_UnInclude(list.at(i),
viewPos.x - viewRect.right / 2.0f,
viewPos.y - viewRect.bottom / 2.0f,
viewPos.x + viewRect.right / 2.0f,
viewPos.y + viewRect.bottom / 2.0f))
{
list.at(i)->SetVisible(false);
}
}
else if (list.at(i)->GetOrder() == LAYER_ENEMY_1 ||
list.at(i)->GetOrder() == LAYER_ENEMY_2 ||
list.at(i)->GetOrder() == LAYER_ENEMY_3)
{
RECT viewRect = Director::getInstance()->GetViewRect();
D3DXVECTOR3 viewPos = Camera::getInstance()->GetViewPosition();
if (list.at(i)->GetPositionY() + (0.5f - list.at(i)->GetAnchorY()) * list.at(i)->GetHeight() <
viewPos.y + viewRect.bottom / 2.0f &&
list.at(i)->GetPositionY() - (0.5f - list.at(i)->GetAnchorY()) * list.at(i)->GetHeight() >
viewPos.y - viewRect.bottom / 2.0f)
{
for (int j = 0; j < list.size(); ++j)
{
if (list.at(j)->GetOrder() == LAYER_PLAYER_BULLET)
{
if (Tools::CheckHit_Circle(list.at(j), list.at(i)) && ((Enemy*)list.at(i))->GetHp() > 0)
{
Bullet* bullet = (Bullet*)list.at(j);
if (bullet->IsCross() == false)
{
bullet->Die();
}
Enemy* enemy = (Enemy*)list.at(i);
enemy->SetHp(enemy->GetHp() - bullet->GetAttack());
enemy->SetBruiseEnable(true);
if (enemy->GetHp() <= 0)
{
enemy->Die();
//分数更新
UserManager* userMgr = UserManager::getInstance();
userMgr->SetScore(userMgr->GetScore() + enemy->GetScore());
enemy->SetScore(0);
_scoreText->SetText("SCORE:" + to_string(userMgr->GetScore()));
if (enemy->GetName().substr(0, 4).compare("boss") == 0)
{
if (userMgr->GetStage() < userMgr->GetStageMax())
{
userMgr->SetStage(userMgr->GetStage() + 1);
if (_black == 0)
{
_black = Sprite::Create("Res/Login/black.png");
_black->SetScale(500);
Add(_black);
ClearUpdateFunc();
AddUpdateFunc(UpdateFunc::Create(CALLBACK_PARAMETER_1(MainScene::Fade, this)));
AudioManager::getInstance()->stopBGM();
AudioManager::getInstance()->playSoundEffect("Sound/se/clear.mp3");
return;
}
}
else
{
}
}
}
else
{
Effect* boom = Effect::Create("fire1");
boom->SetTextureBlend(true);
boom->SetPosition(bullet->GetPositionX(), bullet->GetPositionY(), bullet->GetPositionZ());
boom->SetOrder(LAYER_ENEMY_BOOM);
Add(boom);
AudioManager::getInstance()->playSoundEffect("Sound/se/beiji.ogg");
}
}
}
}
}
else if (Tools::CheckHit_UnInclude(list.at(i),
viewPos.x - viewRect.right / 2.0f - 300,
viewPos.y - viewRect.bottom / 2.0f - 300,
viewPos.x + viewRect.right / 2.0f + 300,
viewPos.y + viewRect.bottom / 2.0f + 300))
//.........这里部分代码省略.........