123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { _decorator, BoxCollider2D, Collider2D, Component, Contact2DType, game, Node, tween, UIOpacity } from 'cc';
- import { GameManager } from '../Manager/GameManager';
- import { AudioManage } from '../Manager/AudioManage';
- import { Global } from '../Common/Global';
- const { ccclass, property } = _decorator;
- @ccclass('ZhuanKuaiItem')
- export class ZhuanKuaiItem extends Component {
- @property(BoxCollider2D)
- topNode: BoxCollider2D = null;
- @property(BoxCollider2D)
- bottomNode: BoxCollider2D = null;
- @property(BoxCollider2D)
- leftNode: BoxCollider2D = null;
- @property(BoxCollider2D)
- rightNode: BoxCollider2D = null;
- start() {
- this.topNode.on(Contact2DType.BEGIN_CONTACT, (() => {
- console.log("碰到砖块上方!");
- this.gamemain.changeAngle(1);
- this.onHide();
- }));
- this.rightNode.on(Contact2DType.BEGIN_CONTACT, (() => {
- console.log("碰到砖块右方!");
- this.gamemain.changeAngle(2);
- this.onHide();
- }));
- this.leftNode.on(Contact2DType.BEGIN_CONTACT, (() => {
- console.log("碰到砖块左方!");
- this.gamemain.changeAngle(3);
- this.onHide();
- }));
- this.bottomNode.on(Contact2DType.BEGIN_CONTACT, (() => {
- console.log("碰到砖块下方!");
- this.gamemain.changeAngle(4);
- this.onHide();
- }));
- }
- private gamemain;
- private isAddScore = true;
- initUI(gamemain) {
- this.gamemain = gamemain;
- }
- private onHide() {
- if (!GameManager.getInstance().isStartGame) return
- if (GameManager.getInstance().isPaused) return
- if (this.isAddScore) {
- this.isAddScore = false;
- GameManager.getInstance().addScore(this.gamemain.score);
- if (GameManager.getInstance().curLevelScore >= GameManager.getInstance().curLevelData.targetScore) {
- this.gamemain.isMove = false;
- }
- // AudioManage.instance.playSound(Global.Audio_AddScore);
- tween(this.node.getComponent(UIOpacity))
- .to(0.03, { opacity: 0 })
- .to(0.03, { opacity: 255 })
- .call(() => {
- this.node.removeFromParent();
- })
- .start();
- }
- }
- update(deltaTime: number) {
- }
- }
|