|
|
@@ -0,0 +1,181 @@
|
|
|
+import MathUtil from "../../mk/utils/MathUtil";
|
|
|
+import { ProductType } from "../data/GameData";
|
|
|
+
|
|
|
+const { ccclass, property } = cc._decorator;
|
|
|
+@ccclass
|
|
|
+export default class HorseRace extends cc.Component {
|
|
|
+
|
|
|
+ @property({ displayName: '图片节点1', type: cc.Sprite })
|
|
|
+ sp_icon_1: cc.Sprite = null;
|
|
|
+ @property({ displayName: '图片节点2', type: cc.Sprite })
|
|
|
+ sp_icon_2: cc.Sprite = null;
|
|
|
+ @property({ displayName: '延时(秒)' })
|
|
|
+ delayTime = 0;
|
|
|
+ @property({ displayName: '1与2的之间的距离' })
|
|
|
+ distance = 97;
|
|
|
+ @property({ displayName: '速率' })
|
|
|
+ curSpeed = 5;
|
|
|
+ @property({ displayName: '刷新次数' })
|
|
|
+ refreshTimes = 5;
|
|
|
+ @property({ displayName: '最快速度展示的次数' })
|
|
|
+ maxShowTimes = 10;
|
|
|
+ @property({ displayName: '数据索引' })
|
|
|
+ index = 0;
|
|
|
+
|
|
|
+ @property({ displayName: '飞行动画节点', type: cc.Node })
|
|
|
+ node_fly: cc.Node = null;
|
|
|
+ @property({ displayName: '飞行终点节点', type: cc.Node })
|
|
|
+ node_des: cc.Node = null;
|
|
|
+ @property({ displayName: 'hide节点', type: cc.Node })
|
|
|
+ node_hide: cc.Node = null;
|
|
|
+ @property({ displayName: '回调', type: cc.Component.EventHandler})
|
|
|
+ callBack: cc.Component.EventHandler = null;
|
|
|
+
|
|
|
+ private node_icon_1: cc.Node = null;
|
|
|
+ private node_icon_2: cc.Node = null;
|
|
|
+ private iconPath = "game/coregame/texture/plant_icons/plantIcon_";
|
|
|
+ private times = 0;
|
|
|
+ private arrData = null;
|
|
|
+ private realyPicture = 0;
|
|
|
+ private delay = 0
|
|
|
+ private isFinish = false;
|
|
|
+ private slowSpeedRefreshTimes = 0
|
|
|
+ private randArr = [];
|
|
|
+ private curRand = -1;
|
|
|
+ private speed = 0
|
|
|
+ start() {
|
|
|
+ this.node_icon_1 = this.sp_icon_1.node;
|
|
|
+ this.node_icon_2 = this.sp_icon_2.node;
|
|
|
+ this.node_icon_2.setPosition(new cc.Vec2(0, this.distance));
|
|
|
+ this.delayTime = Math.floor(this.delayTime * 60);
|
|
|
+ this.arrData = gData.gameData.getProductArrByType(ProductType.nzw);
|
|
|
+ this.delay = this.delayTime;
|
|
|
+ this.speed = this.curSpeed;
|
|
|
+ for (let i = 0; i != this.arrData.length; ++i) {
|
|
|
+ this.randArr.push(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ mk.event.register("flyOrderAni", this.doFlyAni.bind(this), this);
|
|
|
+ }
|
|
|
+
|
|
|
+ onEnable() {
|
|
|
+ let orderData = gData.gameData.playerProp.orderData;
|
|
|
+ let productJson = gData.gameData.configs.Product;
|
|
|
+ let id = orderData.orderTaskList[this.index];
|
|
|
+ this.realyPicture = productJson[id.Id - 1].picture;
|
|
|
+ }
|
|
|
+
|
|
|
+ sss = 0;
|
|
|
+ update(dt) {
|
|
|
+ if (this.delay <= 0 && !this.isFinish) {
|
|
|
+ //节点1
|
|
|
+ this.node_icon_1.setPosition(new cc.Vec2(0, this.node_icon_1.position.y - this.speed));
|
|
|
+ if (this.node_icon_1.position.y <= - this.distance) {
|
|
|
+ ++this.times;
|
|
|
+ if (this.times > this.maxShowTimes) {
|
|
|
+ if (this.speed != 3) {
|
|
|
+ // let s = ((this.refreshTimes - (this.times - this.maxShowTimes)) / this.refreshTimes);
|
|
|
+ // if(s > 1){
|
|
|
+ // s = 1;
|
|
|
+ // }
|
|
|
+ // this.speed *= s;
|
|
|
+ // this.speed = Math.ceil(this.speed);
|
|
|
+
|
|
|
+ ++this.sss;
|
|
|
+ let aa = 2 + this.sss * 0.1;
|
|
|
+ this.speed -= aa;
|
|
|
+ if (this.speed < 3) {
|
|
|
+ this.speed = 2;
|
|
|
+ ++this.slowSpeedRefreshTimes;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ++this.slowSpeedRefreshTimes;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.node_icon_1.setPosition(new cc.Vec2(0, this.distance));
|
|
|
+ if (this.slowSpeedRefreshTimes >= 1) {
|
|
|
+ this.refreshIcon(1, true);
|
|
|
+ } else {
|
|
|
+ this.refreshIcon(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //节点2
|
|
|
+ this.node_icon_2.setPosition(new cc.Vec2(0, this.node_icon_2.position.y - this.speed));
|
|
|
+ if (this.node_icon_2.position.y <= - this.distance) {
|
|
|
+ this.node_icon_2.setPosition(new cc.Vec2(0, this.distance));
|
|
|
+
|
|
|
+ if (this.slowSpeedRefreshTimes >= 1) {
|
|
|
+ this.isFinish = true;
|
|
|
+ this.node_icon_1.setPosition(0, 0);
|
|
|
+ gData.gameData.setOrderAniFinishNum();
|
|
|
+ } else {
|
|
|
+ this.refreshIcon(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ --this.delay;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tests = 0;
|
|
|
+ private async refreshIcon(index, isOver = false) {
|
|
|
+ if (isOver) {
|
|
|
+ this.sp_icon_1.spriteFrame = await mk.loader.load(this.iconPath + this.realyPicture, cc.SpriteFrame);
|
|
|
+ if (this.curRand != -1) {
|
|
|
+ this.randArr.push(this.curRand);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let rand = mk.math.random(0, this.randArr.length - 1);
|
|
|
+ this.randArr.splice(rand, 1);
|
|
|
+ let picId = this.arrData[rand].picture;
|
|
|
+ if (this.curRand != -1) {
|
|
|
+ this.randArr.push(this.curRand);
|
|
|
+ }
|
|
|
+ this.curRand = rand;
|
|
|
+ if(this.index == 0)
|
|
|
+ {
|
|
|
+ ++this.tests;
|
|
|
+ console.log(`=====${this.tests}====${rand}`);
|
|
|
+ }
|
|
|
+ if (index == 1) {
|
|
|
+ this.sp_icon_1.spriteFrame = await mk.loader.load(this.iconPath + picId, cc.SpriteFrame);
|
|
|
+ } else {
|
|
|
+ this.sp_icon_2.spriteFrame = await mk.loader.load(this.iconPath + picId, cc.SpriteFrame);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public doFlyAni()
|
|
|
+ {
|
|
|
+ if(this.node_hide ){
|
|
|
+ this.node_hide.active = false
|
|
|
+ }
|
|
|
+
|
|
|
+ let node = cc.instantiate(this.sp_icon_1.node);
|
|
|
+ node.setScale(0.32);
|
|
|
+ node.parent = this.node_fly;
|
|
|
+ let worldPos = this.sp_icon_1.node.parent.convertToWorldSpaceAR(cc.Vec2.ZERO);
|
|
|
+ let pos = this.node_fly.convertToNodeSpaceAR(worldPos);
|
|
|
+ node.setPosition(pos);
|
|
|
+
|
|
|
+ worldPos = this.node_des.parent.convertToWorldSpaceAR(this.node_des.getPosition())
|
|
|
+ pos = this.node_fly.convertToNodeSpaceAR(worldPos);
|
|
|
+
|
|
|
+ cc.tween(node).to(0.6, {position: cc.v3(pos)}).removeSelf().call(()=>{
|
|
|
+ this.callBack && this.callBack.emit(null);
|
|
|
+ }).start();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ onDisable() {
|
|
|
+ this.delay = this.delayTime;
|
|
|
+ this.isFinish = false;
|
|
|
+ this.slowSpeedRefreshTimes = 0;
|
|
|
+ this.curRand = -1
|
|
|
+ this.times = 0;
|
|
|
+ this.speed = this.curSpeed;
|
|
|
+ }
|
|
|
+}
|