[Cocos2d塔防游戏开发]Cocos2dx-3.X完成塔防游戏《王国保卫战》--防御塔(五)之高级箭塔

该章节主要介绍高级箭塔

2级和3级箭塔与初级箭塔只是替换了图片并且将攻击力、射程等提高,其他并无区别

高级箭塔也是高级塔中最好设计的,通过替换一些图片,增加例如发光的眼睛,飞翔的老鹰等动画即可。

不同之处在于增加1-2个技能

例如下方CossbowHunterTower,在shoot中增加一个技能,添加一个Int类型attackCount,每次攻击加1,每4次攻击使用1次技能。

这个塔技能设计的比较简单(不同原作),技能即秒杀效果,直接爆头,播放一个发光动画即可,具体代码参加github上


上方的TotemTower塔在于会根据周围敌人数量扔两种不同的图腾(原作不同情况用的图腾不同,本作没有设置这个功能,读者可自行设计),重载checknearestMonster,并且设置个bool类型设置为两个技能的CD,每隔5秒将该类型设置为true

void TotemTower::checkNearestMonster()
{
    monstersCount = 0;
    auto instance = GameManager::getInstance();
    auto monsterVector = instance->monsterVector;
    
    auto currMinDistant = this->scope;
    
    BaseMonster *monsterTemp = NULL;
    for(int i = 0; i < monsterVector.size(); i++)
    {
	auto monster = monsterVector.at(i);
	double distance = this->getParent()->getPosition().getDistance(monster->baseSprite->getPosition());

	if (distance < currMinDistant && monster->getAttackByTower()) {
	    currMinDistant = distance;
            monsterTemp = monster;
	    monstersCount++;//计算周围敌人个数
	    }
	}
    nearestMonster = monsterTemp;
}

重载shoot函数,当敌人个数大于5个且技能CD变量为true即释放技能,其他操作与初级箭塔类似

if(totemCD){
    SoundManager::playTotemSpirits();
    auto redTotem = RedTotem::create();
    this->getParent()->addChild(redTotem);
    redTotem->shoot(nearestMonster->baseSprite->getPosition() - this->getParent()->getPosition() + Point(20,20));

    auto violetTotem = VioletTotem::create();
    this->getParent()->addChild(violetTotem);
    violetTotem->shoot(nearestMonster->baseSprite->getPosition() - this->getParent()->getPosition()- Point(20,20));
    totemCD = false;
}


释放技能的图腾也是个继承与子弹类的子类,与炮塔的炮弹类似

void VioletTotem::shoot(Point point)
{
    this->setPosition(point);设置位置
    sprite->runAction(Sequence::create(//播放动画序列
        CallFuncN::create(CC_CALLBACK_0(VioletTotem::boom,this)),//首先播放爆炸动画
	Animate::create(AnimationCache::getInstance()->getAnimation("TotemTower_VioletTotem")),//播放图腾自毁动画
	CallFuncN::create(CC_CALLBACK_0(VioletTotem::removeBullet,this)),NULL));//爆炸,与炮弹类类似
}

以上就是高级箭塔,比较简单

猜你喜欢

转载自blog.csdn.net/oShunz/article/details/49403453