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

fix BreakingBottleController, add reset bottle

parent 5fabb20b
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -23,4 +23,5 @@ export const STOP_GUILD_TAP = 'STOP_GUILD_TAP'; ...@@ -23,4 +23,5 @@ export const STOP_GUILD_TAP = 'STOP_GUILD_TAP';
export const CHECK_TOUCH = 'CHECK_TOUCH'; export const CHECK_TOUCH = 'CHECK_TOUCH';
export const CHECK_FRAGMENT = 'CHECK_FRAGMENT'; export const CHECK_FRAGMENT = 'CHECK_FRAGMENT';
export const HAMMER = 'HAMMER'; export const HAMMER = 'HAMMER';
\ No newline at end of file export const RESET_BOTTLE = 'RESET_BOTTLE';
\ No newline at end of file
import { CHECK_FRAGMENT, CHECK_TOUCH, eventTarget, HAMMER } from "../Events"; import { CHECK_FRAGMENT, CHECK_TOUCH, eventTarget, HAMMER, RESET_BOTTLE, SHOW_CARD_POPUP } from "../Events";
import { Global } from "../Global"; import { Global } from "../Global";
import FragmentController from "./FragmentController"; import FragmentController from "./FragmentController";
import TheController from "./TheController"; import TheController from "./TheController";
...@@ -13,26 +13,44 @@ export default class BreakingBottleController extends cc.Component { ...@@ -13,26 +13,44 @@ export default class BreakingBottleController extends cc.Component {
private _spine: sp.Skeleton = null; private _spine: sp.Skeleton = null;
private _skins = ["Ga", "Gai_lung", "Gay", "Bua",]; private _skins = ["Ga", "Gai_lung", "Gay", "Bua",];
private _cardNode: cc.Node = null;
private _countFragment = 0; private _countFragment = 0;
private _fragmentsPosition: cc.Vec3[] = [];
private _fragmentsNode: cc.Node[] = [];
onLoad() { onLoad() {
cc.director.getPhysicsManager().enabled = true; cc.director.getPhysicsManager().enabled = true;
this._spine = this.hammerNode.getComponentInChildren(sp.Skeleton); this._spine = this.hammerNode.getComponentInChildren(sp.Skeleton);
this._cardNode = this.node.getComponentInChildren(TheController).node;
this._cardNode.active = false;
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this); this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this); this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
eventTarget.on(CHECK_FRAGMENT, this.checkFragment, this); eventTarget.on(CHECK_FRAGMENT, this.checkFragment, this);
eventTarget.on(HAMMER, this.onHammer, this); eventTarget.on(HAMMER, this.onHammer, this);
eventTarget.on(RESET_BOTTLE, this.resetBottle, this);
this._fragmentsNode = this.getComponentsInChildren(FragmentController).map(item => item.node);
console.log('this._fragmentsAll', this._fragmentsNode)
this._fragmentsPosition = this._fragmentsNode.map(item => item.position.clone());
} }
protected start(): void { protected start(): void {
this.hideHammer(); this.hideHammer();
} }
private resetBottle() {
this._countFragment = 0;
this._spine.setSkin(this._skins[Global.tool % this._skins.length]);
this._spine.setAnimation(0, "Dap4", false);
this._fragmentsNode.forEach((item, index) => {
item.position = this._fragmentsPosition[index];
item.getComponent(FragmentController).reset();
})
}
private onHammer(newPos: cc.Vec2) { private onHammer(newPos: cc.Vec2) {
cc.tween(this.hammerNode) cc.tween(this.hammerNode)
.to(0.1, { opacity: 255, position: cc.v3(newPos.x, newPos.y) }) .to(0.1, { opacity: 255, position: cc.v3(newPos.x, newPos.y) })
...@@ -44,14 +62,13 @@ export default class BreakingBottleController extends cc.Component { ...@@ -44,14 +62,13 @@ export default class BreakingBottleController extends cc.Component {
private checkFragment(name: string) { private checkFragment(name: string) {
this._countFragment++; this._countFragment++;
if (this._countFragment == 8) { if (this._countFragment == 8) {
this._cardNode.active = true; eventTarget.emit(SHOW_CARD_POPUP);
} }
} }
private onTouchStart(event: cc.Event.EventTouch) { private onTouchStart(event: cc.Event.EventTouch) {
const pos = event.getLocation(); const pos = event.getLocation();
const nodePos = this.node.convertToNodeSpaceAR(pos); const nodePos = this.node.convertToNodeSpaceAR(pos);
const newPos = cc.v3(nodePos.x, nodePos.y);
eventTarget.emit(CHECK_TOUCH, nodePos); eventTarget.emit(CHECK_TOUCH, nodePos);
......
...@@ -9,18 +9,26 @@ export default class FragmentController extends cc.Component { ...@@ -9,18 +9,26 @@ export default class FragmentController extends cc.Component {
private _collider: cc.PolygonCollider = null; private _collider: cc.PolygonCollider = null;
private _physicsCollider: cc.PhysicsPolygonCollider = null; private _physicsCollider: cc.PhysicsPolygonCollider = null;
private _rg: cc.RigidBody = null; private _rg: cc.RigidBody = null;
private _siblingIndex: number = 0;
onLoad() { onLoad() {
this._collider = this.node.getComponent(cc.PolygonCollider); this._collider = this.node.getComponent(cc.PolygonCollider);
this._physicsCollider = this.node.getComponent(cc.PhysicsPolygonCollider); this._physicsCollider = this.node.getComponent(cc.PhysicsPolygonCollider);
this._physicsCollider.points = this._collider.points; this._physicsCollider.points = this._collider.points;
this._physicsCollider.enabled = false;
this._rg = this.node.getComponent(cc.RigidBody); this._rg = this.node.getComponent(cc.RigidBody);
this._rg.type = cc.RigidBodyType.Static; this._siblingIndex = this.node.getSiblingIndex();
this.reset();
eventTarget.on(CHECK_TOUCH, this.checkTouch, this); eventTarget.on(CHECK_TOUCH, this.checkTouch, this);
} }
public reset() {
this._physicsCollider.enabled = false;
this._rg.type = cc.RigidBodyType.Static;
this.node.angle = 0;
this.node.setSiblingIndex(this._siblingIndex);
}
private checkTouch(point: cc.Vec2) { private checkTouch(point: cc.Vec2) {
const pos = point.clone().subtract(cc.v2(this.node.position.x, this.node.position.y)); const pos = point.clone().subtract(cc.v2(this.node.position.x, this.node.position.y));
......
import { eventTarget, SHOW_ACTION_SCREEN, SHOW_START_SCREEN } from "../Events"; import { eventTarget, RESET_BOTTLE, SHOW_ACTION_SCREEN, SHOW_START_SCREEN } from "../Events";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -8,28 +8,18 @@ export default class BreakingBottleScreen extends cc.Component { ...@@ -8,28 +8,18 @@ export default class BreakingBottleScreen extends cc.Component {
onLoad() { onLoad() {
eventTarget.on(SHOW_ACTION_SCREEN, this.showScreen, this); eventTarget.on(SHOW_ACTION_SCREEN, this.showScreen, this);
eventTarget.on(SHOW_START_SCREEN, this.hideScreen, this); eventTarget.on(SHOW_START_SCREEN, this.hideScreen, this);
// this.node.position = cc.v3(400, 600, 0); this.node.position = cc.v3(0, 0, 0);
} this.node.opacity = 0;
private hideBottle() {
// this.bottleAction.active = true;
// this.bottleIdle.active = false;
} }
private showScreen() { private showScreen() {
console.log('showScreen', this.node) this.node.opacity = 255;
// this.bottleAction.active = false;
// this.bottleIdle.active = true;
// this._spine.setAnimation(0, 'Idle', true);
// this._buaController.onSetTool();
this.node.active = true;
this.node.position = cc.v3(); this.node.position = cc.v3();
eventTarget.emit(RESET_BOTTLE);
} }
private hideScreen() { private hideScreen() {
this.node.active = false; this.node.opacity = 0;
} }
} }
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