浏览代码

游戏结束展示

Roy 6 年之前
父节点
当前提交
9e3175b084
共有 4 个文件被更改,包括 854 次插入274 次删除
  1. 740 180
      assets/Scene/GameSence.fire
  2. 18 3
      assets/Script/Game/GameOverItem.js
  3. 24 21
      assets/Script/Game/GameOverRank.js
  4. 72 70
      assets/Script/Game/GameSence.js

文件差异内容过多而无法显示
+ 740 - 180
assets/Scene/GameSence.fire


+ 18 - 3
assets/Script/Game/GameOverItem.js

@@ -2,16 +2,31 @@ cc.Class({
     extends: cc.Component,
 
     properties: {
-        sprite: cc.Sprite,
-        score: cc.Label,
+        avatar: cc.Sprite,
+        scoreLabel: cc.Label,
+        nickLabel: cc.Label,
+        rankLabel: cc.Label,
     },
 
     // onLoad () {},
 
     start() {},
 
-    updateItem() {
+    updateItem(data, i) {
+        this.scoreLabel.string = data.score;
+        this.nickLabel.string = data.nick;
+        this.rankLabel.string = i + 1;
 
+        cc.loader.load({
+            url: data.url,
+            type: 'jpg'
+        }, (err, texture) => {
+            if (err === undefined || err === null) {
+                this.avatar.spriteFrame = new cc.SpriteFrame(texture);
+            } else {
+                console.log(err);
+            }
+        });
     },
 
     // update (dt) {},

+ 24 - 21
assets/Script/Game/GameOverRank.js

@@ -2,13 +2,9 @@ cc.Class({
     extends: cc.Component,
 
     properties: {
-        item1: cc.Node,
-        item2: cc.Node,
-        item3: cc.Node
+        itemList: [cc.Node],
     },
 
-    // LIFE-CYCLE CALLBACKS:
-
     // onLoad () {},
 
     onEnable() {
@@ -92,7 +88,7 @@ cc.Class({
     },
 
 
-    bindRank(rankList){
+    bindRank(rankList) {
         for (var i = 0; i < rankList.length; ++i) {
             var rd = rankList[i]
             // rd 的字段如下:
@@ -103,29 +99,36 @@ cc.Class({
             //    selfFlag: false,    // 是否是自己
             // }
             if (rd.selfFlag) {
-                if (i > 0) {
-                    self.item1.active = true;
-                    self.item2.active = true;
-
-                    self.item1.updateItem(rankList[i - 1]);
-                    self.item2.updateItem(rd);
-                    if (i + 1 < rankList.length) {
-                        self.item3.active = true;
-                        self.item3.updateItem(rankList[i + 1]);
+                if (i == 0) {
+                    for (var j = 0; j < this.itemList.length; j++) {
+                        let item = this.itemList[j];
+                        let rankIndex = j + i;
+                        if (rankIndex < rankList.length) {
+                            item.active = true;
+                            item.getComponent("GameOverItem").updateItem(rankList[rankIndex], rankIndex);
+                        } else {
+                            item.active = false;
+                        }
                     }
                 } else {
-                    self.item1.active = false;
-                    self.item2.active = true;
-                    self.item2.updateItem(rd);
-                    if (i + 1 < rankList.length) {
-                        self.item3.active = true;
-                        self.item3.updateItem(rankList[i + 1]);
+                    for (var j = 0; j < this.itemList.length; j++) {
+                        let item = this.itemList[j];
+                        let rankIndex = j + i - 1;
+                        if (rankIndex < rankList.length) {
+                            item.active = true;
+                            item.getComponent("GameOverItem").updateItem(rankList[rankIndex], rankIndex);
+                        } else {
+                            item.active = false;
+                        }
                     }
                 }
+                break;
             }
         }
     },
 
+
+
     start() {},
 
     // update (dt) {},

+ 72 - 70
assets/Script/Game/GameSence.js

@@ -226,12 +226,12 @@ cc.Class({
                 gameOverNode.getChildByName("EndNode").active = true;
 
                 this.gameOver();
-				
-				if (CC_QQPLAY) { 
-					this.rankScene.status = 3;
-					this.showRank();
-					this.updateXYXScore('showMyRank', null);
-				}
+
+                if (CC_QQPLAY) {
+                    this.rankScene.status = 3;
+                    this.showRank();
+                    this.updateXYXScore('showMyRank', null);
+                }
             } else {
                 countDown--;
                 countDownLabel.getComponent("cc.Label").string = countDown;
@@ -244,30 +244,30 @@ cc.Class({
     gameOver: function () {
         var gameOverNode = this.node.getChildByName("GameOver");
         var historyScoreLabel = gameOverNode.getChildByName("EndNode").getChildByName("HistoryScoreLabel");
-		var newRecordSp = gameOverNode.getChildByName("EndNode").getChildByName("NewRecordSp");
-		
-		UserInfo.getUserGameData((data) => {
-			var maxScore = data.maxScore || 0;
-			
-			if (this.sumScore > maxScore) {
-				maxScore = this.sumScore;
-				newRecordSp.active = true;
-				UserInfo.setUserGameData(this.sumScore);
-				
-				cc.audioEngine.playEffect(this.newRecordAudio);
-				newRecordSp.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.5), cc.scaleTo(0.5, 1))));
-			} else {
-				newRecordSp.active = false;
-			}
-	
-			if (this.sumScore > UserInfo.getScore()) {
-				UserInfo.setScore(this.sumScore);
-			}
-	
-			historyScoreLabel.getComponent("cc.Label").string = "历史最高分:" + maxScore;
-	
-			UserInfo.addGold(this.sumScore);
-		})
+        var newRecordSp = gameOverNode.getChildByName("EndNode").getChildByName("NewRecordSp");
+
+        UserInfo.getUserGameData((data) => {
+            var maxScore = data.maxScore || 0;
+
+            if (this.sumScore > maxScore) {
+                maxScore = this.sumScore;
+                newRecordSp.active = true;
+                UserInfo.setUserGameData(this.sumScore);
+
+                cc.audioEngine.playEffect(this.newRecordAudio);
+                newRecordSp.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.5), cc.scaleTo(0.5, 1))));
+            } else {
+                newRecordSp.active = false;
+            }
+
+            if (this.sumScore > UserInfo.getScore()) {
+                UserInfo.setScore(this.sumScore);
+            }
+
+            historyScoreLabel.getComponent("cc.Label").string = "历史最高分:" + maxScore;
+
+            UserInfo.addGold(this.sumScore);
+        })
 
         // window.deadBanner.hide();
         // window.accountBanner.show();
@@ -299,7 +299,7 @@ cc.Class({
         this.node.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(this.createObstacle, this), cc.delayTime(1), cc.callFunc(this.createObstacle, this)));
     },
 
-	// 创建障碍物
+    // 创建障碍物
     createObstacle: function () {
         var obstacleType = this.randomObstacleType();
         //根据当前分数控制障碍物之间的高度
@@ -404,7 +404,7 @@ cc.Class({
         })
     },
 
-	// 随机生成障碍物类型
+    // 随机生成障碍物类型
     randomObstacleType: function () {
         var obstacleType = 0;
         this.obstacleNum++;
@@ -455,7 +455,7 @@ cc.Class({
         return obstacleType;
     },
 
-	// 销毁障碍物
+    // 销毁障碍物
     destroyObstacle: function () {
         let obstacle1 = this.obstacleNode.getChildByName("obstacle1"),
             obstacle2 = this.obstacleNode.getChildByName("obstacle2"),
@@ -723,15 +723,15 @@ cc.Class({
                 imgurlData: UserInfo.shareUrl,
                 queryData: 'pp=pp'
             }
-            
+
             QQCommon.ShareAppMessage(data, () => {
-				var gameOverNode = this.node.getChildByName("GameOver");
-				var countDownLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndCountDownLabel");
-				countDownLabel.stopAllActions();
-				this.continueGame();
+                var gameOverNode = this.node.getChildByName("GameOver");
+                var countDownLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndCountDownLabel");
+                countDownLabel.stopAllActions();
+                this.continueGame();
 
-				cc.audioEngine.playMusic(this.gamebgMusic, true);
-			});
+                cc.audioEngine.playMusic(this.gamebgMusic, true);
+            });
         } else {
             var gameOverNode = this.node.getChildByName("GameOver");
             var countDownLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndCountDownLabel");
@@ -853,13 +853,13 @@ cc.Class({
         gameOverNode.getChildByName("EndNode").active = true;
 
         this.gameOver();
-		
-		if (CC_QQPLAY) { 
+
+        if (CC_QQPLAY) {
             // window.deadBanner.hide();
-			this.rankScene.status = 3;
+            this.rankScene.status = 3;
             this.showRank();
             this.updateXYXScore('showMyRank', null);
-		}
+        }
     },
 
     onRestartBtn: function () {
@@ -901,31 +901,33 @@ cc.Class({
     },
 
     updateXYXScore(strFun, data) {
-		var data = {
-			userData: [{
-				openId: GameStatusInfo.openId,
-				startMs: GameStatusInfo.startMs,
-				endMs: ((new Date()).getTime()).toString(),
-				scoreInfo: {
-					score: parseInt(UserInfo.getScore()), //分数,类型必须是整型数
-				}
-			}],
-			attr: {
-				score: {   
-					type: 'rank',
-					order: 1,
-				}
-			},
-		};
-
-		BK.QQ.uploadScoreWithoutRoom(1, data, function(errCode, cmd, data) {
-			// 返回错误码信息
-			if (errCode !== 0) {
-				BK.Script.log(1,1,'上传分数失败!错误码:' + errCode);
-			} else {
-				BK.Script.log(1,1,'上传分数成功' + JSON.stringify(data));
-			}
-		});
+        var data = {
+            userData: [{
+                openId: GameStatusInfo.openId,
+                startMs: GameStatusInfo.startMs,
+                endMs: ((new Date()).getTime()).toString(),
+                scoreInfo: {
+                    score: parseInt(UserInfo.getScore()), //分数,类型必须是整型数
+                }
+            }],
+            attr: {
+                score: {
+                    type: 'rank',
+                    order: 1,
+                }
+            },
+        };
+
+        if (CC_QQPLAY) {
+            BK.QQ.uploadScoreWithoutRoom(1, data, function (errCode, cmd, data) {
+                // 返回错误码信息
+                if (errCode !== 0) {
+                    BK.Script.log(1, 1, '上传分数失败!错误码:' + errCode);
+                } else {
+                    BK.Script.log(1, 1, '上传分数成功' + JSON.stringify(data));
+                }
+            });
+        }
     },
 
     showRank() {
@@ -1006,4 +1008,4 @@ cc.Class({
         // }
 
     },
-});
+});

部分文件因为文件数量过多而无法显示