Commit 99f7e199 authored by Vũ Gia Vương's avatar Vũ Gia Vương

done

parent d2272422
This diff is collapsed.
......@@ -4,7 +4,13 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class FragmentJarController extends cc.Component {
@property(cc.Node)
private fragmentLink: cc.Node = null;
@property
private isBottom: boolean = false;
private _physicsCollider: cc.PhysicsPolygonCollider = null;
private _physicsColliderFragmentLink: cc.PhysicsPolygonCollider = null;
private _rg: cc.RigidBody = null;
private _siblingIndex: number = 0;
private _isDropped: boolean = false;
......@@ -13,6 +19,7 @@ export default class FragmentJarController extends cc.Component {
onLoad() {
this._physicsCollider = this.node.getComponent(cc.PhysicsPolygonCollider);
this._physicsColliderFragmentLink = this.fragmentLink && this.fragmentLink.getComponent(cc.PhysicsPolygonCollider);
this._rg = this.node.getComponent(cc.RigidBody);
this._siblingIndex = this.node.getSiblingIndex();
this._slots = this.node.children;
......@@ -36,14 +43,21 @@ export default class FragmentJarController extends cc.Component {
}
private checkTouch(point: cc.Vec2) {
if (this._isDropped) {
if (this._isDropped || this.isBottom) {
return;
}
const pos = point.clone().subtract(cc.v2(this.node.position.x, this.node.position.y));
const isInside = cc.Intersection.pointInPolygon(pos, this._physicsCollider.points);
let isInsideFragmentLink = false;
if (this._physicsColliderFragmentLink) {
const posFragmentLink = point.clone().subtract(cc.v2(this.fragmentLink.position.x, this.fragmentLink.position.y));
isInsideFragmentLink = cc.Intersection.pointInPolygon(posFragmentLink, this._physicsColliderFragmentLink.points);
console.log('isInside', isInside, isInsideFragmentLink, this.node.name, this._physicsColliderFragmentLink.points.length)
}
let isInside = cc.Intersection.pointInPolygon(pos, this._physicsCollider.points);
if (!isInside) {
if (!isInside && !isInsideFragmentLink) {
return;
}
......@@ -62,7 +76,6 @@ export default class FragmentJarController extends cc.Component {
this._isDropped = true;
const pos = this.node.position;
this.node.setSiblingIndex(-1);
// eventTarget.emit(CHECK_FRAGMENT, this.node.name);
eventTarget.emit(CHECK_FRAGMENT, this.node);
cc.tween(this.node)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment