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

update slot when beat

parent 73822ca3
This diff is collapsed.
......@@ -26,4 +26,5 @@ 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';
\ No newline at end of file
export const DROP_FRAGMENT = 'DROP_FRAGMENT';
export const BEAT_FRAGMENT = 'BEAT_FRAGMENT';
\ No newline at end of file
......@@ -30,13 +30,13 @@ export default class BreakingJarController extends cc.Component {
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._behindJarChild = this._behindJar.children;
// this._frontJarChild = this._frontJar.children;
// this._slotsJarChild = this._slotsJar.children;
this._slotsJarChild.forEach((slot) => {
slot.active = false;
})
// this._slotsJarChild.forEach((slot) => {
// slot.active = false;
// })
cc.director.getPhysicsManager().enabled = true;
// cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit |
......
import { CHECK_FRAGMENT, CHECK_TOUCH, DROP_FRAGMENT, eventTarget, HAMMER, PLAY_DROP_SOUND, RESET_FRAGMENT } from "../Events";
import { BEAT_FRAGMENT, CHECK_FRAGMENT, CHECK_TOUCH, DROP_FRAGMENT, eventTarget, HAMMER, PLAY_DROP_SOUND, RESET_FRAGMENT } from "../Events";
const { ccclass, property } = cc._decorator;
......@@ -8,6 +8,7 @@ export default class FragmentJarController extends cc.Component {
private _rg: cc.RigidBody = null;
private _siblingIndex: number = 0;
private _isDropped: boolean = false;
private _numberOfBeats = 3;
onLoad() {
this._physicsCollider = this.node.getComponent(cc.PhysicsPolygonCollider);
......@@ -35,8 +36,16 @@ export default class FragmentJarController extends cc.Component {
const pos = point.clone().subtract(cc.v2(this.node.position.x, this.node.position.y));
let isInside = cc.Intersection.pointInPolygon(pos, this._physicsCollider.points);
if (isInside) {
eventTarget.emit(HAMMER, point);
if (!isInside) {
return;
}
eventTarget.emit(BEAT_FRAGMENT, this._siblingIndex, this._numberOfBeats);
this._numberOfBeats--;
eventTarget.emit(HAMMER, point);
if (this._numberOfBeats <= 0) {
this.dropFragment();
}
}
......@@ -44,7 +53,7 @@ export default class FragmentJarController extends cc.Component {
private dropFragment() {
this._isDropped = true;
const pos = this.node.position;
this.node.setSiblingIndex(-1);
// this.node.setSiblingIndex(-1);
eventTarget.emit(CHECK_FRAGMENT, this.node.name);
cc.tween(this.node)
......
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