"use strict"; cc._RF.push(module, '26f7fImfqNGg7ShCBBy9H4y', 'Move'); // Script/new_20210323/Move.ts "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShapeType = exports.LineType = exports.LoopType = void 0; var App_1 = require("../Manager/App"); var player_1 = require("../player"); var LoopType; (function (LoopType) { LoopType[LoopType["Loop"] = 0] = "Loop"; LoopType[LoopType["Once"] = 1] = "Once"; LoopType[LoopType["PingPong"] = 2] = "PingPong"; })(LoopType = exports.LoopType || (exports.LoopType = {})); var LineType; (function (LineType) { LineType[LineType["any"] = 0] = "any"; LineType[LineType["Vertical"] = 1] = "Vertical"; LineType[LineType["Horizontal"] = 2] = "Horizontal"; })(LineType = exports.LineType || (exports.LineType = {})); var ShapeType; (function (ShapeType) { ShapeType[ShapeType["StraightLine"] = 0] = "StraightLine"; ShapeType[ShapeType["PathLine"] = 1] = "PathLine"; ShapeType[ShapeType["CircleLine"] = 2] = "CircleLine"; })(ShapeType = exports.ShapeType || (exports.ShapeType = {})); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var NewClass = /** @class */ (function (_super) { __extends(NewClass, _super); function NewClass() { var _this = _super !== null && _super.apply(this, arguments) || this; /**移动速度 */ _this.speed = 1; /**移动pingpong返回速度 */ _this.backSpeed = 1; _this.currentSpeed = 1; /**循环类型 */ _this.loopType = LoopType.Loop; /**移动形状类型 */ _this.shapeType = ShapeType.StraightLine; /**直线类型 */ _this.lineType = LineType.any; /**路径个数 */ _this.pathNum = 1; /** 是否延时开始*/ _this.isDelayStart = false; /** 延时时间*/ _this.delayTime = 0; /**圆标志 */ _this._circleFlag = false; /**加标志 */ _this._addFlag = true; /** 目标位置组*/ _this.posArr = []; /** 当前位置下标*/ _this.currentPosIndex = 0; /** 初始位置*/ _this.startPos = null; /**目标位置 */ _this.targetPos = null; /**半径 */ _this.radius = 0; /**角度 */ _this.angle = 0; _this.isPlaySound = false; /** 坐标组 */ _this.positionArray = []; _this.startMove = false; _this.particle = null; return _this; } // onLoad () {} NewClass.prototype.start = function () { var _this = this; this.startPos = this.positionArray[0]; this.currentSpeed = this.speed; if (this.isDelayStart) this.scheduleOnce(function () { _this.SetStutas(_this.positionArray); }, this.delayTime); else this.SetStutas(this.positionArray); }; /**设置状态 */ NewClass.prototype.SetStutas = function (tempPosArr) { this._circleFlag = false; this.currentPosIndex = 1; if (this.shapeType == ShapeType.PathLine) { this.posArr = tempPosArr; // this.posArr.unshift(this.startPos); } else { this.targetPos = tempPosArr[1]; if (this.shapeType == ShapeType.StraightLine) { if (this.lineType == LineType.Vertical) { this.targetPos.x = this.node.x; } else if (this.lineType == LineType.Horizontal) { this.targetPos.y = this.node.y; } this.posArr = [this.startPos, this.targetPos]; // console.log('this.posArr', this.posArr); } else if (this.shapeType == ShapeType.CircleLine) { this._circleFlag = true; this.radius = this.startPos.sub(this.targetPos).mag(); } } this.startMove = true; }; ; NewClass.prototype.update = function (dt) { if (!this.startMove) return; if (this._circleFlag) this.CircleMove(); else this.PathMove(); }; ; /**圆形运动 */ NewClass.prototype.CircleMove = function () { this.node.position = this.AroundMove(this.targetPos, this.radius, this.angle); // console.log(' this.node.position ', this.node.position, 'this._角度 ', this._角度); if (this.angle >= 360) { if (this.loopType == LoopType.Once) return; if (this.loopType == LoopType.Loop) { this.angle = 0; } else if (this.loopType == LoopType.PingPong) { this.currentSpeed = -Math.abs(this.currentSpeed); } } else if (this.angle <= 0) { if (this.loopType == LoopType.PingPong) this.currentSpeed = Math.abs(this.currentSpeed); } this.angle += this.currentSpeed; }; ; /**路径移动 */ NewClass.prototype.PathMove = function () { var _targetPos = this.posArr[this.currentPosIndex]; var _distance = this.node.position.sub(_targetPos).mag(); if (_distance < this.currentSpeed) { if (this.loopType == LoopType.Once) return; if (this.loopType == LoopType.Loop) { if (this.currentPosIndex < this.posArr.length - 1) { this.currentPosIndex++; } else { this.currentPosIndex = 1; this.node.position = this.posArr[0]; return; } } else if (this.loopType == LoopType.PingPong) { this.node.position = _targetPos; if (this._addFlag) { if (this.currentPosIndex < this.posArr.length - 1) { this.currentPosIndex++; this.currentSpeed = this.speed; } else { this._addFlag = false; } } else { if (this.currentPosIndex > 0) { this.currentPosIndex--; this.currentSpeed = this.backSpeed; this.PlayAudio(); } else { this._addFlag = true; } } } } var returnPos = this.TowardsMove(_targetPos, this.node.position, this.currentSpeed); //, dt this.node.position = returnPos; }; ; NewClass.prototype.PlayAudio = function () { if (!this.isPlaySound || !App_1.App.SoundManager.allowPlayEffect) return; var pos1 = this.node.parent.convertToWorldSpaceAR(this.node.getPosition()); var newVec2 = cc.find('Canvas').convertToNodeSpaceAR(pos1); if (this.IsCameraSaw(newVec2)) { this.node.getComponent(cc.AudioSource).play(); if (this.particle) this.particle.resetSystem(); } }; NewClass.prototype.IsCameraSaw = function (targetPos) { var heights = this.node.height; var posY = player_1.default.getInstance().node.y + cc.winSize.height + heights; var posY1 = player_1.default.getInstance().node.y - cc.winSize.height - heights + player_1.default.getInstance().cameraOffsetY; if (targetPos.y < posY && targetPos.y > posY1) { return true; } else { return false; } }; NewClass.prototype.AroundMove = function (axis, radius, angle) { var x1 = axis.x + radius * Math.sin(angle * Math.PI / 180); var y1 = axis.y + radius * Math.cos(angle * Math.PI / 180); return new cc.Vec3(x1, y1, 0); }; NewClass.prototype.TowardsMove = function (endPos, movePos, speed) { var moveDir = endPos.sub(movePos).normalize(); var vx = moveDir.x * speed; var vy = moveDir.y * speed; var returnX = movePos.x + vx; //* dt var returnY = movePos.y + vy; //* dt return new cc.Vec3(returnX, returnY, 0); }; ; __decorate([ property ], NewClass.prototype, "speed", void 0); __decorate([ property ], NewClass.prototype, "backSpeed", void 0); __decorate([ property({ type: cc.Enum(LoopType) }) ], NewClass.prototype, "loopType", void 0); __decorate([ property({ type: cc.Enum(ShapeType) }) ], NewClass.prototype, "shapeType", void 0); __decorate([ property({ type: cc.Enum(LineType) }) ], NewClass.prototype, "lineType", void 0); __decorate([ property ], NewClass.prototype, "isDelayStart", void 0); __decorate([ property ], NewClass.prototype, "delayTime", void 0); __decorate([ property ], NewClass.prototype, "angle", void 0); __decorate([ property ], NewClass.prototype, "isPlaySound", void 0); __decorate([ property([cc.Vec2]) ], NewClass.prototype, "positionArray", void 0); __decorate([ property(cc.ParticleSystem) ], NewClass.prototype, "particle", void 0); NewClass = __decorate([ ccclass ], NewClass); return NewClass; }(cc.Component)); exports.default = NewClass; cc._RF.pop();