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

update shake behind fragment

parent de9d9ed7
This diff is collapsed.
......@@ -26,6 +26,7 @@ export const CHECK_FRAGMENT = 'CHECK_FRAGMENT';
export const HAMMER = 'HAMMER';
export const RESET_BOTTLE = 'RESET_BOTTLE';
export const RESET_FRAGMENT = 'RESET_FRAGMENT';
export const DROP_FRAGMENT = 'DROP_FRAGMENT';
export const DROP_ALL_FRAGMENT = 'DROP_ALL_FRAGMENT';
export const DROP_TOP_FRAGMENT = 'DROP_TOP_FRAGMENT';
export const DROP_BEHIND_FRAGMENT = 'DROP_BEHIND_FRAGMENT';
export const SHAKE_FRAGMENT = 'SHAKE_FRAGMENT';
\ No newline at end of file
import { eventTarget, RESET_FRAGMENT } from "../Events";
import { eventTarget, RESET_FRAGMENT, SHAKE_FRAGMENT } from "../Events";
const { ccclass, property } = cc._decorator;
......@@ -7,6 +7,7 @@ const { ccclass, property } = cc._decorator;
export default class BehindFragment extends cc.Component {
private _rg: cc.RigidBody = null;
private _physicsCollider: cc.PhysicsCollider = null;
private _isDropped: boolean = false;
onLoad() {
this._rg = this.node.getComponent(cc.RigidBody);
......@@ -15,9 +16,22 @@ export default class BehindFragment extends cc.Component {
this._physicsCollider.enabled = false;
eventTarget.on(RESET_FRAGMENT, this.reset, this);
eventTarget.on(SHAKE_FRAGMENT, this.shakeFragment, this);
}
public shakeFragment() {
if (this._isDropped) {
return;
}
cc.tween(this.node)
.repeat(2, cc.tween(this.node)
.by(0.05, { position: cc.v3(-10, -10) })
.by(0.05, { position: cc.v3(10, 10) })
)
.start();
}
public onDrop() {
this._isDropped = true;
this.scheduleOnce(() => {
this._rg.type = cc.RigidBodyType.Dynamic;
this._rg.gravityScale = 10;
......
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_ALL_FRAGMENT, eventTarget, HAMMER, RESET_BOTTLE, RESET_FRAGMENT, SHOW_CARD_POPUP, STOP_GUILD_TAP } from "../Events";
import { Global } from "../Global";
import FragmentController from "./FragmentController";
......@@ -87,7 +87,7 @@ export default class BreakingBottleController extends cc.Component {
this._isEnd = true;
}
if (this._bodyFragments.length == 6) {
eventTarget.emit(DROP_FRAGMENT);
eventTarget.emit(DROP_ALL_FRAGMENT);
}
}
......
import { BEAT_GUILD, CHECK_FRAGMENT, CHECK_TOUCH, eventTarget, HAMMER, RESET_BOTTLE, RESET_FRAGMENT, SHAKE_FRAGMENT, SHOW_CARD_POPUP, STOP_GUILD_TAP } from "../Events";
import { BEAT_GUILD, CHECK_FRAGMENT, CHECK_TOUCH, DROP_TOP_FRAGMENT, eventTarget, HAMMER, RESET_BOTTLE, RESET_FRAGMENT, SHAKE_FRAGMENT, SHOW_CARD_POPUP, STOP_GUILD_TAP } from "../Events";
import { Global } from "../Global";
import BehindFragment from "./BehindFragment";
import FragmentJarController from "./FragmentJarController";
......@@ -7,7 +7,8 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class BreakingJarController extends cc.Component {
@property([cc.Node])
private fragmentSpecialNodes: cc.Node[] = [];
@property(cc.Node)
private hammerNode: cc.Node = null;
@property(cc.Node)
......@@ -18,7 +19,7 @@ export default class BreakingJarController extends cc.Component {
private _countFragment = 0;
private _fragmentsPosition: cc.Vec3[] = [];
private _fragmentsNode: cc.Node[] = [];
private _fontFragments: cc.Node[] = [];
private _bodyFragments: string[] = [];
private _isEnd = false;
private _behindJarChild: BehindFragment[] = [];
......@@ -41,8 +42,8 @@ export default class BreakingJarController extends cc.Component {
eventTarget.on(RESET_BOTTLE, this.resetBottle, this);
eventTarget.on(BEAT_GUILD, this.beatGuild, this);
this._fragmentsNode = this.getComponentsInChildren(FragmentJarController).map(item => item.node);
this._fragmentsPosition = this._fragmentsNode.map(item => item.position.clone());
this._fontFragments = this.getComponentsInChildren(FragmentJarController).map(item => item.node);
this._fragmentsPosition = this._fontFragments.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());
}
......@@ -60,7 +61,7 @@ export default class BreakingJarController extends cc.Component {
this._bodyFragments = [];
this._spine.setSkin(this._skins[Global.tool % this._skins.length]);
this._fragmentsNode.forEach((node, index) => {
this._fontFragments.forEach((node, index) => {
node.position = this._fragmentsPosition[index];
})
......@@ -89,7 +90,7 @@ export default class BreakingJarController extends cc.Component {
private shakeNode() {
cc.director.getPhysicsManager().enabled = false;
eventTarget.emit(SHAKE_FRAGMENT)
eventTarget.emit(SHAKE_FRAGMENT);
cc.tween(this.node)
.delay(0.15)
.call(() => cc.director.getPhysicsManager().enabled = true)
......@@ -97,8 +98,8 @@ export default class BreakingJarController extends cc.Component {
}
private checkFragment(fragmentNode: cc.Node) {
const fragmentIndex = this._fragmentsNode.findIndex(item => item === fragmentNode);
const behindFragment = this._behindJarChild[fragmentIndex];
const fontFragment = this._fontFragments.findIndex(item => item === fragmentNode);
const behindFragment = this._behindJarChild[fontFragment];
behindFragment.onDrop();
if (this._isEnd) {
......@@ -107,9 +108,20 @@ export default class BreakingJarController extends cc.Component {
this._bodyFragments.push(fragmentNode.name);
this._countFragment++;
if (this._countFragment == 8) {
if (this._countFragment == 9) {
console.log('this._countFragment', this._countFragment)
this.scheduleOnce(() => eventTarget.emit(SHOW_CARD_POPUP), 1.5);
this._isEnd = true;
return;
}
const isSpecial = this.fragmentSpecialNodes.some(item => item === fragmentNode);
const isDropTop = this.fragmentSpecialNodes.every(item => item.getComponent(FragmentJarController).isDropped);
if (isSpecial && isDropTop) {
console.log('this._countFragment', this._countFragment)
eventTarget.emit(DROP_TOP_FRAGMENT);
}
}
......
import { eventTarget, CHECK_TOUCH, CHECK_FRAGMENT, HAMMER, RESET_FRAGMENT, PLAY_DROP_SOUND, DROP_FRAGMENT } from "../Events";
import { eventTarget, CHECK_TOUCH, CHECK_FRAGMENT, HAMMER, RESET_FRAGMENT, PLAY_DROP_SOUND, DROP_ALL_FRAGMENT } from "../Events";
const { ccclass, property } = cc._decorator;
......@@ -22,7 +22,7 @@ export default class FragmentController extends cc.Component {
eventTarget.on(CHECK_TOUCH, this.checkTouch, this);
eventTarget.on(RESET_FRAGMENT, this.reset, this);
eventTarget.on(DROP_FRAGMENT, () => this.node.name.includes('nap') && this.dropFragment(), this);
eventTarget.on(DROP_ALL_FRAGMENT, () => this.node.name.includes('nap') && this.dropFragment(), this);
}
public reset() {
......
import { CHECK_FRAGMENT, CHECK_TOUCH, DROP_FRAGMENT, eventTarget, HAMMER, PLAY_DROP_SOUND, RESET_FRAGMENT, SHAKE_FRAGMENT } from "../Events";
import { CHECK_FRAGMENT, CHECK_TOUCH, DROP_ALL_FRAGMENT, DROP_TOP_FRAGMENT, eventTarget, HAMMER, PLAY_DROP_SOUND, RESET_FRAGMENT, SHAKE_FRAGMENT } from "../Events";
const { ccclass, property } = cc._decorator;
......@@ -9,14 +9,15 @@ export default class FragmentJarController extends cc.Component {
@property
private isBottom: boolean = false;
public isDropped: 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;
private _numberOfBeats = 3;
private _slots: cc.Node[] = [];
onLoad() {
this._physicsCollider = this.node.getComponent(cc.PhysicsPolygonCollider);
this._physicsColliderFragmentLink = this.fragmentLink && this.fragmentLink.getComponent(cc.PhysicsPolygonCollider);
......@@ -29,7 +30,8 @@ export default class FragmentJarController extends cc.Component {
eventTarget.on(CHECK_TOUCH, this.checkTouch, this);
eventTarget.on(RESET_FRAGMENT, this.reset, this);
eventTarget.on(DROP_FRAGMENT, () => this.node.name.includes('nap') && this.dropFragment(), this);
eventTarget.on(DROP_ALL_FRAGMENT, this.dropFragment, this);
eventTarget.on(DROP_TOP_FRAGMENT, this.dropFragmentTop, this);
eventTarget.on(SHAKE_FRAGMENT, this.shakeFragment, this);
}
......@@ -38,15 +40,16 @@ export default class FragmentJarController extends cc.Component {
this._rg.type = cc.RigidBodyType.Static;
this.node.angle = 0;
this.node.setSiblingIndex(this._siblingIndex);
this._isDropped = false;
this.isDropped = false;
this._numberOfBeats = 3;
this.node.children.forEach(slot => slot.active = false);
}
public shakeFragment() {
if (this._isDropped) {
if (this.isDropped) {
return;
}
cc.tween(this.node)
.repeat(2, cc.tween(this.node)
.by(0.05, { position: cc.v3(-10, -10) })
......@@ -56,7 +59,7 @@ export default class FragmentJarController extends cc.Component {
}
private checkTouch(point: cc.Vec2) {
if (this._isDropped || this.isBottom) {
if (this.isDropped) {
return;
}
const pos = point.clone().subtract(cc.v2(this.node.position.x, this.node.position.y));
......@@ -84,13 +87,31 @@ export default class FragmentJarController extends cc.Component {
}
eventTarget.emit(HAMMER, point);
if (this._numberOfBeats <= 0) {
this.dropFragment();
if (this._numberOfBeats > 0) {
return;
}
if (this.isBottom) {
eventTarget.emit(DROP_ALL_FRAGMENT)
return;
}
this.dropFragment();
}
private dropFragmentTop() {
if (this.isBottom) {
return;
}
this.dropFragment();
}
private dropFragment() {
this._isDropped = true;
if (this.isDropped) {
return;
}
this.isDropped = true;
const pos = this.node.position;
eventTarget.emit(CHECK_FRAGMENT, 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