| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { _decorator, Component, instantiate, Node, Prefab, randomRangeInt, RigidBody2D, Sprite, SpriteFrame, Vec2 } from 'cc';
- import { endPos, UI_Main } from '../../../ui/main/UI_Main';
- import { GameState } from '../../GameState';
- const { ccclass, property } = _decorator;
- @ccclass('Stone')
- export class Stone extends Component {
- state: number
- rigt: RigidBody2D
- @property([SpriteFrame])
- stoneSkin1: SpriteFrame[] = [];
- @property([SpriteFrame])
- stoneSkin2: SpriteFrame[] = [];
- @property([SpriteFrame])
- stoneSkin3: SpriteFrame[] = [];
- @property([SpriteFrame])
- stoneSkin4: SpriteFrame[] = [];
- private uiMain: UI_Main | null = null;
- stoneSpriteFrame: SpriteFrame | null = null;
- start() {
- this.checkStonePosition();
- // this.node.getComponent(Sprite).spriteFrame = GameState.inst.spf
- }
- // 初始化方法,接收精灵帧
- init(uiMain: UI_Main) {
- this.uiMain = uiMain;
- }
- // // 初始化方法,接收精灵帧
- // init(uiMain: UI_Main, spriteFrame: SpriteFrame) {
- // this.uiMain = uiMain;
- // this.stoneSpriteFrame = spriteFrame;
- // // 立即设置精灵帧
- // this.node.getComponent(Sprite).spriteFrame = spriteFrame;
- // }
- update(dt: number) {
- // 每帧检查石头的位置
- this.checkStonePosition();
- }
- // 重置石头状态
- reset() {
- this.node.active = true;
- const rigidBody = this.node.getComponent(RigidBody2D);
- if (rigidBody) {
- rigidBody.linearVelocity = Vec2.ZERO;
- rigidBody.angularVelocity = 0;
- }
- }
- private checkStonePosition() {
- if (this.node.position.y < endPos.ballEndY && this.uiMain) {
- // 使用回收代替销毁
- this.uiMain.recycleStone(this.node);
- }
- }
- }
|