删除废弃脚本,修改商店礼包显示,添加道具引导
This commit is contained in:
parent
5b04762c74
commit
3a9402e0c7
File diff suppressed because it is too large
Load Diff
72
assets/Script/ItemGuide.ts
Normal file
72
assets/Script/ItemGuide.ts
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
|
||||||
|
|
||||||
|
import JiaZai from "./JiaZai";
|
||||||
|
import MapConroler from "./Map";
|
||||||
|
|
||||||
|
const { ccclass, property } = cc._decorator;
|
||||||
|
|
||||||
|
|
||||||
|
@ccclass
|
||||||
|
export default class ItemGuide extends cc.Component {
|
||||||
|
static _instance: any;
|
||||||
|
time: number = 0;
|
||||||
|
//需要替换的三个道具节点
|
||||||
|
@property([cc.Node])
|
||||||
|
itemList: cc.Node[] = [];
|
||||||
|
@property(cc.Node)
|
||||||
|
itemGuide: cc.Node = null;
|
||||||
|
//道具节点的图片
|
||||||
|
@property([cc.SpriteFrame])
|
||||||
|
itemSpriteList: cc.SpriteFrame[] = [];
|
||||||
|
//飞的目标节点
|
||||||
|
@property([cc.Node])
|
||||||
|
targetNode: cc.Node[] = [];
|
||||||
|
onLoad() {
|
||||||
|
if (cc.fx.GameConfig.GM_INFO.level + 1 == 8) {
|
||||||
|
this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[0];
|
||||||
|
this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[1];
|
||||||
|
this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[2];
|
||||||
|
} else if (cc.fx.GameConfig.GM_INFO.level + 1 == 11) {
|
||||||
|
this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[3];
|
||||||
|
this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[4];
|
||||||
|
this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[5];
|
||||||
|
} else if (cc.fx.GameConfig.GM_INFO.level + 1 == 16) {
|
||||||
|
this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[6];
|
||||||
|
this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[7];
|
||||||
|
this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[8];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
}
|
||||||
|
//关闭引导
|
||||||
|
closeGuide() {
|
||||||
|
this.node.children.forEach((item) => {
|
||||||
|
item.active = false;
|
||||||
|
})
|
||||||
|
this.node.children[0].active = true;
|
||||||
|
this.node.children[0].getComponent(cc.Sprite).spriteFrame = null;
|
||||||
|
this.itemGuide.active = true;
|
||||||
|
this.itemGuide.zIndex = 1000;
|
||||||
|
//获取目标节点的位置并且转换到itemGuide的位置的层级
|
||||||
|
let index = 0;
|
||||||
|
if (cc.fx.GameConfig.GM_INFO.level + 1 == 8) {
|
||||||
|
index = 0;
|
||||||
|
} else if (cc.fx.GameConfig.GM_INFO.level + 1 == 11) {
|
||||||
|
index = 1;
|
||||||
|
} else if (cc.fx.GameConfig.GM_INFO.level + 1 == 16) {
|
||||||
|
index = 2;
|
||||||
|
}
|
||||||
|
let pos = this.targetNode[index].convertToWorldSpaceAR(cc.Vec3.ZERO);
|
||||||
|
pos = this.node.convertToNodeSpaceAR(pos);
|
||||||
|
this.itemGuide.zIndex = 1000;
|
||||||
|
//同时改变大小和位置
|
||||||
|
cc.tween(this.itemGuide)
|
||||||
|
.to(1.3, { scale: 0.3, position: pos }) // 同时执行
|
||||||
|
.call(() => { this.node.active = false; })
|
||||||
|
.start();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// update (dt) {}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"ver": "1.1.0",
|
"ver": "1.1.0",
|
||||||
"uuid": "6ff610c1-4a4b-4030-a777-c8e0cc2528b8",
|
"uuid": "54996cd2-afca-4734-b3a6-9aa9d34465de",
|
||||||
"importer": "typescript",
|
"importer": "typescript",
|
||||||
"isPlugin": false,
|
"isPlugin": false,
|
||||||
"loadPluginInWeb": true,
|
"loadPluginInWeb": true,
|
|
@ -52,7 +52,12 @@ export default class MapConroler extends cc.Component {
|
||||||
magics: cc.Node = null;
|
magics: cc.Node = null;
|
||||||
@property(cc.Node)
|
@property(cc.Node)
|
||||||
mask: cc.Node = null;
|
mask: cc.Node = null;
|
||||||
|
//引导道具
|
||||||
|
@property(cc.Node)
|
||||||
|
guideItem: cc.Node = null;
|
||||||
|
//道具锁
|
||||||
|
@property([cc.Node])
|
||||||
|
itemLock: cc.Node[] = [];
|
||||||
@property(cc.Label)
|
@property(cc.Label)
|
||||||
iceLabel: cc.Label = null;
|
iceLabel: cc.Label = null;
|
||||||
@property(cc.Label)
|
@property(cc.Label)
|
||||||
|
@ -217,7 +222,59 @@ export default class MapConroler extends cc.Component {
|
||||||
this.magicNode.children[1].active = false;
|
this.magicNode.children[1].active = false;
|
||||||
this.magicNode.children[2].active = false;
|
this.magicNode.children[2].active = false;
|
||||||
}
|
}
|
||||||
|
//道具锁 第八关之前全为true
|
||||||
|
const currentLevel = cc.fx.GameConfig.GM_INFO.level + 1;
|
||||||
|
let lock0Active = false;
|
||||||
|
let lock1Active = false;
|
||||||
|
let lock2Active = false;
|
||||||
|
|
||||||
|
if (currentLevel < 8) {
|
||||||
|
lock0Active = true;
|
||||||
|
lock1Active = true;
|
||||||
|
lock2Active = true;
|
||||||
|
this.iceNode.active = false;
|
||||||
|
this.hammerNode.active = false;
|
||||||
|
this.magicNode.active = false;
|
||||||
|
this.iceNode.parent.getComponent(cc.Button).interactable = false;
|
||||||
|
this.hammerNode.parent.getComponent(cc.Button).interactable = false;
|
||||||
|
this.magicNode.parent.getComponent(cc.Button).interactable = false;
|
||||||
|
} else if (currentLevel >= 8 && currentLevel < 11) {
|
||||||
|
lock0Active = false;
|
||||||
|
lock1Active = true;
|
||||||
|
lock2Active = true;
|
||||||
|
this.iceNode.active = false;
|
||||||
|
this.hammerNode.active = true;
|
||||||
|
this.magicNode.active = false;
|
||||||
|
this.iceNode.parent.getComponent(cc.Button).interactable = false;
|
||||||
|
this.hammerNode.parent.getComponent(cc.Button).interactable = true;
|
||||||
|
this.magicNode.parent.getComponent(cc.Button).interactable = false;
|
||||||
|
} else if (currentLevel >= 11 && currentLevel < 16) {
|
||||||
|
lock0Active = false;
|
||||||
|
lock1Active = false;
|
||||||
|
lock2Active = true;
|
||||||
|
this.iceNode.active = true;
|
||||||
|
this.hammerNode.active = true;
|
||||||
|
this.magicNode.active = false;
|
||||||
|
this.iceNode.parent.getComponent(cc.Button).interactable = true;
|
||||||
|
this.hammerNode.parent.getComponent(cc.Button).interactable = true;
|
||||||
|
this.magicNode.parent.getComponent(cc.Button).interactable = false;
|
||||||
|
} else if (currentLevel >= 16) {
|
||||||
|
lock0Active = false;
|
||||||
|
lock1Active = false;
|
||||||
|
lock2Active = false;
|
||||||
|
this.iceNode.active = true;
|
||||||
|
this.hammerNode.active = true;
|
||||||
|
this.magicNode.active = true;
|
||||||
|
this.iceNode.parent.getComponent(cc.Button).interactable = true;
|
||||||
|
this.hammerNode.parent.getComponent(cc.Button).interactable = true;
|
||||||
|
this.magicNode.parent.getComponent(cc.Button).interactable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.itemLock[0].active = lock0Active;
|
||||||
|
this.itemLock[1].active = lock1Active;
|
||||||
|
this.itemLock[2].active = lock2Active;
|
||||||
|
}
|
||||||
|
|
||||||
startUpdate() {
|
startUpdate() {
|
||||||
if (this.gameStart == false) {
|
if (this.gameStart == false) {
|
||||||
this.gameStart = true;
|
this.gameStart = true;
|
||||||
|
@ -331,7 +388,9 @@ export default class MapConroler extends cc.Component {
|
||||||
this.guideNode.zIndex = 1000;
|
this.guideNode.zIndex = 1000;
|
||||||
this.guideNode.getComponent(Animation).play();
|
this.guideNode.getComponent(Animation).play();
|
||||||
}
|
}
|
||||||
|
if (cc.fx.GameConfig.GM_INFO.level + 1 == 8 || cc.fx.GameConfig.GM_INFO.level + 1 == 11 || cc.fx.GameConfig.GM_INFO.level + 1 == 16) {
|
||||||
|
this.guideItem.active = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建方块
|
//创建方块
|
||||||
|
|
|
@ -1,203 +0,0 @@
|
||||||
|
|
||||||
import List from "./List";
|
|
||||||
const { ccclass, property } = cc._decorator;
|
|
||||||
|
|
||||||
@ccclass
|
|
||||||
export default class NewClass extends cc.Component {
|
|
||||||
@property(cc.Node)
|
|
||||||
content: cc.Node = null;
|
|
||||||
@property(cc.Prefab)
|
|
||||||
itemPrefab: cc.Prefab = null;
|
|
||||||
private rankList: any;
|
|
||||||
private Player: cc.Node;
|
|
||||||
private listData: any;
|
|
||||||
private selfData: any;
|
|
||||||
private rankNumber: number;
|
|
||||||
private rankTotal: number;
|
|
||||||
private selfNode: cc.Node;
|
|
||||||
score: any;
|
|
||||||
allInfoList: any[];
|
|
||||||
//content: any;
|
|
||||||
|
|
||||||
|
|
||||||
onLoad() {
|
|
||||||
if (typeof wx === 'undefined') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wx.onMessage(data => {
|
|
||||||
console.log('子域接收到消息:', data);
|
|
||||||
if (data.message) {
|
|
||||||
console.log('成功接入开放域');
|
|
||||||
//如果收到的消息是分数
|
|
||||||
if (typeof (data.message) == 'number') {
|
|
||||||
//上传分数
|
|
||||||
console.log('收到的分数', data.message);
|
|
||||||
this.score = data.message;
|
|
||||||
this.compareOldNewScore();
|
|
||||||
this.allInfoList = [];
|
|
||||||
this.getPlayerInfo();
|
|
||||||
}
|
|
||||||
//如果收到的是要清空域的消息
|
|
||||||
else if (data.message == 'clear') {
|
|
||||||
//清空排行榜
|
|
||||||
this.content.removeAllChildren();
|
|
||||||
} else if (data.message == 'preload') {
|
|
||||||
console.log('子域收到预加载消息');
|
|
||||||
// 预加载排行榜item
|
|
||||||
if (this.itemPrefab) {
|
|
||||||
// 这里可以根据需要进行更复杂的预加载,例如加载图片等
|
|
||||||
console.log('预加载排行榜itemPrefab成功');
|
|
||||||
} else {
|
|
||||||
console.error('itemPrefab 未赋值');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新:请读者在主域中比较分数,并调用wx.setUserCloudStorage这个API来更新云托管分数(该API可以在主域中使用),否则玩家只有在点击了排行榜按钮后才会将分数存入云托管。
|
|
||||||
// 逻辑:将每局分数与存储在本地的最高分进行比较,如果超过历史最高分数则同时更新本地和云托管数据。不需要再将分数传到子域。
|
|
||||||
compareOldNewScore() {
|
|
||||||
// 将传过来的新分数和之前玩的分数进行比较
|
|
||||||
wx.getUserCloudStorage({
|
|
||||||
keyList: ['score'],
|
|
||||||
success: (res) => {
|
|
||||||
if (res.KVDataList.length) {
|
|
||||||
let KVData = res.KVDataList[0];
|
|
||||||
let storedScore = Number(KVData['value']);
|
|
||||||
if (this.score > storedScore) {
|
|
||||||
// 如果新分数大于存储分数,则将新分数存入云托管
|
|
||||||
let newKVData = { key: 'score', value: String(this.score) }
|
|
||||||
this.setNewCloudScore(newKVData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// 如果第一次玩,那么直接将传过来的分数设置到云托管
|
|
||||||
let newKVData = { key: 'score', value: String(this.score) }
|
|
||||||
this.setNewCloudScore(newKVData);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
fail: (res) => {
|
|
||||||
console.log(res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setNewCloudScore(newKVData) {
|
|
||||||
// 设置新云托管分数(第一次游戏时,也调用该方法设置云托管分数)
|
|
||||||
wx.setUserCloudStorage({
|
|
||||||
KVDataList: [newKVData],
|
|
||||||
success: (res) => {
|
|
||||||
console.log('更新玩家分数成功!');
|
|
||||||
},
|
|
||||||
fail: (res) => {
|
|
||||||
console.log(res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getPlayerInfo() {
|
|
||||||
// 获取当前玩家信息
|
|
||||||
// 用于读者Demo测试,实际项目中获取排行榜只需要调用getFriendInfo方法
|
|
||||||
wx.getUserInfo({
|
|
||||||
openIdList: ['selfOpenId'],
|
|
||||||
lang: 'zh_CN',
|
|
||||||
success: (res) => {
|
|
||||||
let userInfo = res.data[0];
|
|
||||||
|
|
||||||
// 获取玩家微信名和头像url
|
|
||||||
let nickName = userInfo.nickName;
|
|
||||||
let avatarUrl = userInfo.avatarUrl;
|
|
||||||
|
|
||||||
// 生成多个当前玩家的信息(分数不同)
|
|
||||||
for (let i = 0; i < 40; i++) {
|
|
||||||
// 加入到数组中
|
|
||||||
this.allInfoList.push({
|
|
||||||
nickName: nickName,
|
|
||||||
avatarUrl: avatarUrl,
|
|
||||||
score: Math.round(Math.random() * 100)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 开始排名
|
|
||||||
this.makeRanks();
|
|
||||||
},
|
|
||||||
|
|
||||||
fail: (res) => {
|
|
||||||
console.log(res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getFriendInfo() {
|
|
||||||
// 获取同城好友信息(包括自身)
|
|
||||||
wx.getFriendCloudStorage({
|
|
||||||
keyList: ['score'],
|
|
||||||
success: (res) => {
|
|
||||||
for (let i = 0; i < res.data.length; i++) {
|
|
||||||
// 获取玩家微信名,头像url和分数
|
|
||||||
let nickName = res.data[i].nickname;
|
|
||||||
let avatarUrl = res.data[i].avatarUrl;
|
|
||||||
let score = 0;
|
|
||||||
if (res.data[i].KVDataList.length)
|
|
||||||
score = res.data[i].KVDataList[0]['value'];
|
|
||||||
|
|
||||||
// 加入到数组中
|
|
||||||
this.allInfoList.push({
|
|
||||||
nickName: nickName,
|
|
||||||
avatarUrl: avatarUrl,
|
|
||||||
score: score
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 开始排名
|
|
||||||
this.makeRanks();
|
|
||||||
},
|
|
||||||
|
|
||||||
fail: (res) => {
|
|
||||||
console.log(res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
makeRanks() {
|
|
||||||
// 首先将allInfoList内部元素进行排序,根据分数来降序排列
|
|
||||||
this.allInfoList.sort((a, b) => {
|
|
||||||
return b['score'] - a['score'];
|
|
||||||
});
|
|
||||||
|
|
||||||
// 根据各个玩家的分数制作排名
|
|
||||||
for (let i = 0; i < this.allInfoList.length; i++) {
|
|
||||||
let nickName = this.allInfoList[i]['nickName'];
|
|
||||||
let avatarUrl = this.allInfoList[i]['avatarUrl'];
|
|
||||||
let score = this.allInfoList[i]['score'];
|
|
||||||
this.createItem(i + 1, nickName, avatarUrl, score);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createItem(rank, nickName, avatarUrl, score) {
|
|
||||||
// 生成item
|
|
||||||
let item = cc.instantiate(this.itemPrefab);
|
|
||||||
|
|
||||||
// 排名
|
|
||||||
item.children[0].getComponent(cc.Label).string = String(rank);
|
|
||||||
// 微信名
|
|
||||||
item.children[4].getComponent(cc.Label).string = nickName;
|
|
||||||
// 分数
|
|
||||||
item.children[5].getComponent(cc.Label).string = score;
|
|
||||||
// 头像
|
|
||||||
cc.loader.load({ url: avatarUrl, type: 'png' }, (err, texture) => {
|
|
||||||
if (err) console.error(err);
|
|
||||||
item.children[1].getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 添加到content中
|
|
||||||
this.content.addChild(item);
|
|
||||||
}
|
|
||||||
start() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// update (dt) {}
|
|
||||||
}
|
|
|
@ -753,7 +753,7 @@
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 1080,
|
"width": 1080,
|
||||||
"height": 1500
|
"height": 3350
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user