London/library/imports/bc/bcbd5530-23cd-4902-a0c9-c135ed3d1a2a.js
2024-08-28 11:14:05 +08:00

181 lines
7.0 KiB
JavaScript

"use strict";
cc._RF.push(module, 'bcbd5UwI81JAqDJwTXtPRoq', 'Ball');
// Script/Ball.ts
"use strict";
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
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 Ball = /** @class */ (function (_super) {
__extends(Ball, _super);
function Ball() {
return _super !== null && _super.apply(this, arguments) || this;
}
// LIFE-CYCLE CALLBACKS:
Ball.prototype.onLoad = function () {
// this.init();
this._touch = false;
this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
};
Ball.prototype.init = function (type, id) {
this.set_Touch(type);
if (this.node.parent.name != "GameArea") {
return;
}
this.GameManager = this.node.parent.parent.getComponent("GameManager");
this.tube_Array = this.GameManager.tube_Array;
this._posX = this.node.x;
this._posY = this.node.y;
this.size = cc.winSize;
this._id = id;
};
Ball.prototype.set_Touch = function (type) {
this._touch = type;
};
Ball.prototype.start = function () {
};
//开始点击,提高层级
Ball.prototype.touchStart = function (event) {
if (this._touch) {
return true;
}
else {
return false;
}
};
//移动小球,跟随手指移动
Ball.prototype.touchMove = function (event) {
this.node.zIndex = 2;
if (this._touch) {
var touchTemp = cc.v2(event.touch._point.x - this.size.width / 2, event.touch._point.y - this.size.height / 2);
this.node.x = touchTemp.x;
this.node.y = touchTemp.y;
}
};
//松手,还原层级,判断是否落到玻璃管内
Ball.prototype.touchEnd = function (event) {
//先判断是否是回收
this.node.zIndex = 0;
if (this._touch) {
var jg = this.getPos(cc.v2(this.node.x, this.node.y));
if (jg == 0) {
this.node.x = this._posX;
this.node.y = this._posY;
}
else if (jg == 1 && this._posX == -210) {
this.node.x = this._posX;
this.node.y = this._posY;
}
else if (jg == 2 && this._posX == 0) {
this.node.x = this._posX;
this.node.y = this._posY;
}
else if (jg == 3 && this._posX == 210) {
this.node.x = this._posX;
this.node.y = this._posY;
}
else {
this.runEnter(jg);
}
this._posX = this.node.x;
this._posY = this.node.y;
}
};
//执行进管子动画
Ball.prototype.runEnter = function (jg) {
var _this = this;
if (jg == 1 && this.tube_Array[0].length < 3) {
var height = -100 + this.tube_Array[0].length * 100;
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 0,
start_Pos: cc.v2(this._posX, this._posY),
end_Pos: cc.v2(-210, height) });
cc.tween(this.node)
.to(0.2, { x: -210 })
.to(0.25, { y: height })
.call(function () {
_this._posX = _this.node.x;
_this._posY = _this.node.y;
})
.start();
}
else if (jg == 2 && this.tube_Array[1].length < 2) {
var height = -100 + this.tube_Array[1].length * 100;
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 1,
start_Pos: cc.v2(this._posX, this._posY),
end_Pos: cc.v2(0, height) });
cc.tween(this.node)
.to(0.2, { x: 0 })
.to(0.25, { y: height })
.call(function () {
_this._posX = _this.node.x;
_this._posY = _this.node.y;
})
.start();
}
else if (jg == 3 && this.tube_Array[2].length < 1) {
var height = -100 + this.tube_Array[2].length * 100;
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 2,
start_Pos: cc.v2(this._posX, this._posY),
end_Pos: cc.v2(210, height) });
cc.tween(this.node)
.to(0.2, { x: 210 })
.to(0.25, { y: height })
.call(function () {
_this._posX = _this.node.x;
_this._posY = _this.node.y;
})
.start();
}
};
Ball.prototype.getPos = function (point) {
var jg = 0;
var tube1 = this.GameManager.tube1;
var tube2 = this.GameManager.tube2;
var tube3 = this.GameManager.tube3;
var rect1 = cc.rect(tube1.x, tube1.y, tube1.width, tube1.height);
var rect2 = cc.rect(tube2.x, tube2.y, tube2.width, tube2.height);
var rect3 = cc.rect(tube3.x, tube3.y, tube3.width, tube3.height);
var nodeRect = cc.rect(point.x, point.y, this.node.width, this.node.height);
if (nodeRect.intersects(rect1))
jg = 1;
else if (nodeRect.intersects(rect2))
jg = 2;
else if (nodeRect.intersects(rect3))
jg = 3;
return jg;
};
Ball = __decorate([
ccclass
], Ball);
return Ball;
}(cc.Component));
exports.default = Ball;
cc._RF.pop();