Cocos classic game tutorial imitation of the royal war

Copyright Notice:

  • Original article published on the blog Park "You dream maker culture," the blog space (URL: http://www.cnblogs.com/raymondking123/) and micro-channel public number "dream maker culture"
  • You are free to reprint, but must include the full copyright notice!

Client

Achieve troops landed status

  • The army will enter an idle state status to move into the state ArmyCallState
OnEnter(){
    // TODO: 选择路点,进入ArmyCallState
    this.card.fsm.ChangeState(ArmyCallState);
}
  • Realized ArmyCallState class in ArmyCallState script (script is written ArmyCallState)

Increase playback walking in the army moving state of the animation feature

//取得军队移动方向与上方向之间的弧度
let radian = dir.signAngle(cc.Vec2.UP);
//将弧度转为角度
let angle = cc.misc.radiansToDegrees(radian);

//如果军队移动方向与上方向的夹角在 -45到45之间,说明军队移动的方向是偏向上方的
if (angle > -45 && angle < 45) {
    let clip = this.animation.getClips()[0]; //取得往上走的动画片段
    if (this.animation.currentClip != clip) { //如果当前播放的动画不是往上走的动画
        this.animation.play(clip.name); //播放往上走的动画
    }
}
else if (angle > 135 || angle < -135) { //下
    let clip = this.animation.getClips()[1]; //下走
    if (this.animation.currentClip != clip) {
        this.animation.play(clip.name);
    }
}
else if (angle >= -135 && angle <= -45) { //左
    let clip = this.animation.getClips()[2]; //左走
    if (this.animation.currentClip != clip) {
        this.animation.play(clip.name);
    }
}
else if (angle >= 45 && angle <= 135) { //右
    let clip = this.animation.getClips()[3]; //右走
    if (this.animation.currentClip != clip) {
        this.animation.play(clip.name);
    }
}

In the state of the army moving in increasing access speed and waypoints index

//取得初始路点(桥)
let initialWaypoint = WayMgr.instance.ways[this.wayIdx].nodes[0].position;
//取得终点(国王塔位置)
let destination = WayMgr.instance.ways[this.wayIdx].nodes[1].position;
//如果玩家到国王塔的距离 小于 桥到国王塔的距离
if(destination.sub(this.card.pos).mag()<destination.sub(initialWaypoint).mag()){
    this.wpIdx = 1; //就将路点索引设为1(就是直接往国王塔走)
}

let moveSpeed = this.card.propsTmp.mspd //获取模板属性中的移动速度(枚举值)
if(moveSpeed == MoveSpeed.Invalid){ //如果速度是无效
    this.spd = 0;
}
else if(moveSpeed == MoveSpeed.VeryFast){ //非常快
    this.spd = 50;
}
else if(moveSpeed == MoveSpeed.Fast){ //快
    this.spd = 40;
}
else if(moveSpeed == MoveSpeed.Mid){ //正常
    this.spd = 30;
}
else if(moveSpeed == MoveSpeed.Slow){ //慢
    this.spd = 20;
}
else if(moveSpeed == MoveSpeed.VerySlow){ //非常慢
    this.spd = 10;
}

Adding functionality to track enemy movement in the army

  • Players get an enemy combatant
  • Traversing the array of enemy combatants fight card players
  • Find fight card from the nearest enemy this fight card from enemy combatants card array
  • If that enemy combatants cards go out into the enemy where to go in the vision of this fight card
  • If that enemy combatants in this fight card card into the scope of the attack on the army to attack state

Guess you like

Origin www.cnblogs.com/raymondking123/p/11326265.html