void GoodNPC::attckCallBackAction(Node* pSender){ Rect attackRect = PublicFun::getAttackRect(this);//¹ÖÎï¹¥»÷ÇøÓò Rect hurtRect; for (NPC* npc : global->badNpcs) { if (!npc || npc->getActionState() == ActionStateDie) { continue; } hurtRect = PublicFun::getHurtRect(npc);// ÓѾüÊÜÉËÇøÓò if (attackRect.intersectsRect(hurtRect)) { npc->setAllowMove(false); damageDisplay(StringUtils::format("-%d", getAP()).c_str(), npc); npc->hurt(getAP(), 10); } } this->setActionState(ActionStateNone); this->setAllowMove(true); this->runIdleAction(); }
void Hero::normalAttackCallBackAction(Node* pSender) { /* //play sound effect if (this->currActionState == ACTION_STATE_NOMAL_ATTACK_A || this->currActionState == ACTION_STATE_NOMAL_ATTACK_B || this->currActionState == ACTION_STATE_NOMAL_ATTACK_C || this->currActionState == ACTION_STATE_NOMAL_ATTACK_D ) CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Sound/BladeBig2.mp3"); */ __Array *pEnemies; if (global->sceneInfoVector[global->sceneIndex]->bossFormatStr == NULL) { pEnemies = global->enemies; } else { pEnemies = global->bosses; } Ref *enemyObj = NULL; Size visibleSize = Director::getInstance()->getVisibleSize(); //判断是否可以放大招 if (this->getCurrMagicPoint() >= 100) { addUltimateSkill(); this->setCurrMagicPoint(0.0f); } CCARRAY_FOREACH(pEnemies, enemyObj) { Enemy *pEnemy = (Enemy*)enemyObj; if (fabsf(this->getPosition().y - pEnemy->getPosition().y < 20)) { Rect attackRect = m_hitBox.actual;//英雄攻击区域 Rect hurtRect = pEnemy->getBodyBox().actual;//怪物受伤区域 if (attackRect.intersectsRect(hurtRect)) { pEnemy->setAllowMove(false); //此处可处理怪物被攻击后的后续,产生伤害数字 int damage = random(this->getDamageStrength()*0.7, this->getDamageStrength()*1.3); hitCounter(); Vec2 point = pEnemy->getBodyBox().actual.origin; damageDisplay(damage, Vec2(point.x , point.y + 80)); pEnemy->runHurtAction(); enemyBloodDisplay(Vec2(point.x-10,point.y-10)); if (this->getCurrActionState() == ACTION_STATE_NOMAL_ATTACK_C || this->getCurrActionState() == ACTION_STATE_NOMAL_ATTACK_D) { if (getRoleDirection()) { pEnemy->setFlippedX(false); pEnemy->runHurtFlyLeftAction(); } else { pEnemy->setFlippedX(true); pEnemy->runHurtFlyRightAction(); } } //pEnemy->runHurtFlyLeftAction(); if (hitCount > 1) { combosDisplay(hitCount, Vec2(visibleSize.width *0.15, visibleSize.height * 0.75)); } pEnemy->setCurtLifeValue(pEnemy->getCurtLifeValue() - damage); if (pEnemy->getCurtLifeValue() <= 0) { pEnemy->runDeadAction(); pEnemy->setBodyBox(createBoundingBox(Vec2::ZERO, Size::ZERO)); pEnemy->setOpacity(124); float temp = this->getPosition().x - visibleSize.width / 2; float destX = (temp > 0) ? temp : 0; addDeadFire(Vec2(destX,visibleSize.height) ,pEnemy->getPosition()); pEnemy->setVisible(false); } } } }