CCARRAY_FOREACH(pEnemies, enemyObj) { Enemy *pEnemy = (Enemy*)enemyObj; if (pEnemy->getCurrActionState() != ACTION_STATE_DEAD) { break; } global->enemiesAllDie = true; }
void GameLayer::onHeroAttack() { if(m_pHero->isLive()) { m_pHero->runAttackAction(); if(m_pHero->getCurrActionState() == ACTION_STATE_ATTACK) { Object *enemyObj = NULL; CCARRAY_FOREACH(m_pEnemies, enemyObj) { Enemy *pEnemy = (Enemy*)enemyObj; if(pEnemy->getCurrActionState() >= ACTION_STATE_DEAD) { continue; } if(fabsf(m_pHero->getPosition().y - pEnemy->getPosition().y) < 10) { BoundingBox heroHitBox = m_pHero->getHitBox(); BoundingBox enemyBodyBox = pEnemy->getBodyBox(); if(::collisionDetection(heroHitBox, enemyBodyBox)) { int damage = m_pHero->getAttack(); pEnemy->runHurtAction(); pEnemy->setHP(pEnemy->getHP() - damage); if(pEnemy->getHP() <= 0) { pEnemy->runDeadAction(); } CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(PATH_HERO_HIT_EFFECT); } } }