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

add behind fragment

parent 19bfc091
This diff is collapsed.
...@@ -27,3 +27,4 @@ export const HAMMER = 'HAMMER'; ...@@ -27,3 +27,4 @@ export const HAMMER = 'HAMMER';
export const RESET_BOTTLE = 'RESET_BOTTLE'; export const RESET_BOTTLE = 'RESET_BOTTLE';
export const RESET_FRAGMENT = 'RESET_FRAGMENT'; export const RESET_FRAGMENT = 'RESET_FRAGMENT';
export const DROP_FRAGMENT = 'DROP_FRAGMENT'; export const DROP_FRAGMENT = 'DROP_FRAGMENT';
export const DROP_BEHIND_FRAGMENT = 'DROP_BEHIND_FRAGMENT';
\ No newline at end of file
import { eventTarget, RESET_FRAGMENT } from "../Events";
const { ccclass, property } = cc._decorator;
@ccclass
export default class BehindFragment extends cc.Component {
private _rg: cc.RigidBody = null;
private _physicsCollider: cc.PhysicsCollider = null;
onLoad() {
this._rg = this.node.getComponent(cc.RigidBody);
this._rg.type = cc.RigidBodyType.Static;
this._physicsCollider = this.node.getComponent(cc.PhysicsCollider);
this._physicsCollider.enabled = false;
eventTarget.on(RESET_FRAGMENT, this.reset, this);
}
public onDrop() {
this._rg.type = cc.RigidBodyType.Dynamic;
this._rg.gravityScale = 10;
this._physicsCollider.enabled = true;
}
public reset() {
this._physicsCollider.enabled = false;
this._rg.type = cc.RigidBodyType.Static;
this.node.angle = 0;
}
}
{
"ver": "1.1.0",
"uuid": "2c4e47d9-d7cd-4f92-9b79-1bb85932b7e9",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import { BEAT_GUILD, CHECK_FRAGMENT, CHECK_TOUCH, DROP_FRAGMENT, eventTarget, HAMMER, RESET_BOTTLE, RESET_FRAGMENT, SHOW_CARD_POPUP, STOP_GUILD_TAP } from "../Events"; import { BEAT_GUILD, CHECK_FRAGMENT, CHECK_TOUCH, DROP_FRAGMENT, eventTarget, HAMMER, RESET_BOTTLE, RESET_FRAGMENT, SHOW_CARD_POPUP, STOP_GUILD_TAP } from "../Events";
import { Global } from "../Global"; import { Global } from "../Global";
import BehindFragment from "./BehindFragment";
import FragmentJarController from "./FragmentJarController"; import FragmentJarController from "./FragmentJarController";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -9,6 +10,8 @@ export default class BreakingJarController extends cc.Component { ...@@ -9,6 +10,8 @@ export default class BreakingJarController extends cc.Component {
@property(cc.Node) @property(cc.Node)
private hammerNode: cc.Node = null; private hammerNode: cc.Node = null;
@property(cc.Node)
private behindJar: cc.Node = null;
private _spine: sp.Skeleton = null; private _spine: sp.Skeleton = null;
private _skins = ["Ga", "Gai_lung", "Gay", "Bua",]; private _skins = ["Ga", "Gai_lung", "Gay", "Bua",];
...@@ -18,26 +21,11 @@ export default class BreakingJarController extends cc.Component { ...@@ -18,26 +21,11 @@ export default class BreakingJarController extends cc.Component {
private _fragmentsNode: cc.Node[] = []; private _fragmentsNode: cc.Node[] = [];
private _bodyFragments: string[] = []; private _bodyFragments: string[] = [];
private _isEnd = false; private _isEnd = false;
private _behindJarChild: BehindFragment[] = [];
private _BG: cc.Node = null; private _behindJarChildPosition: cc.Vec3[] = [];
private _behindJar: cc.Node = null;
private _frontJar: cc.Node = null;
private _slotsJar: cc.Node = null;
private _behindJarChild: cc.Node[] = [];
private _frontJarChild: cc.Node[] = [];
private _slotsJarChild: cc.Node[] = [];
onLoad() { onLoad() {
[this._BG, this._behindJar, this._frontJar, this._slotsJar] = this.node.children;
// this._behindJarChild = this._behindJar.children;
// this._frontJarChild = this._frontJar.children;
// this._slotsJarChild = this._slotsJar.children;
// this._slotsJarChild.forEach((slot) => {
// slot.active = false;
// })
cc.director.getPhysicsManager().enabled = true; cc.director.getPhysicsManager().enabled = true;
// cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit | // cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit |
// cc.PhysicsManager.DrawBits.e_jointBit | // cc.PhysicsManager.DrawBits.e_jointBit |
...@@ -55,6 +43,8 @@ export default class BreakingJarController extends cc.Component { ...@@ -55,6 +43,8 @@ export default class BreakingJarController extends cc.Component {
this._fragmentsNode = this.getComponentsInChildren(FragmentJarController).map(item => item.node); this._fragmentsNode = this.getComponentsInChildren(FragmentJarController).map(item => item.node);
this._fragmentsPosition = this._fragmentsNode.map(item => item.position.clone()); this._fragmentsPosition = this._fragmentsNode.map(item => item.position.clone());
this._behindJarChild = this.behindJar.children.map(item => item.getComponent(BehindFragment));
this._behindJarChildPosition = this.behindJar.children.map(item => item.position.clone());
} }
private beatGuild() { private beatGuild() {
...@@ -73,6 +63,12 @@ export default class BreakingJarController extends cc.Component { ...@@ -73,6 +63,12 @@ export default class BreakingJarController extends cc.Component {
this._fragmentsNode.forEach((node, index) => { this._fragmentsNode.forEach((node, index) => {
node.position = this._fragmentsPosition[index]; node.position = this._fragmentsPosition[index];
}) })
this._behindJarChild.forEach((behindFragment, index) => {
behindFragment.node.position = this._behindJarChildPosition[index];
behindFragment.reset();
})
eventTarget.emit(RESET_FRAGMENT); eventTarget.emit(RESET_FRAGMENT);
this._isEnd = false; this._isEnd = false;
} }
...@@ -90,23 +86,40 @@ export default class BreakingJarController extends cc.Component { ...@@ -90,23 +86,40 @@ export default class BreakingJarController extends cc.Component {
.start(); .start();
} }
private checkFragment(name: string) { private checkFragment(fragmentNode: cc.Node) {
const fragmentIndex = this._fragmentsNode.findIndex(item => item === fragmentNode);
const behindFragment = this._behindJarChild[fragmentIndex];
behindFragment.onDrop();
if (this._isEnd) { if (this._isEnd) {
return; return;
} }
if (!name.includes('nap')) {
this._bodyFragments.push(name); this._bodyFragments.push(fragmentNode.name);
}
this._countFragment++; this._countFragment++;
if (this._countFragment == 8) { if (this._countFragment == 8) {
this.scheduleOnce(() => eventTarget.emit(SHOW_CARD_POPUP), 1.5); this.scheduleOnce(() => eventTarget.emit(SHOW_CARD_POPUP), 1.5);
this._isEnd = true; this._isEnd = true;
} }
if (this._bodyFragments.length == 6) {
eventTarget.emit(DROP_FRAGMENT);
}
} }
// private checkFragment(name: string) {
// if (this._isEnd) {
// return;
// }
// if (!name.includes('nap')) {
// this._bodyFragments.push(name);
// }
// this._countFragment++;
// if (this._countFragment == 8) {
// this.scheduleOnce(() => eventTarget.emit(SHOW_CARD_POPUP), 1.5);
// this._isEnd = true;
// }
// if (this._bodyFragments.length == 6) {
// eventTarget.emit(DROP_FRAGMENT);
// }
// }
private onTouchStart(event: cc.Event.EventTouch) { private onTouchStart(event: cc.Event.EventTouch) {
eventTarget.emit(STOP_GUILD_TAP); eventTarget.emit(STOP_GUILD_TAP);
const pos = event.getLocation(); const pos = event.getLocation();
......
...@@ -31,6 +31,8 @@ export default class FragmentJarController extends cc.Component { ...@@ -31,6 +31,8 @@ export default class FragmentJarController extends cc.Component {
this.node.angle = 0; this.node.angle = 0;
this.node.setSiblingIndex(this._siblingIndex); this.node.setSiblingIndex(this._siblingIndex);
this._isDropped = false; this._isDropped = false;
this._numberOfBeats = 3;
this.node.children.forEach(slot => slot.active = false);
} }
private checkTouch(point: cc.Vec2) { private checkTouch(point: cc.Vec2) {
...@@ -59,8 +61,9 @@ export default class FragmentJarController extends cc.Component { ...@@ -59,8 +61,9 @@ export default class FragmentJarController extends cc.Component {
private dropFragment() { private dropFragment() {
this._isDropped = true; this._isDropped = true;
const pos = this.node.position; const pos = this.node.position;
// this.node.setSiblingIndex(-1); this.node.setSiblingIndex(-1);
eventTarget.emit(CHECK_FRAGMENT, this.node.name); // eventTarget.emit(CHECK_FRAGMENT, this.node.name);
eventTarget.emit(CHECK_FRAGMENT, this.node);
cc.tween(this.node) cc.tween(this.node)
.delay(0.5) .delay(0.5)
......
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