本文整理汇总了C++中Enemy类的典型用法代码示例。如果您正苦于以下问题:C++ Enemy类的具体用法?C++ Enemy怎么用?C++ Enemy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Enemy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void EnemyManager::Update()
{
for (int i = 0; i < m_enemies->size(); i++)
{
Enemy* e = m_enemies->at(i);
if (e->hp < 0)
{
delete e;
m_enemies->erase(m_enemies->begin() + i);
i--;
continue;
}
e->Update();
}
}
示例2: Enemy
//================================================================================
// 生成処理
//================================================================================
Enemy* Enemy::create(const Vec2& pos,ENEMY_KIND nKindEnemy)
{
// インスタンスの生成
Enemy* pEnemy = new Enemy();
// メンバ変数の代入
pEnemy->m_pos = pos;
pEnemy->m_nEnemyKind = nKindEnemy;
// 初期化
pEnemy->init();
return pEnemy;
}
示例3: testEnemySet
// Tests for Enemy
void testEnemySet(void) {
setUp();
Enemy *enemy = new Enemy();
enemy->set(*tileSet, 0, 0);
Sprite * testSprite = new Sprite();
testSprite->setTexture(*tileSet);
testSprite->setTextureRect(IntRect(0, 0, 1, 1));
TS_ASSERT_DELTA(enemy->dx, ENEMY_SPEED, 0.01);
TS_ASSERT(enemy->life);
delete enemy;
breakDown();
}
示例4: Enemy
vector<Enemy*> CharacterFactory::parseXML(string xmlPath) {
// Read from file
XMLDocument doc;
doc.LoadFile(xmlPath.c_str());
// Text is just another Node to TinyXML-2. The more
// general way to get to the XMLText:
XMLElement *node = doc.FirstChildElement("enemies")->FirstChildElement("enemy")->ToElement();
for (node; node; node = node->NextSiblingElement())
{
Enemy* character = new Enemy();
character->parseXMLElement(node);
characters.push_back(character);
}
return characters;
}
示例5:
/**
* \brief Returns whether the hero can be hurt by an attacker in this state.
* \param attacker an attacker that is trying to hurt the hero
* (or nullptr if the source of the attack is not an enemy)
* \return true if the hero can be hurt in this state
*/
bool Hero::RunningState::can_be_hurt(Entity* attacker) const {
if (phase == 0) {
// Preparing to run.
return true;
}
if (attacker != nullptr && attacker->get_type() == EntityType::ENEMY) {
// TODO move get_can_hurt_hero_running to Entity.
Enemy* enemy = static_cast<Enemy*>(attacker);
return enemy->get_can_hurt_hero_running();
}
return false;
}
示例6: HandleBullets
// Public for enemy to call - handle bullet collision and damage applying
void Player::HandleBullets(Enemy& e)
{
if (!e.IsSpawned())
return;
for (int i = 0; i < m_Bullets.size(); i++)
{
if (e.DetectBulletCollision(m_Bullets[i]))
{
e.ApplyDamage(2);
m_Bullets.erase(m_Bullets.begin() + i);
i--;
continue;
}
}
}
示例7: Enemy
Enemy* Enemy::nodeWithTheGame(HelloWorld* game)
{
Enemy *pRet = new Enemy();
if (pRet && pRet->initWithTheGame(game))
{
pRet->autorelease();
return pRet;
}
else
{
delete pRet;
pRet = NULL;
return NULL;
}
}
示例8: ReadXmlEnemyData
EnemyManager::EnemyManager(char* filename, Ogre::SceneManager* _inMgr, Blocks* block_ent)
{
vData.clear();
vEnemy.clear();
ReadXmlEnemyData(filename);
for (int i = 0; i < vData.size(); i++) {
Ogre::Vector3 startPos = Ogre::Vector3(vData[i].x, vData[i].y, vData[i].z);
Ogre::Vector3 pos = block_ent->absToRealPos(startPos);
Enemy* enemy = new Enemy(_inMgr, Ogre::Vector3(pos.x, pos.y-25, pos.z), startPos);
vEnemy.push_back(enemy);
enemy->Initialize();
enemy->InitCmdVector(vData[i].vCmd);
}
}
示例9: Enemy
Enemy* Enemy::create ( KDuint uType )
{
Enemy* pRet = new Enemy ( );
if ( pRet && pRet->init ( uType ) )
{
pRet->autorelease ( );
}
else
{
CC_SAFE_DELETE ( pRet );
}
return pRet;
}
示例10: enemyBossUpdate
//////// Boss moves down into game screen ////////
//////// then begins its attack run ////////
void AI::enemyBossUpdate(Enemy &enemy, const float dt)
{
// Move into game screen
if (enemy.getPosition() < D3DXVECTOR3(0.0f, 20.0f, 0.0f)) // TODO: Modify for constant Y position value
{
D3DXVECTOR3 vel = D3DXVECTOR3(0.0f, -5.0f, 0.0f);
enemy.setVelocity(vel);
// Uncomment if needed
//enemy.setPosition(enemy.getPosition() += vel * dt);
}
else
{
// Begin attack run
// Fire bullets
float bFireRate = enemy.getBulletFireRate();
enemy.setBulletFireRate(bFireRate -= dt);
if (bFireRate <= 0.0f)
{
float x = -20.0f;
for (int i = 0; i < 4; i++)
{
enemy.fireBullet(D3DXVECTOR3(x, -20.0f, 0.0f));
x += 10.0f;
}
enemy.setBulletFireRate(1.0f);
}
// Fire missiles
float missFireRate = enemy.getMissileFireRate();
enemy.setMissileFireRate(missFireRate -= dt);
if (missFireRate <= 0.0f)
{
enemy.fireMissile(D3DXVECTOR3(0.0f, -20.0f, 0.0f));
enemy.setMissileFireRate(10.0f);
}
// Fire mines
// Cannot specify where to drop mine
// Mines are listed as a pickup, are they intended to be picked up by the player?
/*float mineFireRate = enemy.getMineFireRate();
enemy.setMineFireRate(mineFireRate -= dt);
if (mineFireRate <= 0.0f)
{
}*/
}
}
示例11: Enemy
void LevelGenerator::spawnEnemy(core::Siika2D *siika, int xPos, int yPos)
{
Enemy *e;
bool fly = false;
if (lrand48() % 3 == 0)
fly = true;
int frames = 0;
int speed = 200;
if (fly)
{
if (generatorName == "castle")
e = new Enemy("sprite_mikucopter.png");
else if (generatorName == "plains")
e = new Enemy("sprite_noodles.png");
else
{
e = new Enemy("sprite_shibat.png");
yPos += 80;
}
}
else
{
if (generatorName == "castle")
e = new Enemy("sprite_meido.png");
else if (generatorName == "forest")
e = new Enemy("sprite_shimapanda.png");
else
{
e = new Enemy("sprite_gigapuddi.png", true);
speed = 100;
frames = 8;
}
}
e->init(siika, 0, frames, speed);
e->xPos = xPos;
e->yPos = yPos;
e->yLevel = e->yPos;
if (fly)
e->flies = true;
e->go->move(glm::vec2(e->xPos, e->yPos));
enemies.push_back(e);
}
示例12: Enemy
Enemy* Enemy::create(CCPoint position, const char* fileName)
{
//エネミー生成
Enemy* enemy = new Enemy();
if (enemy)
{
enemy->initEnemy(position, fileName);
enemy->autorelease();
GAME::getInstance()->addChild(enemy, kTag_Enemy, kOrder_Enemy);
return enemy;
}
//autoreleaseを使用しているため、deleteの代わりに使用、メモリを開放
//何度も生成しないようにガードをかける
CC_SAFE_DELETE(enemy);
return NULL;
}
示例13: Fire
// Attempt to fire at enemy; return true if destroyed
bool Tower::Fire(Enemy &enemy, vector <Bullet> &Shots)
{
if (reloadTime <= 0)
{
double dx, dy, towerX, towerY, enemyX, enemyY;
towerX = (gridX + .5)*TILESIZE;
towerY = (gridY + .5)*TILESIZE;
enemyX = enemy.x + .5*TILESIZE;
enemyY = enemy.y + .5*TILESIZE;
dx = enemyX - towerX;
dy = enemyY - towerY;
if (dx*dx + dy*dy <= range*range)
{
double angle = atan2(dy, dx)/M_PI + 1;
direction = (int)((4*(angle))+6.5)%8;
reloadTime+=1./rate;
angle = (direction+2)*M_PI/4;
int bulletX = towerX - TILESIZE*cos(angle)/2;
int bulletY = towerY - TILESIZE*sin(angle)/2;
Shots.push_back(Bullet(bulletX, bulletY,
enemyX, enemyY));
if (enemy.damage(power))
{
return true;
}
}
}
return false;
};
示例14: update
double Player::update(const Enemy& enemy) {
vec3 el = enemy.getLoc();
vel += (el-loc).norm() * 6000 / (pow((el-loc).abs(),1.83)+80);
if((el-loc).abs() < 250) return 0.005;
return 0;
}
示例15: notify_collision_with_enemy
/**
* \brief This function is called when an enemy's sprite collides with a sprite of this entity.
* \param enemy the enemy
* \param enemy_sprite the enemy's sprite that overlaps the hero
* \param this_sprite the arrow sprite
*/
void Hookshot::notify_collision_with_enemy(
Enemy& enemy, Sprite& enemy_sprite, Sprite& /* this_sprite */) {
if (!overlaps(get_hero())) {
enemy.try_hurt(EnemyAttack::HOOKSHOT, *this, &enemy_sprite);
}
}