本文整理汇总了C++中Enemy::checkCollision方法的典型用法代码示例。如果您正苦于以下问题:C++ Enemy::checkCollision方法的具体用法?C++ Enemy::checkCollision怎么用?C++ Enemy::checkCollision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Enemy
的用法示例。
在下文中一共展示了Enemy::checkCollision方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
PlayerProjectile lemon = projectile;
if(player->getPlayerState() == Player::idleRight
|| player->getPlayerState() == Player::jumpRight
|| player->getPlayerState() == Player::runRight
|| player->getPlayerState() == Player::fallRight) {
lemon.setVelocity(7);
lemon.setSprite(PlayerProjectile::right);
} else {
//lemonSprite.setTexture(projectile.lemonLeft);
lemon.setVelocity(-7);
lemon.setSprite(PlayerProjectile::left);
}
lemon.setPosition(PlayerObject.getPosition());
ProjsInView.push_back(lemon);
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::C)){
if(player->Shoot()){
PlayerProjectile lemon = chargePro;
if(player->getPlayerState() == Player::idleRight
|| player->getPlayerState() == Player::jumpRight
|| player->getPlayerState() == Player::runRight
|| player->getPlayerState() == Player::fallRight) {
lemon.setVelocity(7);
lemon.setSprite(PlayerProjectile::right);
} else {
//lemonSprite.setTexture(projectile.lemonLeft);
lemon.setVelocity(-7);
lemon.setSprite(PlayerProjectile::left);
}
lemon.setPosition(PlayerObject.getPosition());
ProjsInView.push_back(lemon);
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
player->setDirection(Player::left);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
player->setDirection(Player::right);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && sf::Keyboard::isKeyPressed(sf::Keyboard::X)) {
player->setDirection(Player::left);
player->Shoot();
shotsFired++;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && sf::Keyboard::isKeyPressed(sf::Keyboard::X)) {
player->setDirection(Player::right);
player->Shoot();
shotsFired++;
}
if(player->boundingBox.getGlobalBounds().intersects(floorCollider.getGlobalBounds())){
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) {
player->Jump();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z) && sf::Keyboard::isKeyPressed(sf::Keyboard::X)){
player->Jump();
player->Shoot();
shotsFired++;
}
}
if (!sf::Keyboard::isKeyPressed(sf::Keyboard::Right) &&
!sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
player->setDirection(Player::none);
}
PlayerObject.move(player->getVelocity(), player->getGravity(floorCollider));
enemy->positionBounds(EnemyObject);
if(!enemy->checkCollision(player->boundingBox)){
EnemyObject.move(enemy->Move(EnemyObject), 0);
}
player->positionBounds(PlayerObject);
window.draw(background);
window.draw(floorCollider);
for(unsigned i = 0; i < world.TilesInView.size(); ++i){
RenderTiles(world.TilesInView[i]->getTiles(), world.TilesInView[i], window);
}
sf::Texture playerTex = player->Update();
sf::Texture enemyTex = enemy->Update();
//playerTex.setSmooth(false);
PlayerObject.setTexture(playerTex, true);
EnemyObject.setTexture(enemyTex, true);
RenderProjectiles(ProjsInView, window, projectile, player);
window.draw(EnemyObject);
window.draw(player->boundingBox);
window.draw(PlayerObject);
// Update the window
window.display();
}
if(!out.fail()){
accessStream(out, false, shotsFired);
//out << shotsFired;
//out << std::flush;
}
return 0;
}