本文整理汇总了C++中Enemy::getDirection方法的典型用法代码示例。如果您正苦于以下问题:C++ Enemy::getDirection方法的具体用法?C++ Enemy::getDirection怎么用?C++ Enemy::getDirection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Enemy
的用法示例。
在下文中一共展示了Enemy::getDirection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void FightingLayer::update(float dt) {
_playDuration += dt;
Rect rect = Rect(0, 0, _ground->getContentSize().width, _ground->getContentSize().height);
// Update bullets
for (std::vector<Bullet *>::size_type i = 0; i != _bullets->size(); i++) {
Bullet *bullet = _bullets->at(i);
bullet->update(dt);
if (!rect.containsPoint(bullet->getPosition())) {
bullet->kill();
_bullets->erase(_bullets->begin() + i);
i--;
continue;
}
for (std::vector<Enemy *>::size_type j = 0; j != _enemies->size(); j++) {
Enemy *enemy = _enemies->at(j);
// Check if bullet hits
if (enemy->getBoundingBox().containsPoint(bullet->getPosition())) {
_score += 10;
// Remove enemy
//enemy->removeFromParent();
enemy->kill();
_enemies->erase(_enemies->begin() + j);
j--;
// REmove bullet
bullet->kill();
_bullets->erase(_bullets->begin() + i);
i--;
updateScore();
break;
}
}
}
for (std::vector<Smoke *>::size_type i = 0; i != _smokes->size(); i++) {
Smoke *smoke = _smokes->at(i);
Point position = smoke->getPosition();
if (position.x < 0) {
position.x = 0;
smoke->reverse();
}
else if (position.x > rect.size.width) {
position.x = rect.size.width;
smoke->reverse();
}
}
for (std::vector<Enemy *>::size_type i = 0; i != _enemies->size(); i++) {
Enemy *enemy = _enemies->at(i);
// Check if outside
bool isOutside = (enemy->getDirection() == -1 && enemy->getPosition().x < 0) || (enemy->getDirection() == 1 && enemy->getPosition().x > _ground->getContentSize().width);
if (isOutside) {
enemy->removeFromParent();
_enemies->erase(_enemies->begin() + i);
i--;
continue;
}
// Check if hits player
if (_player->getBoundingBox().intersectsRect(enemy->getBoundingBox()) && _player->isAlive()) {
_player->kill();
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("die_sound.wav");
this->gameDidEnd();
break;
}
}
if (_player->isAlive()) {
Point playerPosition = _player->getPosition();
if (playerPosition.x < _player->getContentSize().width) {
playerPosition.x = _player->getContentSize().width;
_player->setPosition(playerPosition);
}
else if (playerPosition.x > _ground->getContentSize().width -_player->getContentSize().width) {
_player->setPositionX(_ground->getContentSize().width -_player->getContentSize().width);
}
}
}
示例2: checkEntityCollision
/**
* Handles a numerous amount of collisions that happen in this game.
* Will detect if the player is colliding with an enemy or a ,
* or if an enemy is colliding with an enemy or bullet and then respond
* appropriately
*/
void checkEntityCollision() {
for(std::vector<Enemy*>::iterator iter = enemies.begin(); iter != enemies.end(); ++iter) {
Enemy * eni = *iter;
// Check if bullets are colliding with enemies
for(std::vector<Bullet*>::iterator checkAgainst = bullets.begin(); checkAgainst != bullets.end(); ++checkAgainst) {
Bullet * b = *checkAgainst;
if(eni->isColliding(*b)) {
eni->damage(*b);
b->damage(*eni);
score += 50;
}
}
// Check if player is colliding with enemies
if(p.isColliding(*eni)) {
Direction moveTo = eni->getDirection();
p.move(moveTo);
eni->move(eni->flipDirection(moveTo));
p.damage(*eni);
eni->damage(p);
p.setBlinking(true);
sf::SoundBuffer buffer;
buffer.loadFromFile("hit.wav");
sf::Sound sound;
sound.setBuffer(buffer);
sound.play();
}
// Check if sword is colliding with enemies
Sword * s = p.getSword();
if(s->swordColliding(*eni) && s->isSwung()) {
Direction moveTo = eni->getDirection();
eni->move(eni->flipDirection(moveTo), 200);
s->damage(*eni);
eni->damage(*s);
}
// Check if enemies are colliding with each other
for(std::vector<Enemy*>::iterator checkAgainst = enemies.begin(); checkAgainst != enemies.end(); ++checkAgainst) {
Enemy * next = *checkAgainst;
Enemy nexter = *next;
Direction moveTo = eni->flipDirection(eni->getDirection());
if(eni->isColliding(nexter) && (eni != next)) {
bool checkOverlap = true;
while(checkOverlap) {
eni->move(moveTo);
if(eni->isColliding(nexter) && (eni != next)) {
checkOverlap = true;
} else {
checkOverlap = false;
}
}
}
}
}
}