import { _decorator, Component, Node } from 'cc';
import { app } from '../../../App';
import { GModeEvent } from '../../../battle/modes/GMode';
import { tween } from 'cc';
import { Vec3 } from 'cc';
import RandomUtil from '../../../../../extensions/ngame/assets/ngame/util/RandomUtil';
import { v3 } from 'cc';
const { ccclass, property } = _decorator;

//游戏震屏
@ccclass('ModeShakeScreen')
export class ModeShakeScreen extends Component {

    local:Vec3;

    onLoad(){

        this.local = this.node.position.clone();
        app.event.on(GModeEvent.HIT,this.onShakeScreen,this);

    }

    protected onDestroy(): void {

        app.event.off(GModeEvent.HIT,this.onShakeScreen,this);

    }

    onShakeScreen(){

        tween(this.node).
            to(0.1, { position: this.local.clone().add(v3(RandomUtil.RandomInt(-5, 5), RandomUtil.RandomInt(-5, 0), 0)) })
            .call(() => {
                tween(this.node).to(0.1 / 2, { position: this.local.clone() }).start();
            })
            .start();

    }


}


