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

update shake jar when hammer hit

parent c6c9e97a
...@@ -28,3 +28,4 @@ export const RESET_BOTTLE = 'RESET_BOTTLE'; ...@@ -28,3 +28,4 @@ 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'; export const DROP_BEHIND_FRAGMENT = 'DROP_BEHIND_FRAGMENT';
export const SHAKE_FRAGMENT = 'SHAKE_FRAGMENT';
\ 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, eventTarget, HAMMER, RESET_BOTTLE, RESET_FRAGMENT, SHAKE_FRAGMENT, SHOW_CARD_POPUP, STOP_GUILD_TAP } from "../Events";
import { Global } from "../Global"; import { Global } from "../Global";
import BehindFragment from "./BehindFragment"; import BehindFragment from "./BehindFragment";
import FragmentJarController from "./FragmentJarController"; import FragmentJarController from "./FragmentJarController";
...@@ -80,12 +80,22 @@ export default class BreakingJarController extends cc.Component { ...@@ -80,12 +80,22 @@ export default class BreakingJarController extends cc.Component {
cc.tween(this.hammerNode) cc.tween(this.hammerNode)
.to(0.5, { position: cc.v3(newPos.x, newPos.y, 0) }) .to(0.5, { position: cc.v3(newPos.x, newPos.y, 0) })
.call(() => this.shakeNode())
.delay(0.1) .delay(0.1)
.to(0.2, { position: cc.v3(400, -400) }) .to(0.2, { position: cc.v3(400, -400) })
.call(() => this.hammerNode.active = false) .call(() => this.hammerNode.active = false)
.start(); .start();
} }
private shakeNode() {
cc.director.getPhysicsManager().enabled = false;
eventTarget.emit(SHAKE_FRAGMENT)
cc.tween(this.node)
.delay(0.15)
.call(() => cc.director.getPhysicsManager().enabled = true)
.start();
}
private checkFragment(fragmentNode: cc.Node) { private checkFragment(fragmentNode: cc.Node) {
const fragmentIndex = this._fragmentsNode.findIndex(item => item === fragmentNode); const fragmentIndex = this._fragmentsNode.findIndex(item => item === fragmentNode);
const behindFragment = this._behindJarChild[fragmentIndex]; const behindFragment = this._behindJarChild[fragmentIndex];
......
import { CHECK_FRAGMENT, CHECK_TOUCH, DROP_FRAGMENT, eventTarget, HAMMER, PLAY_DROP_SOUND, RESET_FRAGMENT } from "../Events"; import { CHECK_FRAGMENT, CHECK_TOUCH, DROP_FRAGMENT, eventTarget, HAMMER, PLAY_DROP_SOUND, RESET_FRAGMENT, SHAKE_FRAGMENT } from "../Events";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -30,6 +30,7 @@ export default class FragmentJarController extends cc.Component { ...@@ -30,6 +30,7 @@ export default class FragmentJarController extends cc.Component {
eventTarget.on(CHECK_TOUCH, this.checkTouch, this); eventTarget.on(CHECK_TOUCH, this.checkTouch, this);
eventTarget.on(RESET_FRAGMENT, this.reset, this); eventTarget.on(RESET_FRAGMENT, this.reset, this);
eventTarget.on(DROP_FRAGMENT, () => this.node.name.includes('nap') && this.dropFragment(), this); eventTarget.on(DROP_FRAGMENT, () => this.node.name.includes('nap') && this.dropFragment(), this);
eventTarget.on(SHAKE_FRAGMENT, this.shakeFragment, this);
} }
public reset() { public reset() {
...@@ -42,6 +43,18 @@ export default class FragmentJarController extends cc.Component { ...@@ -42,6 +43,18 @@ export default class FragmentJarController extends cc.Component {
this.node.children.forEach(slot => slot.active = false); this.node.children.forEach(slot => slot.active = false);
} }
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();
}
private checkTouch(point: cc.Vec2) { private checkTouch(point: cc.Vec2) {
if (this._isDropped || this.isBottom) { if (this._isDropped || this.isBottom) {
return; return;
......
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