[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));//爆炸,与炮弹类类似
}

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值