| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- cc.Class({
- extends: require("BaseCharactor"),
- properties: {
- PlayerController: cc.Node,
- AiPlayerController: cc.Node,
- },
- onLoad() {
- this._super();
- this.armatureDisplay = this.node.getComponent(dragonBones.ArmatureDisplay);
- this.armature = this.armatureDisplay.armature();
- //添加动画事件监听
- this.armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this);
- this.armatureDisplay.addEventListener(dragonBones.EventObject.FRAME_EVENT, this.animationEventHandler_Enter, this);
- },
- start() {
- this.init();
- },
- attack(bLeft) {
- //发射攻击事件 // 普攻
- if (bLeft == 0) {
- //右拳
- // this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("left_fit", 1);
- this.node.emit("attack");
- } else if (bLeft == 1) {
- //左拳
- // this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("right_fit", 1);
- this.node.emit("attack");
- }
- //暴击右
- else if (bLeft == 2) {
- this.armatureDisplay.node.scaleX = -0.39;
- this.armature.animation.play("double_hit", 1);
- this.node.emit("attack_critical_strike");
- }
- //暴击左
- else if (bLeft == 3) {
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("double_hit", 1);
- this.node.emit("attack_critical_strike");
- }
- //连击右
- else if (bLeft == 4) {
- this.armatureDisplay.node.scaleX = -0.39;
- this.armature.animation.play("critical_strike", 1);
- this.node.emit("attack_double-hit");
- }
- //连击
- else if (bLeft == 5) {
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("critical_strike", 1);
- this.node.emit("attack_double-hit");
- }
- },
- dodge(bLeft) { //躲闪
- //发射躲闪事件
- if (bLeft == 0) {
- //左躲闪
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("dodge", 1);
- } else if (bLeft == 1) {
- //右躲闪
- this.armatureDisplay.node.scaleX = -0.39;
- this.armature.animation.play("dodge", 1);
- }
- this.node.emit("dodge");
- },
- hurt(bLeft, type) { ////挨打 左右拳,击打类型
- //发射挨打事件
- if (type == 0) {
- if (bLeft == 0) {
- //左挨打
- // this.armatureDisplay.node.scaleX = 0.39;
- //this.armature.animation.play("be_beaten_right", 1);
- } else if (bLeft == 1) {
- //右挨打
- // this.armatureDisplay.node.scaleX = -0.39;
- //this.armature.animation.play("be_beaten_left", 1);
- }
- this.node.emit("hurt_ord");
- }
- if (type == 1) {
- if (bLeft == 0) {
- //左挨打
- //被暴打
- // this.armatureDisplay.node.scaleX = -0.39;
- // this.armature.animation.play("be_double_hit", 1);
- } else if (bLeft == 1) {
- //被暴打
- //右挨打
- // this.armatureDisplay.node.scaleX = 0.39;
- // this.armature.animation.play("be_double_hit", 1);
- }
- this.node.emit("hurt_critical");
- }
- if (type == 2) {
- if (bLeft == 0) {
- //被连击打
- //左挨打
- // this.armatureDisplay.node.scaleX = -0.39;
- // this.armature.animation.play("be_critical_strike", 1);
- } else if (bLeft == 1) {
- //被连击打
- //右挨打
- // this.armatureDisplay.node.scaleX = 0.39;
- // this.armature.animation.play("be_critical_strike", 1);
- }
- this.node.emit("hurt_double");
- }
- },
- block() { //防御
- this.armature.animation.play("block", 1);
- this.node.emit("block");
- },
- animationEventHandler(event) {
- if (event.type === dragonBones.EventObject.COMPLETE) {
- //主角
- if (event.animationState.name === "left_fit") {
- // console.log("attack 动作播放完毕!!!");
- //TODO:
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("idle", 0);
- this.controScp._RightJayShow = false;
- this.controScp._LeftJayShow = false;
- this.aicontroScp._Statepassivity = false;
- }
- if (event.animationState.name === "right_hit") {
- // console.log("attack 动作播放完毕!!!");
- //TODO:
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("idle", 0);
- this.controScp._RightJayShow = false;
- this.controScp._LeftJayShow = false;
- this.aicontroScp._Statepassivity = false;
- }
- if (event.animationState.name === "double_hit") {
- // console.log("critical_strike 动作播放完毕!!!");
- //TODO:
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("idle", 0);
- this.controScp._CriticalStrike = false;
- this.aicontroScp._Statepassivity = false;
- }
- if (event.animationState.name === "critical_strike") {
- // console.log("critical_strike 动作播放完毕!!!");
- //TODO:
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("idle", 0);
- this.controScp._CriticalStrike = false;
- this.aicontroScp._Statepassivity = false;
- }
- if (event.animationState.name === "be_beaten_left" || event.animationState.name === "be_beaten_right") {
- // console.log("double-hit 动作播放完毕!!!");
- //TODO:
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("idle", 0);
- this.controScp._DoubleHit = false;
- this.aicontroScp._Statepassivity = false;
- }
- if (event.animationState.name === "dodge") {
- // console.log("dodge 动作播放完毕!!!");
- //TODO:
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("idle", 0);
- this.controScp._RightDodge = false;
- this.controScp._LeftDodg = false;
- }
- if (event.animationState.name === "block") {
- // console.log("block 动作播放完毕!!!");
- //TODO:
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("idle", 0);
- this.controScp._Defence = false;
- }
- if (event.animationState.name === "be_beaten_left" || event.animationState.name === "be_critical_strike" ||
- event.animationState.name === "be_double_hit" || event.animationState.name === "be_beaten_right") {
- // console.log("be_beaten 动作播放完毕!!!");
- //TODO:
- this.armatureDisplay.node.scaleX = 0.39;
- this.armature.animation.play("idle", 0);
- this.controScp._Defence = false;
- this.aicontroScp._Statepassivity = false;
- }
- }
- },
- animationEventHandler_Enter(event) {
- },
- // update (dt) {},
- init() {
- //角色脚本
- this.controScp = this.PlayerController.getComponent('PlayerController');
- //Ai脚本
- this.aicontroScp = this.AiPlayerController.getComponent('AiPlayerController');
- },
- });
|