bool EnemyController::withinReach(void) { EnemyPlane* enemy = static_cast<EnemyPlane*>(IDManager::getPointer(_enemyName, ACTOR)); double distance = enemy->getPosition().distance(FCKnowledge::getSingleton().getPlayerPosition()); return distance < 100.0; }
void EnemyController::approach(void) { EnemyPlane* enemy = static_cast<EnemyPlane*>(IDManager::getPointer(_enemyName, ACTOR)); Ogre::Vector3 temp = FCKnowledge::getSingleton().getPlayerPosition() - enemy->getPosition(); Ogre::Vector3 direction = temp * enemy->getAxis(); //std::cout<<direction.x<<" "<<direction.y<<" "<<direction.z<<std::endl; if(direction.angleBetween(Ogre::Vector3::NEGATIVE_UNIT_Z) >= Ogre::Radian(Ogre::Degree(1))) { Ogre::Quaternion test = direction.getRotationTo(Ogre::Vector3::NEGATIVE_UNIT_Z); Ogre::Degree angle = enemy->getRotateLimit(); double yawNum = test.getYaw().valueDegrees()/(angle*WORLD_UPDATE_INTERVAL).valueDegrees(); yawNum = Ogre::Math::Clamp(yawNum, -1.0, 1.0); enemy->yaw(yawNum); double pitchNum = test.getPitch().valueDegrees()/(angle*WORLD_UPDATE_INTERVAL).valueDegrees(); pitchNum = Ogre::Math::Clamp(pitchNum, -1.0, 1.0); enemy->pitch(pitchNum); double rollNum = test.getRoll().valueDegrees()/(angle*WORLD_UPDATE_INTERVAL).valueDegrees(); rollNum = Ogre::Math::Clamp(rollNum, -1.0, 1.0); enemy->roll(rollNum); } else { enemy->yaw(0); enemy->pitch(0); enemy->roll(0); } }
void EnemyPlaneLayer::enemyPlaneDeadCallBack(CCObject *obj) { EnemyPlane* enemyPlane = dynamic_cast<EnemyPlane*>(obj); if(enemyPlane){ enemyPlane->removeFromParent(); enemyPlane->retrieve(); } }
EnemyPlane* EnemyPlane::createWithSpriteFrameName(const char* spriteFrameName){ EnemyPlane* pPlane = new EnemyPlane; if (pPlane&&pPlane->initWithSpriteFrameName(spriteFrameName)){ pPlane->autorelease(); return pPlane; } CC_SAFE_RELEASE(pPlane); return NULL; }
void MyBullet::hit(float dt) { EnemyPlane *pEnemyPlane = EnemyPlane::getSharedEnemyPlane(); for (int i = 0; i < m_pArrayOfBullet->count(); ) { CCBullet *pCurBullet = (CCBullet*) m_pArrayOfBullet->objectAtIndex(i); if (pEnemyPlane->hitByBullet(pCurBullet, DEFAULT_POWER)) isOver(pCurBullet); else i++; } }
void EditorWeapon::groupFireEnd() { EnemyPlane* plane = dynamic_cast<EnemyPlane*>(this->getParent()->getParent()); if(plane && plane->m_isAutoFire && !plane->m_haveCallBack) { plane->m_haveCallBack = true; plane->runAction(Sequence::create(DelayTime::create(this->fireGroupInterval),CallFunc::create(CC_CALLBACK_0(EnemyPlane::StartFire,plane)), nullptr)); } if(this->isOneTime) { // this->unscheduleUpdate(); this->unschedule(CC_SCHEDULE_SELECTOR(EditorWeapon::mainLoop)); this->removeFromParent(); } }
void PlayerTrackBomb::SelectTarget() { POSITION pos = list_->GetHeadPosition(); while (pos != NULL) { EnemyPlane *p = (EnemyPlane *)list_->GetNext(pos); if (!p->GetLock()) { p->Lock(); plane_ = p; return; } } Killed(); }
EnemyPlane* EnemyPlane::create(DefaultPlane* const player_plane) { EnemyPlane* pSprite = new EnemyPlane(player_plane); if (pSprite->initWithFile("enemyplane.png")) { pSprite->autorelease(); pSprite->initOptions(); pSprite->addEvents(); pSprite->ChangeBehavoiur(player_plane); return pSprite; } CC_SAFE_DELETE(pSprite); return NULL; }
void EnemyController::fire(void) { EnemyPlane* enemy = static_cast<EnemyPlane*>(IDManager::getPointer(_enemyName, ACTOR)); enemy->fire(); //std::cout << enemy->getName()<<std::endl; }
void EnemyPlaneLayer::loadEnemys() { //当一批飞机全部添加后,此批敌机没有被消灭干净前,不再增加下批敌机 if((EnemyPlane::_enemyPlanes.count() > 0)){ delayTimerCallLoadEnemys(1.0f); return; } static int batchIndex = 0; //第几批敌机 float aircraftTimeSum = 0; //每批敌机出场时间和 //当前批敌机数组 CCArray* batchEnemys = dynamic_cast<CCArray*>(m_enemyPlanesArray.objectAtIndex(batchIndex)); CCObject* obj = NULL; CCARRAY_FOREACH(batchEnemys,obj){ CCDictionary* enemyDict = dynamic_cast<CCDictionary*>(obj); //当前敌机属性字典,获取敌机出场时间 GameObjectPool* factory = EnemyPlaneFactory::shareEnemyPlaneFactory(); EnemyPlane* enemyPlane = NULL; if(factory) { enemyPlane = dynamic_cast<EnemyPlane*>(factory->getObject(enemyDict)); //调式用的全局敌机变量 _enemyPlane = enemyPlane; //设置被碰撞粒子效果的文件名 enemyPlane->setHitParticleName(NORMAL_HIT_PARTICLE_PLIST); //粒子效果的父层需要是非批渲染层 enemyPlane->setBatchParticleNodesParent(this); //计算出场时间之和 aircraftTimeSum += enemyPlane->getAircraftTime(); //计算出场位置 srand((unsigned) time(NULL)); float t = enemyPlane->getScale(); int t1 = rand(); float widthRange = CCDirector::sharedDirector()->getWinSize().width - enemyPlane->boundingBox().size.width * enemyPlane->getScale(); float startPositionX = enemyPlane->boundingBox().size.width / 2 * enemyPlane->getScale() + rand() % int(widthRange); float startPositionY = CCDirector::sharedDirector()->getWinSize().height + enemyPlane->boundingBox().size.height * enemyPlane->getScale() + 10; startPositionX = CCDirector::sharedDirector()->getWinSize().width / 2; enemyPlane->setPosition(ccp(startPositionX,startPositionY)); enemyPlane->prepareFly(); CCSpriteBatchNode* batchNode = AppConfig::shareAppConfig()->getGlobalBatchNode(); enemyPlane->setBullteFlySpace(batchNode); batchNode->addChild(enemyPlane,ENEMY_PLANE_ZORDER); } }