Browse Source

主角动作测试,逻辑处理

FantasyUFG 5 years ago
parent
commit
c829494ad3

File diff suppressed because it is too large
+ 245 - 128
assets/scene/Game.fire


+ 1 - 1
assets/script/Game/Ai/AiPlayerStates.js

@@ -4,7 +4,7 @@ cc.Class({
     properties: {
 
     },
-    // onLoad () {},
+    onLoad() {},
 
     start() {
 

+ 7 - 5
assets/script/Game/Base/BaseCharactor.js

@@ -1,13 +1,15 @@
-
 cc.Class({
     extends: cc.Component,
 
     properties: {
-      
+
     },
-    // onLoad () {},
-    start () {
+    onLoad() {
 
     },
+    start() {
+
+    },
+
     // update (dt) {},
-});
+});

+ 3 - 5
assets/script/Game/Base/BaseGameStates.js

@@ -8,15 +8,13 @@ cc.Class({
         this.restTime = 0;
         this.currentTime = 0;
         this.player_name = "";
-        this.player_gold = 0;
-        this.player_energy = 0;
+        this.player_gold = 10000;
+        this.player_energy = 10001;
         this.player_sex = 0;
 
     },
     start() {
-        this.InformationChanges("set", 0, "AFHRFS");
-        this.InformationChanges("set", 1, 50);
-        this.InformationChanges("set", 2, 50);
+
     },
 
     // update (dt) {},

+ 27 - 4
assets/script/Game/Base/BasePlayerController.js

@@ -2,11 +2,34 @@ cc.Class({
     extends: cc.Component,
 
     properties: {
-       
+        //角色状态
+        RightJayShow: false, //出右拳
+        LeftJayShow: false, //出左拳
+
+        RightDodge: false, //右躲闪
+        LeftDodg: false, //左躲闪
+
+        Defence: false, //防御
+
+        Hurt: false,
+
+        CriticalStrike: false, //暴击
+
+        DoubleHit: false, //连击
+
+        BeCriticalStrike: false, //暴击
+
+        BeDoubleHit: false, //连击
+
+
+        Statepassivity: false, //被动状态
     },
-    // onLoad () {},
-    start () {
+    onLoad() {
+
+    },
+    start() {
 
     },
     // update (dt) {},
-});
+
+});

+ 76 - 5
assets/script/Game/Base/BasePlayerStates.js

@@ -4,16 +4,87 @@ cc.Class({
     properties: {
 
     },
-    // onLoad () {},
+    onLoad() {
+        this.hp = 110;
+        this.maxhp = 110; //血量
+        this.endurance = 100;
+        this.maxendurance = 100; //蓝量
+        this.damage = 11; //攻击力
+        this.defense = 3; //防御
+        this.combo_rate = 5; //连击率
+        this.crit_rate = 5; //暴击率
+        this.dodge_endurance = 10; //闪避回蓝
+        this.defense_hp = 11; //格挡回血
+        this.recover_hp = 1; //被动回血1/s
+        this.recover_endurance = 1; //被动回蓝1/s
+        this.block_minus_endurance = 10; //格挡减蓝量
+
+    },
 
     start() {
 
     },
-    //血量变化
-    //减血
-    oligemia() {
+
+    //#region 血量变化  是否暴击bool_crit  是否连击bool_combo
+    //减血  不暴击 不连击  hpnum=otherdamage-defense  连击hpnum*2
+    minusblood(oneself_hp) {
         console.log("血量减少");
-    }
+        let _oligemia = this.damage - this.defense;
+        oneself_hp -= _oligemia;
+        if (oneself_hp <= 0) {
+            oneself_hp = 0;
+        }
+    },
+    //加血 
+    //格挡加血 被动回血recover_hp, defense_hp  ---恢复血量类型 0被动回血 1格挡回血
+    addblood(oneself_maxhp, oneself_hp, heal_bool, heal_type) {
+        console.log("血量增加");
+        if (heal_bool) {
+            if (oneself_hp >= oneself_maxhp) {
+                oneself_hp == oneself_maxhp;
+                return;
+            }
+            if (heal_type == 0) { //被动回血 1/s
+                this.schedule(function() {
+                    oneself_hp += this.recover_hp;
+                }, 1);
+            }
+            if (heal_type == 1) { //格挡回血 11/次
+                oneself_hp += this.defense_hp;
+            }
+        }
+    },
+    //#endregion
 
     // update (dt) {},
+
+    //#region 蓝量变化
+    //减蓝  endurance-=this.block_minus_endurance
+    minusendurance(oneself_endurance) {
+        console.log("蓝量减少");
+        oneself_endurance -= this.block_minus_endurance;
+        if (oneself_endurance <= 0) {
+            oneself_endurance = 0;
+        }
+    },
+    //加蓝 
+    //闪避加蓝 被动回蓝recover_endurance, dodge_endurance  ---恢复蓝量类型 0被动回蓝 1闪避回蓝
+    addendurance(oneself_maxendurance, oneself_endurance, heal_bool, heal_type) {
+        console.log("蓝量增加");
+        if (heal_bool) {
+            if (oneself_endurance >= oneself_maxendurance) {
+                oneself_endurance == oneself_maxendurance;
+                return;
+            }
+            if (heal_type == 0) { //被动回蓝 1/s
+                this.schedule(function() {
+                    oneself_endurance += this.recover_endurance;
+                }, 1);
+            }
+            if (heal_type == 1) { //闪避回蓝 11/次
+                oneself_endurance += this.dodge_endurance;
+            }
+        }
+    }
+    //#endregion
 });

+ 12 - 6
assets/script/Game/GameStates.js

@@ -9,20 +9,21 @@ cc.Class({
 
     },
     onLoad() {
+        this._super();
+        //#region 
         // this.InformationChanges("set", "name", "小明");
         //let name = this.InformationChanges("get", "name");
         // console.log(a);
-        this.InformationChanges("set", 0, "小明");
-        this.InformationChanges("set", 1, 50);
-        this.InformationChanges("set", 2, 50);
-    },
-    start() {
+        // this.InformationChanges("set", 0, "小明");
+        // this.InformationChanges("set", 1, 50);
+        // this.InformationChanges("set", 2, 50);
+        //#endregion
 
         for (let i = 0; i < this.Player_infoArr.length; i++) {
             let info = this.InformationChanges("get", i);
             if (i == 1 || i == 2) {
                 if (info / 1000 > 1) {
-                    this.Player_infoArr[i].string = info / 1000 + "K";
+                    this.Player_infoArr[i].string = parseInt(info / 1000) + "K";
                 } else {
                     this.Player_infoArr[i].string = info;
                 }
@@ -30,6 +31,11 @@ cc.Class({
                 this.Player_infoArr[i].string = info;
             }
         }
+
+    },
+    start() {
+        //console.log("金币", this.player_gold);
+
     },
     // update (dt) {},
 

+ 77 - 5
assets/script/Game/Player/Charactor.js

@@ -1,32 +1,104 @@
 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.armature.animation.play("right_hit", 1);
+            this.node.emit("attack");
+        }
+        if (bLeft == 1) {
+            //左拳
+            this.armature.animation.play("left_fit", 1);
+            this.node.emit("attack");
+        }
+        //暴击
+        if (bLeft == 2) {
+            this.armature.animation.play("critical_strike", 1);
+            this.node.emit("attack_critical_strike");
+        }
+        //连击
+        if (bLeft == 3) {
+            this.armature.animation.play("double-hit", 1);
+            this.node.emit("attack_double-hit");
+        }
+    },
+    dodge(bLeft) { //躲闪
+
+        console.log("躲闪");
+        //发射躲闪事件 
+        if (bLeft == 0) {
+            //左躲闪
+            this.armatureDisplay.node.scaleX = 0.39;
+            this.armature.animation.play("dodge", 1);
+        }
+        if (bLeft == 1) {
+            //右躲闪
+            this.armatureDisplay.node.scaleX = -0.39;
+            this.armature.animation.play("dodge", 1);
+        }
+        this.node.emit("dodge");
     },
+    block() { //防御
+        this.armature.animation.play("block", 1);
+        this.node.emit("block");
+    },
+
+
     animationEventHandler(event) {
         if (event.type === dragonBones.EventObject.COMPLETE) {
+            //主角
             if (event.animationState.name === "attack") {
                 console.log("attack 动作播放完毕!!!");
                 //TODO:
                 this.armature.animation.play("idle", -1);
+                this.controScp._RightJayShow = false;
+                this.controScp._LeftJayShow = false;
+                this.controScp._CriticalStrike = false;
+                this.controScp._DoubleHit = false;
+            }
+            if (event.animationState.name === "dodge") {
+                console.log("dodge 动作播放完毕!!!");
+                //TODO:
+                this.armature.animation.play("idle", -1);
+                this.controScp._RightDodge = false;
+                this.controScp._LeftDodg = false;
+            }
+            if (event.animationState.name === "block") {
+                console.log("block 动作播放完毕!!!");
+                //TODO:
+                this.armature.animation.play("idle", -1);
+                this.controScp._Defence = false;
             }
         }
-    }
+    },
+    animationEventHandler_Enter(event) {
+
+    },
     // update (dt) {},
+    init() {
+        //角色脚本
+        this.controScp = this.PlayerController.getComponent('PlayerController');
+        //Ai脚本
+        this.aicontroScp = this.AiPlayerController.getComponent('AiPlayerController');
+    },
 });

+ 68 - 27
assets/script/Game/Player/PlayerController.js

@@ -2,50 +2,91 @@ cc.Class({
     extends: require("BasePlayerController"),
 
     properties: {
-        leftTouchNode: cc.Node,
-        rightTouchNode: cc.Node,
+        TouchNode: cc.Node,
         charactor: cc.Node,
     },
     onLoad() {
+        this._super();
+        this._Statepassivity = this.Statepassivity;
+        this._RightJayShow = this.RightJayShow; //出右拳
+        this._LeftJayShow = this.LeftJayShow; //出左拳
+
+        this._RightDodge = this.RightDodge; //右躲闪
+        this._LeftDodg = this.LeftDodg; //左躲闪
+
+        this._Defence = this.Defence; //防御
+
+        this._Hurt = this.Hurt;
+        this._CriticalStrike = this.CriticalStrike; //暴击
+        this._DoubleHit = this.DoubleHit; //连击
+        this._BeCriticalStrike = this.BeCriticalStrike; //被暴击
+        this._BeDoubleHit = this.BeDoubleHit; //被连击
         //注册回调事件
         let Self = this;
-        this.leftTouchNode.on('gesture', function(event) {
-            console.log(event.name);
-            Self.leftGesture(event.name);
-        })
 
-        this.rightTouchNode.on('gesture', function(event) {
+        this.TouchNode.on('gesture', function(event) {
             console.log(event.name);
-            Self.rightGesture(event.name);
-        })
+            Self.Gesture(event.name);
+        });
     },
     start() {
         this.init();
     },
     init() {
         //角色脚本
-        this.ctorScp = this.charactor.getComponent('baseCharactor');
+        this.ctorScp = this.charactor.getComponent('BaseCharactor');
+        this.statesScp = this.charactor.getComponent('PlayerStates');
     },
-    leftGesture(name) {
-        if (name == 'up') {
-            this.ctorScp.attack(1);
-        } else if (name == 'down') {
+    Gesture(name) {
+        var randomnum_1 = parseInt(Math.round(Math.random() * 98 + 1)); //(0-100]
+        var randomnum_2 = parseInt(Math.round(Math.random() + 1)); //[1-2]
+        console.log(randomnum_1, randomnum_2);
+        if (name == 'right_top') {
+            if (randomnum_1 >= 1 && randomnum_1 <= 10) {
+                //出现暴击或者连击
+                if (randomnum_2 == 1) {
+                    //暴击
+                    this._CriticalStrike = true;
+                    this.ctorScp.attack(2);
+                }
+                if (randomnum_2 == 2) {
+                    //连击
+                    this._DoubleHit = true;
+                    this.ctorScp.attack(3);
+                }
+            } else { //普攻状态 普攻动作
+                this._RightJayShow = true;
+                this.ctorScp.attack(1);
+            }
 
-        } else if (name == 'left') {
 
-        } else if (name == 'right') {
-            this.ctorScp.attack(1);
-        }
-    },
-    rightGesture(name) {
-        if (name == 'up') {
-            this.ctorScp.attack(0);
-        } else if (name == 'down') {
-
-        } else if (name == 'left') {
-            this.ctorScp.attack(0);
-        } else if (name == 'right') {
+        } else if (name == 'left_top') {
+            if (randomnum_1 >= 1 && randomnum_1 <= 10) {
+                //出现暴击或者连击
+                if (randomnum_2 == 1) {
+                    //暴击
+                    this._CriticalStrike = true;
+                    this.ctorScp.attack(2);
+                }
+                if (randomnum_2 == 2) {
+                    //连击
+                    this._DoubleHit = true;
+                    this.ctorScp.attack(3);
+                }
+            } else { //普攻状态 普攻动作
+                this._LeftJayShow = true;
+                this.ctorScp.attack(0);
+            }
 
+        } else if (name == 'right_down') {
+            this._RightDodge = true;
+            this.ctorScp.dodge(0);
+        } else if (name == 'left_down') {
+            this._LeftDodg = true;
+            this.ctorScp.dodge(1);
+        } else if (name == 'down') {
+            this._Defence = true;
+            this.ctorScp.block();
         }
     },
 

+ 50 - 1
assets/script/Game/Player/PlayerStates.js

@@ -2,12 +2,61 @@ cc.Class({
     extends: require("BasePlayerStates"),
 
     properties: {
-
+        playerController: cc.Node,
+        Charactor: cc.Node,
     },
     onLoad() {
+        this._super();
+        this._hp = this.hp;
+        this._maxhp = this.maxhp; //血量
+        this._endurance = this.endurance;
+        this._maxendurance = this.maxendurance; //蓝量
+        this._damage = this.damage; //攻击力
+        this._defense = this.defense; //防御
+        this._combo_rate = this.combo_rate; //连击率
+        this._crit_rate = this.crit_rate; //暴击率
+        this._dodge_endurance = this.dodge_endurance; //闪避回蓝
+        this._defense_hp = this.defense_hp; //格挡回血
+        this._recover_hp = this.recover_hp; //被动回血1/s
+        this._recover_endurance = this.recover_endurance; //被动回蓝1/s
+        this._block_minus_endurance = this.block_minus_endurance; //格挡减蓝量
+        this.init();
         //this.oligemia();//继承BasePlayerStates函数
+        this.Charactor.on("attack", function() {
+            console.log("检测到攻击1");
+        });
+        this.Charactor.on("attack_critical_strike", function() {
+            console.log("检测到暴击1");
+
+        });
+        this.Charactor.on("attack_double-hit", function() {
+            console.log("检测到连击1");
+        });
+        this.Charactor.on("dodge", function() {
+            console.log("检测到躲闪");
+        });
+        this.Charactor.on("block", function() {
+            console.log("检测到防御");
+            this.block();
+        });
+        this.Charactor.on("hurt", function() {
+            console.log("检测到受伤");
+
+        });
     },
     start() {
 
     },
+    init() {
+        //角色脚本
+        this.controScp = this.playerController.getComponent('PlayerController');
+        this.charactortroScp = this.Charactor.getComponent('Charactor');
+    },
+    block() { //防御
+        this.minusendurance(this._endurance); //减蓝
+    },
+    hurt() { //受伤
+        this.minusblood(this._hp); //减血
+    },
+    update(dt) {},
 });

+ 48 - 41
assets/script/Game/Touch.js

@@ -2,53 +2,60 @@ cc.Class({
     extends: cc.Component,
     properties: {
         // nodeArr:[cc.Node]
+        touchStartPoint: cc.Vec2,
+        touchEndPoint: cc.Vec2,
     },
-    onLoad () {
-        this.firstX = null;
-        this.firsty = null;
+    onLoad() {
 
-        this.node.on(cc.Node.EventType.TOUCH_START,this.touchBegin,this);
-        this.node.on(cc.Node.EventType.TOUCH_END,this.touchEnd,this);
+        this.node.on(cc.Node.EventType.TOUCH_START, this.ontouch_start, this);
+        this.node.on(cc.Node.EventType.TOUCH_END, this.ontouch_End, this);
 
         this.nodeArr = [];
     },
-    touchBegin:function(event)
-    {
-        let location = event.getLocation();// 获取节点坐标
-        this.firstX = location.x;
-        this.firstY = location.y;
+    ontouch_start(event) {
+        // 获取节点坐标
+        this.touchStartPoint = event.getLocation();
     },
     //以下部分参考用,具体识别用自己的算法
-    touchEnd:function(event)
-    {
-        let touchPoint = event.getLocation();
-        let endX = this.firstX - touchPoint.x;
-        let endY = this.firstY - touchPoint.y;
-    
-        if (Math.abs(endX) > Math.abs(endY)){
-            //手势向左右
-            //判断向左还是向右 
-            if (endX  > 0){
-                //向左函数
-                // console.log('left');
-                this.node.emit("gesture",{name:'left'});
-            } else {
-                //向右函数
-                // console.log('right');
-                this.node.emit("gesture",{name:'right'});
+    ontouch_End(event) {
+
+        this.touchEndPoint = event.getLocation();
+        this.calcDir();
+    },
+    calcDir: function() {
+        let dirvecX = this.touchEndPoint.x - this.touchStartPoint.x;
+        let dirvecY = this.touchEndPoint.y - this.touchStartPoint.y;
+
+        if (dirvecY >= 0) {
+            if (dirvecX > 0) {
+                //向右 上  出左拳
+                console.log("右上滑!");
+                this.node.emit("gesture", { name: 'right_top' });
+
+            } else if (dirvecX < 0) {
+
+                //向左上 出右拳
+                console.log("左上滑!");
+                this.node.emit("gesture", { name: 'left_top' });
+
             }
-        } else {
-            //手势向上下
-            //判断手势向上还是向下
-            if (endY  > 0){
-                //向下函数
-                // console.log('down');
-                this.node.emit("gesture",{name:'down'});
-            } else {
-                //向上函数
-                // console.log('up');
-                this.node.emit("gesture",{name:'up'});
+
+        } else if (dirvecY <= 0) {
+
+            if (dirvecX > 15) {
+                console.log("右下滑!");
+                this.node.emit("gesture", { name: 'right_down' });
+
+            } else if (dirvecX < -15) {
+
+                console.log("左下滑!");
+                this.node.emit("gesture", { name: 'left_down' });
+
+
+            } else if (dirvecX <= 15 && dirvecX >= -15) {
+                console.log("向下");
+                this.node.emit("gesture", { name: 'down' });
             }
-         }
-    }
-});
+        }
+    },
+});

Some files were not shown because too many files changed in this diff