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

move slot to fragment

parent 296dfde1
This diff is collapsed.
......@@ -27,4 +27,3 @@ export const HAMMER = 'HAMMER';
export const RESET_BOTTLE = 'RESET_BOTTLE';
export const RESET_FRAGMENT = 'RESET_FRAGMENT';
export const DROP_FRAGMENT = 'DROP_FRAGMENT';
\ No newline at end of file
export const BEAT_FRAGMENT = 'BEAT_FRAGMENT';
\ No newline at end of file
import { BEAT_FRAGMENT, 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 } from "../Events";
const { ccclass, property } = cc._decorator;
......@@ -9,11 +9,15 @@ export default class FragmentJarController extends cc.Component {
private _siblingIndex: number = 0;
private _isDropped: boolean = false;
private _numberOfBeats = 3;
private _slots: cc.Node[] = [];
onLoad() {
this._physicsCollider = this.node.getComponent(cc.PhysicsPolygonCollider);
this._rg = this.node.getComponent(cc.RigidBody);
this._siblingIndex = this.node.getSiblingIndex();
this._slots = this.node.children;
this._slots.forEach(slot => slot.active = false);
this.reset();
eventTarget.on(CHECK_TOUCH, this.checkTouch, this);
......@@ -41,7 +45,9 @@ export default class FragmentJarController extends cc.Component {
return;
}
eventTarget.emit(BEAT_FRAGMENT, this._siblingIndex, this._numberOfBeats);
if (this._slots.length > 0) {
this._slots[Math.min(3 - this._numberOfBeats, 1)].active = true;
}
this._numberOfBeats--;
eventTarget.emit(HAMMER, point);
......
import { BEAT_FRAGMENT, eventTarget } from "../Events";
const { ccclass, property } = cc._decorator;
@ccclass
export default class SlotController extends cc.Component {
private _slots: cc.Node[][] = [];
protected onLoad(): void {
this._slots = this.node.children.map(fragment => fragment.children.map(slot => {
slot.active = false;
return slot;
}));
console.log('this._slots', this._slots)
eventTarget.on(BEAT_FRAGMENT, this.onBeat, this);
}
private onBeat(fragmentIndex: number, beatIndex: number): void {
if (3 - beatIndex > 1) {
this._slots[fragmentIndex].map(slot => slot.active = false);
return;
}
this._slots[fragmentIndex][3 - beatIndex].active = true;
}
}
{
"ver": "1.1.0",
"uuid": "2dadf33a-b19b-4abb-9a33-ec0d14e46375",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
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