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

update hammer

parent 5ceadf6d
This diff is collapsed.
......@@ -22,3 +22,5 @@ export const STOP_GUILD_ROTATE = 'STOP_GUILD_ROTATE';
export const STOP_GUILD_TAP = 'STOP_GUILD_TAP';
export const CHECK_TOUCH = 'CHECK_TOUCH';
export const CHECK_FRAGMENT = 'CHECK_FRAGMENT';
export const HAMMER = 'HAMMER';
\ No newline at end of file
import { CHECK_FRAGMENT, CHECK_TOUCH, eventTarget, HAMMER } from "../Events";
import { Global } from "../Global";
import FragmentController from "./FragmentController";
import TheController from "./TheController";
const { ccclass, property } = cc._decorator;
@ccclass
export default class BreakingBottleController extends cc.Component {
private _body: cc.Node = null;
private _lid: cc.Node = null;
private _fragmentsBody: cc.Node[] = [];
private _fragmentsLid: cc.Node[] = [];
private _fragmentsAll: cc.Node[] = [];
@property(cc.Node)
private hammerNode: cc.Node = null;
protected onLoad(): void {
private _spine: sp.Skeleton = null;
private _skins = ["Ga", "Gai_lung", "Gay", "Bua",];
private _cardNode: cc.Node = null;
private _countFragment = 0;
[this._body, this._lid] = this.node.children;
this._fragmentsBody = this._body.children;
this._fragmentsLid = this._lid.children;
this._fragmentsAll = [...this._fragmentsBody, ...this._fragmentsLid];
onLoad() {
cc.director.getPhysicsManager().enabled = true;
this._spine = this.hammerNode.getComponentInChildren(sp.Skeleton);
this._cardNode = this.node.getComponentInChildren(TheController).node;
this._cardNode.active = false;
// console.log('this._fragmentsAll', this._fragmentsAll.map(item => item.position.toString()));
this.node.position = cc.v3(0, 0);
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
eventTarget.on(CHECK_FRAGMENT, this.checkFragment, this);
eventTarget.on(HAMMER, this.onHammer, this);
}
// this._fragmentsAll.forEach(item => {
// item.addComponent(FragmentController);
// })
protected start(): void {
this.hideHammer();
}
private onHammer(newPos: cc.Vec2) {
cc.tween(this.hammerNode)
.to(0.1, { opacity: 255, position: cc.v3(newPos.x, newPos.y) })
.delay(0.7)
.to(0.2, { opacity: 0 })
.start();
}
private checkFragment(name: string) {
this._countFragment++;
if (this._countFragment == 8) {
this._cardNode.active = true;
}
}
private onTouchStart(event: cc.Event.EventTouch) {
const pos = event.getLocation();
const nodePos = this.node.convertToNodeSpaceAR(pos);
const newPos = cc.v3(nodePos.x, nodePos.y);
eventTarget.emit(CHECK_TOUCH, nodePos);
this._spine.setSkin(this._skins[Global.tool % this._skins.length]);
this._spine.setAnimation(0, "Dap4", false);
}
private onTouchEnd(event: cc.Event.EventTouch) {
}
private hideHammer() {
this.hammerNode.opacity = 0;
}
}
import { eventTarget, CHECK_TOUCH } from "../Events";
import { eventTarget, CHECK_TOUCH, CHECK_FRAGMENT, HAMMER } from "../Events";
const { ccclass, property } = cc._decorator;
......@@ -25,6 +25,7 @@ export default class FragmentController extends cc.Component {
let isInside = cc.Intersection.pointInPolygon(pos, this._collider.points);
if (isInside) {
eventTarget.emit(HAMMER, point);
this.dropFragment();
}
}
......@@ -33,6 +34,7 @@ export default class FragmentController extends cc.Component {
const pos = this.node.position;
this.node.setSiblingIndex(-1);
cc.tween(this.node)
.delay(0.5)
.to(0.2, { scale: 0.95 })
.to(0.2, { scale: 1.05, position: pos.clone().multiplyScalar(1.2) })
.call(() => {
......@@ -40,6 +42,10 @@ export default class FragmentController extends cc.Component {
this._rg.type = cc.RigidBodyType.Dynamic;
this._rg.gravityScale = 5;
})
.delay(1)
.call(() => {
eventTarget.emit(CHECK_FRAGMENT, this.node.name);
})
.start();
}
}
......@@ -14,6 +14,7 @@ export default class TheController extends cc.Component {
protected onLoad(): void {
this._textSprite = this.getComponentInChildren(cc.Sprite);
this._spine = this.node.getComponent(sp.Skeleton);
this._spine.setCompleteListener((trackEntry) => {
if (trackEntry.animation.name == 'Open') {
this._spine.setAnimation(0, 'Idle', true);
......
import { eventTarget, CHECK_TOUCH } from "../Events";
const { ccclass, property } = cc._decorator;
@ccclass
export default class BreakingBottleScreen extends cc.Component {
@property(cc.Node)
private spriteNode: cc.Node = null;
@property(cc.Node)
private hammerNode: cc.Node = null;
onLoad() {
cc.director.getPhysicsManager().enabled = true;
this.node.position = cc.v3(0, 0);
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
}
private onTouchStart(event: cc.Event.EventTouch) {
const pos = event.getLocation();
const nodePos = this.node.convertToNodeSpaceAR(pos);
this.spriteNode.position = cc.v3(nodePos.x, nodePos.y);
eventTarget.emit(CHECK_TOUCH, nodePos);
this.hammerNode.position = cc.v3(nodePos.x, nodePos.y);
}
}
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