"use strict"; cc._RF.push(module, '3fd2fh6vHNJeISUizW09xat', 'GuideManager'); // Script/GuideManager.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 }); 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; // LIFE-CYCLE CALLBACKS: _this.dialog = null; _this.ball = null; _this.qiu1 = null; _this.linePrefab = null; return _this; } // onLoad () {} NewClass.prototype.start = function () { cc.fx.GameConfig.GM_INFO.custom = 0; this.init(); this.startGuide(0); }; //初始化数据 NewClass.prototype.init = function () { this.custom = 1; this.ball.zIndex = 100; this.Pos_Array = []; this.ball_Array = []; this.begin = false; this.clickNow = 0; this.tip = null; }; //开始引导方法 NewClass.prototype.startGuide = function (type) { var _this = this; var num = this.custom; var time = 0.5; var name = "tip" + num; if (type != 0) { cc.tween(this.node) .to(time, { opacity: 255 }) .call(function () { _this.custom += 1; if (type != 0) _this.custom = 2; if (_this.custom == 2) _this.createSun(true); else if (_this.custom == 3) _this.createSun(false); else if (_this.custom == 4) _this.begin = true; else if (_this.custom == 5) cc.director.loadScene("GameScene"); }) .start(); } else { this.tip = this.dialog.getChildByName(name); this.tip.active = true; this.tip.opacity = 0; cc.tween(this.tip) .to(time, { opacity: 255 }) .start(); } }; //清除所有太阳 NewClass.prototype.beginClick = function () { for (var i = 0; i < this.ball_Array.length; i++) { this.ball_Array[i].getComponent("Sun").move = false; } }; //点击开始游戏,或者点击跳过引导 NewClass.prototype.clickBtn = function () { cc.director.loadScene("GameScene"); }; //点击下一步按钮 NewClass.prototype.next = function () { var _this = this; var time = 0.5; cc.tween(this.tip) .to(time, { opacity: 0 }) .call(function () { _this.custom += 1; if (_this.custom == 2) _this.createSun(true); else if (_this.custom == 3) _this.createSun(false); else if (_this.custom == 4) _this.begin = true; else if (_this.custom == 5) cc.director.loadScene("GameScene"); }) .start(); }; //创建太阳 NewClass.prototype.createSun = function (type) { var _this = this; if (type == true) { this.ball_Array = []; this.Pos_Array.push(cc.v2(-250, -216), cc.v2(200, -115), cc.v2(-35, -500)); var time1 = this.calculateDistance(this.ball.x, this.ball.y, this.Pos_Array[0].x, this.Pos_Array[0].y); this.ball.opacity = 0; cc.tween(this.ball) .to(time1, { position: this.Pos_Array[0] }) .call(function () { _this.createBall(0, 0, 0, false); }) .delay(1) .call(function () { _this.startGuide(0); }) .start(); } else { var time2 = this.calculateDistance(this.Pos_Array[0].x, this.Pos_Array[0].y, this.Pos_Array[1].x, this.Pos_Array[1].y); var time3 = this.calculateDistance(this.Pos_Array[1].x, this.Pos_Array[1].y, this.Pos_Array[2].x, this.Pos_Array[2].y); this.ball.opacity = 255; this.createLine(cc.v2(this.ball.x, this.ball.y), cc.v2(this.Pos_Array[1].x, this.Pos_Array[1].y), 0.5); cc.tween(this.ball) .to(time2, { position: this.Pos_Array[1] }) .call(function () { _this.createBall(1, 0, 0, false); }) .delay(0.5) .call(function () { _this.createLine(cc.v2(_this.ball.x, _this.ball.y), cc.v2(_this.Pos_Array[2].x, _this.Pos_Array[2].y), 0.5); }) .to(time3, { position: this.Pos_Array[2] }) .call(function () { _this.createBall(2, 0, 0, false); _this.ball.opacity = 0; }) .delay(0.2) .call(function () { _this.destroyLine(); _this.startGuide(0); }) .start(); } }; //创建太阳 NewClass.prototype.createBall = function (number, color, speed, repeat) { var ball = null; ball = cc.instantiate(this.qiu1); ball.parent = this.node.getChildByName("Sun"); ball.zIndex = this.Pos_Array.length - number; ball.setPosition(this.ball.x, this.ball.y); ball.getComponent("Sun").init(number, color, speed, repeat); ball.getComponent("Sun").move = true; this.ball_Array.push(ball); }; //获取两点之间角度创建连线用 NewClass.prototype.calculateDistance = function (x1, y1, x2, y2) { var dx = x2 - x1; var dy = y2 - y1; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 800) distance = 800; var time = distance / 800 * 0.8; return time; }; //引导成功 NewClass.prototype.passLevel = function () { var _this = this; var win = this.node.getChildByName("Win"); win.active = true; win.setScale(0); cc.tween(win) .delay(0.4) .to(0.01, { scale: 2.5 }) .to(0.35, { scale: 1 }) .delay(0.6) .call(function () { win.active = false; setTimeout(function () { _this.destroyLine(); var timeArray = []; var timeCount = 0; var ball = _this.ball_Array[0]; for (var i = 1; i < _this.ball_Array.length; i++) { var time = _this.calculateDistance(_this.ball_Array[i].x, _this.ball_Array[i].y, _this.ball_Array[i - 1].x, _this.ball_Array[i - 1].y); timeArray.push(time); } var _loop_1 = function (k) { setTimeout(function () { cc.tween(ball) .to(timeArray[k - 1], { x: _this.ball_Array[k].x, y: _this.ball_Array[k].y }) .call(function () { _this.ball_Array[k].active = false; if (k == _this.ball_Array.length - 1) { setTimeout(function () { _this.ball.opacity = 255; _this.ball.position = cc.v3(ball.x, ball.y, 0); _this.ball.active = false; _this.startGuide(0); }, 200); } }) .start(); }, timeCount * 1000); timeCount += (timeArray[k - 1] + 0.1); }; for (var k = 1; k < _this.ball_Array.length; k++) { _loop_1(k); } }, 400); }) .start(); }; //点击太阳执行方法 NewClass.prototype.clickSun = function (data) { var _this = this; if (this.begin == true) { if (data == this.clickNow) { cc.fx.AudioManager._instance.playAudioButton(); if (this.clickNow > 0) { this.createLine(cc.v2(this.ball_Array[this.clickNow - 1].x, this.ball_Array[this.clickNow - 1].y), cc.v2(this.ball_Array[this.clickNow].x, this.ball_Array[this.clickNow].y), 0.2); } this.clickNow += 1; cc.fx.GameConfig.GM_INFO.total += 1; setTimeout(function () { if (_this.ball_Array[_this.clickNow - 1]) _this.ball_Array[_this.clickNow - 1].getChildByName("guang").active = false; }, 200); if (this.clickNow == 3) { this.passLevel(); } } else { this.loseLevel(); } } }; //失败事件 NewClass.prototype.loseLevel = function () { var _this = this; this.begin = false; cc.fx.AudioManager._instance.playWarning(); this.destroyLine(); var ball = this.ball_Array[0]; var _loop_2 = function (k) { cc.tween(this_1.ball_Array[k]) .to(0.6, { x: ball.x, y: ball.y }) .call(function () { _this.ball_Array[k].active = false; if (k == _this.ball_Array.length - 1) { _this.ball.opacity = 0; _this.ball.position = cc.v3(ball.x, ball.y, 0); _this.clearSun(); _this.custom = 1; _this.startGuide(1); } }) .start(); }; var this_1 = this; for (var k = 1; k < this.ball_Array.length; k++) { _loop_2(k); } //结束页面动画 var over = this.node.getChildByName("Over"); cc.tween(over) .to(0.25, { opacity: 255 }) .delay(0.1) .to(0.2, { opacity: 0 }) .delay(0.1) .to(0.15, { opacity: 255 }) .delay(0.1) .to(0.1, { opacity: 0 }) .start(); }; //点击太阳事件 NewClass.prototype.clearSun = function () { for (var k = 0; k < this.ball_Array.length; k++) { this.ball_Array[k].removeFromParent(); this.ball_Array[k] = null; } this.ball_Array = []; }; //创造连线,参数起点,终点,连线时间 NewClass.prototype.createLine = function (start, end, time) { var line = cc.instantiate(this.linePrefab); line.parent = this.node.getChildByName("Line"); line.setPosition(start.x, start.y); var dx = end.x - start.x; var dy = end.y - start.y; var distance = Math.sqrt(dx * dx + dy * dy); line.height = distance; line.getComponent(cc.Sprite).fillRange = 0; line.angle = -this.calculateAngle(start.x, start.y, end.x, end.y); cc.tween(line.getComponent(cc.Sprite)) .to(time, { fillRange: 1 }) .start(); }; //摧毁连线 NewClass.prototype.destroyLine = function () { for (var i = 0; i < this.node.getChildByName("Line").children.length; i++) { if (this.node.getChildByName("Line").children[i]) { this.node.getChildByName("Line").children[i].removeFromParent(); this.node.getChildByName("Line").children[i] = null; } } this.node.getChildByName("Line").removeAllChildren(); }; //获取两个点之间的角度 用于写连线 确定连线方向 NewClass.prototype.calculateAngle = function (x1, y1, x2, y2) { var angle = Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI - 90; return -angle; }; NewClass.prototype.onEnable = function () { cc.fx.Notifications.on("clickSun", this.clickSun, this); }; NewClass.prototype.onDisable = function () { cc.fx.Notifications.off("clickSun", this.clickSun); }; __decorate([ property(cc.Node) ], NewClass.prototype, "dialog", void 0); __decorate([ property(cc.Node) ], NewClass.prototype, "ball", void 0); __decorate([ property(cc.Prefab) ], NewClass.prototype, "qiu1", void 0); __decorate([ property(cc.Prefab) ], NewClass.prototype, "linePrefab", void 0); NewClass = __decorate([ ccclass ], NewClass); return NewClass; }(cc.Component)); exports.default = NewClass; cc._RF.pop();