소스 검색

对打,交互,AI 玩家数据实现

FantasyUFG 5 년 전
부모
커밋
7fc5026942

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 2707 - 135
assets/scene/Game.fire


+ 3 - 1
assets/script/Game/Ai/AiCharactor.js

@@ -92,6 +92,7 @@ cc.Class({
                 this.armatureDisplay.node.scaleX = 1;
                 this.armature.animation.play("be_beaten", 1);
             }
+            this.node.emit("hurt_ord");
         }
         if (type == 1) {
             console.log("Ai挨暴打");
@@ -107,6 +108,7 @@ cc.Class({
                 this.armatureDisplay.node.scaleX = 1;
                 this.armature.animation.play("be_critical_strike", 1);
             }
+            this.node.emit("hurt_critical");
         }
         if (type == 2) {
             console.log("Ai挨连打");
@@ -122,8 +124,8 @@ cc.Class({
                 this.armatureDisplay.node.scaleX = 1;
                 this.armature.animation.play("be_double_hit", 1);
             }
+            this.node.emit("hurt_double");
         }
-        this.node.emit("be_beaten");
     },
     block() { //防御
         this.armature.animation.play("block", 1);

+ 13 - 3
assets/script/Game/Ai/AiPlayerController.js

@@ -4,6 +4,7 @@ cc.Class({
     properties: {
         charactor: cc.Node,
         PlayerController: cc.Node,
+        PlayerctorScp: cc.Node,
     },
     onLoad() {
         this._super();
@@ -29,7 +30,7 @@ cc.Class({
 
         this.schedule(function() {
             this.onAttck_Ai();
-        }, 1.5);
+        }, 1);
 
         //}, 5.5);
     },
@@ -37,6 +38,8 @@ cc.Class({
         //角色脚本
         this.ctorScp = this.charactor.getComponent('AiCharactor');
         this.PlayerControScp = this.PlayerController.getComponent('PlayerController');
+        //角色脚本
+        this.playerctorScp = this.PlayerctorScp.getComponent('Charactor');
     },
     update(dt) {
 
@@ -112,7 +115,9 @@ cc.Class({
                     this.ctorScp.attack(2);
                     // this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
                     if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
-                        this.PlayerControScp._Hurt = true;
+                        this.PlayerControScp._BeCriticalStrike = true;
+                        this.playerctorScp.hurt(0, 1); //左暴击
+
                     }
                 }
                 if (randomnum_2 == 2) {
@@ -121,7 +126,8 @@ cc.Class({
                     this.ctorScp.attack(4);
                     //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
                     if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
-                        this.PlayerControScp._Hurt = true;
+                        this.PlayerControScp._BeDoubleHit = true;
+                        this.playerctorScp.hurt(0, 2); //左连击
                     }
                 }
             } else { //普攻状态 普攻动作
@@ -130,6 +136,7 @@ cc.Class({
                 //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
                 if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
                     this.PlayerControScp._Hurt = true;
+                    this.playerctorScp.hurt(0, 0); //左击
                 }
             }
 
@@ -144,12 +151,14 @@ cc.Class({
                     this._CriticalStrike = true;
                     this.ctorScp.attack(2);
                     //this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
+                    this.playerctorScp.hurt(1, 1); //右暴击
                 }
                 if (randomnum_2 == 2) {
                     //连击
                     this._DoubleHit = true;
                     this.ctorScp.attack(4);
                     //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
+                    this.playerctorScp.hurt(1, 2); //右连击
                 }
             } else { //普攻状态 普攻动作
                 this._RightJayShow = true;
@@ -157,6 +166,7 @@ cc.Class({
                 //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
                 if (!this.PlayerControScp._LeftDodg && !this.PlayerControScp._Defence) {
                     this.PlayerControScp._Hurt = true;
+                    this.playerctorScp.hurt(1, 0); //右击
                 }
             }
 

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

@@ -2,12 +2,80 @@ cc.Class({
     extends: require("BasePlayerStates"),
 
     properties: {
+        playerController: cc.Node,
+        Charactor: cc.Node,
+
+        progressBar_hp: cc.Node,
+        progressBar_endur: 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.schedule(() => {
+            this._hp = this.addblood(this._maxhp, this._hp, 0);
+            this._endurance = this.addendurance(this._maxendurance, this._endurance, 0);
+            console.log("Ai被动", this._hp, this._endurance);
+        }, 1);
 
     },
-    onLoad() {},
 
     start() {
+        this.Charactor.on("attack", () => {
+            //console.log("检测到攻击2");
+        });
+        this.Charactor.on("attack_critical_strike", () => {
+            //console.log("检测到暴击2");
+
+        });
+        this.Charactor.on("attack_double-hit", () => {
+            //console.log("检测到连击2");
+
+        });
+        this.Charactor.on("dodge", () => {
+            //console.log("检测到躲闪2");
+            this.addendurance(this._maxendurance, this._endurance, 1); //闪避回蓝
+            this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
+        });
+        this.Charactor.on("block", () => {
+            // console.log("检测到防御2");
+            this._endurance = this.minusendurance(this._endurance); //减蓝
+            this._hp = this.addblood(this._maxhp, this._hp, 1); //回血
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
+            this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
+        });
+        this.Charactor.on("hurt_ord", () => {
+            // console.log("检测到受普攻");
+            this._hp = this.minusblood(this._hp);
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
+        });
+        this.Charactor.on("hurt_critical", () => {
+            //console.log("检测到受暴击");
+            this._hp = this.minusblood_critical(this._hp);
+            //console.log("暴击后的血量:", this._hp);
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
+        });
+        this.Charactor.on("hurt_double", () => {
+            //console.log("检测到受连攻");
+            this._hp = this.minusblood(this._hp);
 
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
+            this._hp = this.minusblood(this._hp);
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
+        });
     },
 
     // update (dt) {},

+ 11 - 2
assets/script/Game/Base/BaseGameStates.js

@@ -5,7 +5,7 @@ cc.Class({
 
     },
     onLoad() {
-        this.restTime = 0;
+        this.restTime = 12;
         this.currentTime = 0;
         this.player_name = "";
         this.player_gold = 10000;
@@ -48,5 +48,14 @@ cc.Class({
             }
         }
 
-    }
+    },
+    //时间减少
+    countdown(currentTime) {
+        currentTime--;
+        if (currentTime <= 0) {
+            currentTime = 0;
+        }
+        return currentTime;
+    },
+
 });

+ 46 - 31
assets/script/Game/Base/BasePlayerStates.js

@@ -19,12 +19,12 @@ cc.Class({
         this.recover_endurance = 1; //被动回蓝1/s
         this.block_minus_endurance = 10; //格挡减蓝量
 
+
     },
 
     start() {
 
     },
-
     //#region 血量变化  是否暴击bool_crit  是否连击bool_combo
     //减血  不暴击 不连击  hpnum=otherdamage-defense  连击hpnum*2
     minusblood(oneself_hp) {
@@ -34,25 +34,38 @@ cc.Class({
         if (oneself_hp <= 0) {
             oneself_hp = 0;
         }
+        return oneself_hp;
+    },
+    minusblood_critical(oneself_hp) {
+        console.log("暴击血量减少");
+        let _oligemia = this.damage * 2 - this.defense;
+        oneself_hp -= _oligemia;
+        if (oneself_hp <= 0) {
+            oneself_hp =
+                0;
+        }
+        return oneself_hp;
     },
     //加血 
-    //格挡加血 被动回血recover_hp, defense_hp  ---恢复血量类型 0被动回血 1格挡回血
-    addblood(oneself_maxhp, oneself_hp, heal_bool, heal_type) {
+    //格挡加血 被动回血recover_hp, defense_hp  ---恢复血量类型 0被动回血 1格挡回血heal_bool
+    addblood(oneself_maxhp, oneself_hp, 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;
-            }
+        //if (heal_bool) {
+        if (oneself_hp >= oneself_maxhp) {
+            oneself_hp == oneself_maxhp;
+            return oneself_hp;;
+        }
+        if (heal_type == 0) { //被动回血 1/s
+            // this.schedule(function() {
+            oneself_hp += this.recover_hp;
+            return oneself_hp;
+            //}, 1);
+        }
+        if (heal_type == 1) { //格挡回血 11/次
+            oneself_hp += this.defense_hp;
+            return oneself_hp;
         }
+        // }
     },
     //#endregion
 
@@ -65,26 +78,28 @@ cc.Class({
         oneself_endurance -= this.block_minus_endurance;
         if (oneself_endurance <= 0) {
             oneself_endurance = 0;
+            return oneself_endurance;
         }
+        return oneself_endurance;
     },
     //加蓝 
-    //闪避加蓝 被动回蓝recover_endurance, dodge_endurance  ---恢复蓝量类型 0被动回蓝 1闪避回蓝
-    addendurance(oneself_maxendurance, oneself_endurance, heal_bool, heal_type) {
+    //闪避加蓝 被动回蓝recover_endurance, dodge_endurance  -heal_bool--恢复蓝量类型 0被动回蓝 1闪避回蓝
+    addendurance(oneself_maxendurance, oneself_endurance, 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;
-            }
+        //if (heal_bool) {
+        if (oneself_endurance >= oneself_maxendurance) {
+            oneself_endurance == oneself_maxendurance;
+            return oneself_endurance;
+        }
+        if (heal_type == 0) { //被动回蓝 1/s  
+            oneself_endurance += this.recover_endurance;
+            return oneself_endurance;
+        }
+        if (heal_type == 1) { //闪避回蓝 11/次
+            oneself_endurance += this.dodge_endurance;
+            return oneself_endurance;
         }
+        //}
     }
     //#endregion
 });

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

@@ -10,6 +10,12 @@ cc.Class({
     },
     onLoad() {
         this._super();
+        this._restTime = this.restTime;
+        this._currentTime = this.currentTime;
+        this._player_name = this.player_name;
+        this._player_gold = this.player_gold;
+        this._player_energy = this.player_energy;
+        this._player_sex = this.player_sex;
         //#region 
         // this.InformationChanges("set", "name", "小明");
         //let name = this.InformationChanges("get", "name");

+ 47 - 12
assets/script/Game/Player/Charactor.js

@@ -72,20 +72,55 @@ cc.Class({
         }
         this.node.emit("dodge");
     },
-    hurt(bLeft) { //挨打
-
-        console.log("挨打");
+    hurt(bLeft, type) { ////挨打 左右拳,击打类型
         //发射挨打事件 
-        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);
+        if (type == 0) {
+            console.log("挨打");
+            if (bLeft == 0) {
+                //左挨打
+                this.armatureDisplay.node.scaleX = 0.39;
+                this.armature.animation.play("be_beaten", 1);
+            } else if (bLeft == 1) {
+                //右挨打
+                this.armatureDisplay.node.scaleX = -0.39;
+                this.armature.animation.play("be_beaten", 1);
+            }
+            this.node.emit("hurt_ord");
         }
-        this.node.emit("dodge");
+        if (type == 1) {
+            console.log("挨暴打");
+            if (bLeft == 0) {
+                //左挨打
+                //被暴打
+                this.armatureDisplay.node.scaleX = -0.39;
+                this.armature.animation.play("be_beaten", 1);
+
+            } else if (bLeft == 1) {
+                //被暴打
+                //右挨打
+                this.armatureDisplay.node.scaleX = 0.39;
+                this.armature.animation.play("be_beaten", 1);
+            }
+            this.node.emit("hurt_critical");
+        }
+        if (type == 2) {
+            console.log("挨连打");
+            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_double");
+        }
+
+
     },
     block() { //防御
         this.armature.animation.play("block", 1);

+ 34 - 2
assets/script/Game/Player/PlayerController.js

@@ -87,12 +87,44 @@ cc.Class({
             }
 
         } else if (name == 'right_down') {
-            this._RightDodge = true;
+
             this.AiControScp._Statepassivity = false;
+            if (this.AiControScp._RightJayShow) {
+                //被右拳打中
+                if (this.AiControScp._CriticalStrike) {
+                    //被右拳打中 暴击
+                    this.ctorScp.hurt(1, 1);
+                    return;
+                }
+                if (this.AiControScp._DoubleHit) {
+                    //被右拳打中 连击
+                    this.ctorScp.hurt(1, 2);
+                    return;
+                }
+                this.ctorScp.hurt(1, 0);
+                return;
+            }
+
+            this._RightDodge = true;
             this.ctorScp.dodge(0);
         } else if (name == 'left_down') {
-            this._LeftDodg = true;
             this.AiControScp._Statepassivity = false;
+            if (this.AiControScp._LeftJayShow) {
+                //被左拳打中
+                if (this.AiControScp._CriticalStrike) {
+                    //被左拳打中 暴击
+                    this.ctorScp.hurt(0, 1);
+                    return;
+                }
+                if (this.AiControScp._DoubleHit) {
+                    //被左拳打中 连击
+                    this.ctorScp.hurt(0, 2);
+                    return;
+                }
+                this.ctorScp.hurt(0, 0);
+                return;
+            }
+            this._LeftDodg = true;
             this.ctorScp.dodge(1);
         } else if (name == 'down') {
             this._Defence = true;

+ 44 - 19
assets/script/Game/Player/PlayerStates.js

@@ -4,6 +4,9 @@ cc.Class({
     properties: {
         playerController: cc.Node,
         Charactor: cc.Node,
+
+        progressBar_hp: cc.Node,
+        progressBar_endur: cc.Node,
     },
     onLoad() {
         this._super();
@@ -22,27 +25,55 @@ cc.Class({
         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", () => {
+            //console.log("检测到攻击1");
         });
-        this.Charactor.on("attack_critical_strike", function() {
-            console.log("检测到暴击1");
+        this.Charactor.on("attack_critical_strike", () => {
+            //console.log("检测到暴击1");
 
         });
-        this.Charactor.on("attack_double-hit", function() {
-            console.log("检测到连击1");
+        this.Charactor.on("attack_double-hit", () => {
+            //console.log("检测到连击1");
+        });
+        this.Charactor.on("dodge", () => {
+            //console.log("检测到躲闪");
+            this.addendurance(this._maxendurance, this._endurance, 1); //闪避回蓝
+            this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
         });
-        this.Charactor.on("dodge", function() {
-            console.log("检测到躲闪");
+        this.Charactor.on("block", () => {
+            //console.log("检测到防御");
+            this._endurance = this.minusendurance(this._endurance); //减蓝
+            this._hp = this.addblood(this._maxhp, this._hp, 1); //回血
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
+            this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
         });
-        this.Charactor.on("block", function() {
-            console.log("检测到防御");
-            this.block();
+        this.Charactor.on("hurt_ord", () => {
+            console.log("检测到受普攻");
+            this._hp = this.minusblood(this._hp);
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
         });
-        this.Charactor.on("hurt", function() {
-            console.log("检测到受伤");
+        this.Charactor.on("hurt_critical", () => {
+            console.log("检测到受暴击");
+            this._hp = this.minusblood_critical(this._hp);
+            //console.log("暴击后的血量:", this._hp);
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
+        });
+        this.Charactor.on("hurt_double", () => {
+            console.log("检测到受连攻");
+            this._hp = this.minusblood(this._hp);
+
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
+            this._hp = this.minusblood(this._hp);
+            this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
 
         });
+        //被动回血回蓝
+        this.schedule(() => {
+
+            this._hp = this.addblood(this._maxhp, this._hp, 0);
+            this._endurance = this.addendurance(this._maxendurance, this._endurance, 0);
+            console.log("玩家被动", this._hp, this._endurance);
+        }, 1);
     },
     start() {
 
@@ -52,11 +83,5 @@ cc.Class({
         this.controScp = this.playerController.getComponent('PlayerController');
         this.charactortroScp = this.Charactor.getComponent('Charactor');
     },
-    block() { //防御
-        this.minusendurance(this._endurance); //减蓝
-    },
-    hurt() { //受伤
-        this.minusblood(this._hp); //减血
-    },
     update(dt) {},
 });

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.