26f7f226-7ea3-4683-b4a1-081072f47e32.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. "use strict";
  2. cc._RF.push(module, '26f7fImfqNGg7ShCBBy9H4y', 'Move');
  3. // Script/new_20210323/Move.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. 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;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. exports.ShapeType = exports.LineType = exports.LoopType = void 0;
  26. var App_1 = require("../Manager/App");
  27. var player_1 = require("../player");
  28. var LoopType;
  29. (function (LoopType) {
  30. LoopType[LoopType["Loop"] = 0] = "Loop";
  31. LoopType[LoopType["Once"] = 1] = "Once";
  32. LoopType[LoopType["PingPong"] = 2] = "PingPong";
  33. })(LoopType = exports.LoopType || (exports.LoopType = {}));
  34. var LineType;
  35. (function (LineType) {
  36. LineType[LineType["any"] = 0] = "any";
  37. LineType[LineType["Vertical"] = 1] = "Vertical";
  38. LineType[LineType["Horizontal"] = 2] = "Horizontal";
  39. })(LineType = exports.LineType || (exports.LineType = {}));
  40. var ShapeType;
  41. (function (ShapeType) {
  42. ShapeType[ShapeType["StraightLine"] = 0] = "StraightLine";
  43. ShapeType[ShapeType["PathLine"] = 1] = "PathLine";
  44. ShapeType[ShapeType["CircleLine"] = 2] = "CircleLine";
  45. })(ShapeType = exports.ShapeType || (exports.ShapeType = {}));
  46. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  47. var NewClass = /** @class */ (function (_super) {
  48. __extends(NewClass, _super);
  49. function NewClass() {
  50. var _this = _super !== null && _super.apply(this, arguments) || this;
  51. /**移动速度 */
  52. _this.speed = 1;
  53. /**移动pingpong返回速度 */
  54. _this.backSpeed = 1;
  55. _this.currentSpeed = 1;
  56. /**循环类型 */
  57. _this.loopType = LoopType.Loop;
  58. /**移动形状类型 */
  59. _this.shapeType = ShapeType.StraightLine;
  60. /**直线类型 */
  61. _this.lineType = LineType.any;
  62. /**路径个数 */
  63. _this.pathNum = 1;
  64. /** 是否延时开始*/
  65. _this.isDelayStart = false;
  66. /** 延时时间*/
  67. _this.delayTime = 0;
  68. /**圆标志 */
  69. _this._circleFlag = false;
  70. /**加标志 */
  71. _this._addFlag = true;
  72. /** 目标位置组*/
  73. _this.posArr = [];
  74. /** 当前位置下标*/
  75. _this.currentPosIndex = 0;
  76. /** 初始位置*/
  77. _this.startPos = null;
  78. /**目标位置 */
  79. _this.targetPos = null;
  80. /**半径 */
  81. _this.radius = 0;
  82. /**角度 */
  83. _this.angle = 0;
  84. _this.isPlaySound = false;
  85. /** 坐标组 */
  86. _this.positionArray = [];
  87. _this.startMove = false;
  88. _this.particle = null;
  89. return _this;
  90. }
  91. // onLoad () {}
  92. NewClass.prototype.start = function () {
  93. var _this = this;
  94. this.startPos = this.positionArray[0];
  95. this.currentSpeed = this.speed;
  96. if (this.isDelayStart)
  97. this.scheduleOnce(function () { _this.SetStutas(_this.positionArray); }, this.delayTime);
  98. else
  99. this.SetStutas(this.positionArray);
  100. };
  101. /**设置状态 */
  102. NewClass.prototype.SetStutas = function (tempPosArr) {
  103. this._circleFlag = false;
  104. this.currentPosIndex = 1;
  105. if (this.shapeType == ShapeType.PathLine) {
  106. this.posArr = tempPosArr;
  107. // this.posArr.unshift(this.startPos);
  108. }
  109. else {
  110. this.targetPos = tempPosArr[1];
  111. if (this.shapeType == ShapeType.StraightLine) {
  112. if (this.lineType == LineType.Vertical) {
  113. this.targetPos.x = this.node.x;
  114. }
  115. else if (this.lineType == LineType.Horizontal) {
  116. this.targetPos.y = this.node.y;
  117. }
  118. this.posArr = [this.startPos, this.targetPos];
  119. // console.log('this.posArr', this.posArr);
  120. }
  121. else if (this.shapeType == ShapeType.CircleLine) {
  122. this._circleFlag = true;
  123. this.radius = this.startPos.sub(this.targetPos).mag();
  124. }
  125. }
  126. this.startMove = true;
  127. };
  128. ;
  129. NewClass.prototype.update = function (dt) {
  130. if (!this.startMove)
  131. return;
  132. if (this._circleFlag)
  133. this.CircleMove();
  134. else
  135. this.PathMove();
  136. };
  137. ;
  138. /**圆形运动 */
  139. NewClass.prototype.CircleMove = function () {
  140. this.node.position = this.AroundMove(this.targetPos, this.radius, this.angle);
  141. // console.log(' this.node.position ', this.node.position, 'this._角度 ', this._角度);
  142. if (this.angle >= 360) {
  143. if (this.loopType == LoopType.Once)
  144. return;
  145. if (this.loopType == LoopType.Loop) {
  146. this.angle = 0;
  147. }
  148. else if (this.loopType == LoopType.PingPong) {
  149. this.currentSpeed = -Math.abs(this.currentSpeed);
  150. }
  151. }
  152. else if (this.angle <= 0) {
  153. if (this.loopType == LoopType.PingPong)
  154. this.currentSpeed = Math.abs(this.currentSpeed);
  155. }
  156. this.angle += this.currentSpeed;
  157. };
  158. ;
  159. /**路径移动 */
  160. NewClass.prototype.PathMove = function () {
  161. var _targetPos = this.posArr[this.currentPosIndex];
  162. var _distance = this.node.position.sub(_targetPos).mag();
  163. if (_distance < this.currentSpeed) {
  164. if (this.loopType == LoopType.Once)
  165. return;
  166. if (this.loopType == LoopType.Loop) {
  167. if (this.currentPosIndex < this.posArr.length - 1) {
  168. this.currentPosIndex++;
  169. }
  170. else {
  171. this.currentPosIndex = 1;
  172. this.node.position = this.posArr[0];
  173. return;
  174. }
  175. }
  176. else if (this.loopType == LoopType.PingPong) {
  177. this.node.position = _targetPos;
  178. if (this._addFlag) {
  179. if (this.currentPosIndex < this.posArr.length - 1) {
  180. this.currentPosIndex++;
  181. this.currentSpeed = this.speed;
  182. }
  183. else {
  184. this._addFlag = false;
  185. }
  186. }
  187. else {
  188. if (this.currentPosIndex > 0) {
  189. this.currentPosIndex--;
  190. this.currentSpeed = this.backSpeed;
  191. this.PlayAudio();
  192. }
  193. else {
  194. this._addFlag = true;
  195. }
  196. }
  197. }
  198. }
  199. var returnPos = this.TowardsMove(_targetPos, this.node.position, this.currentSpeed); //, dt
  200. this.node.position = returnPos;
  201. };
  202. ;
  203. NewClass.prototype.PlayAudio = function () {
  204. if (!this.isPlaySound || !App_1.App.SoundManager.allowPlayEffect)
  205. return;
  206. var pos1 = this.node.parent.convertToWorldSpaceAR(this.node.getPosition());
  207. var newVec2 = cc.find('Canvas').convertToNodeSpaceAR(pos1);
  208. if (this.IsCameraSaw(newVec2)) {
  209. this.node.getComponent(cc.AudioSource).play();
  210. if (this.particle)
  211. this.particle.resetSystem();
  212. }
  213. };
  214. NewClass.prototype.IsCameraSaw = function (targetPos) {
  215. var heights = this.node.height;
  216. var posY = player_1.default.getInstance().node.y + cc.winSize.height + heights;
  217. var posY1 = player_1.default.getInstance().node.y - cc.winSize.height - heights + player_1.default.getInstance().cameraOffsetY;
  218. if (targetPos.y < posY && targetPos.y > posY1) {
  219. return true;
  220. }
  221. else {
  222. return false;
  223. }
  224. };
  225. NewClass.prototype.AroundMove = function (axis, radius, angle) {
  226. var x1 = axis.x + radius * Math.sin(angle * Math.PI / 180);
  227. var y1 = axis.y + radius * Math.cos(angle * Math.PI / 180);
  228. return new cc.Vec3(x1, y1, 0);
  229. };
  230. NewClass.prototype.TowardsMove = function (endPos, movePos, speed) {
  231. var moveDir = endPos.sub(movePos).normalize();
  232. var vx = moveDir.x * speed;
  233. var vy = moveDir.y * speed;
  234. var returnX = movePos.x + vx; //* dt
  235. var returnY = movePos.y + vy; //* dt
  236. return new cc.Vec3(returnX, returnY, 0);
  237. };
  238. ;
  239. __decorate([
  240. property
  241. ], NewClass.prototype, "speed", void 0);
  242. __decorate([
  243. property
  244. ], NewClass.prototype, "backSpeed", void 0);
  245. __decorate([
  246. property({ type: cc.Enum(LoopType) })
  247. ], NewClass.prototype, "loopType", void 0);
  248. __decorate([
  249. property({ type: cc.Enum(ShapeType) })
  250. ], NewClass.prototype, "shapeType", void 0);
  251. __decorate([
  252. property({ type: cc.Enum(LineType) })
  253. ], NewClass.prototype, "lineType", void 0);
  254. __decorate([
  255. property
  256. ], NewClass.prototype, "isDelayStart", void 0);
  257. __decorate([
  258. property
  259. ], NewClass.prototype, "delayTime", void 0);
  260. __decorate([
  261. property
  262. ], NewClass.prototype, "angle", void 0);
  263. __decorate([
  264. property
  265. ], NewClass.prototype, "isPlaySound", void 0);
  266. __decorate([
  267. property([cc.Vec2])
  268. ], NewClass.prototype, "positionArray", void 0);
  269. __decorate([
  270. property(cc.ParticleSystem)
  271. ], NewClass.prototype, "particle", void 0);
  272. NewClass = __decorate([
  273. ccclass
  274. ], NewClass);
  275. return NewClass;
  276. }(cc.Component));
  277. exports.default = NewClass;
  278. cc._RF.pop();