import { GameLogic } from "./GameLogic";

const {ccclass, property} = cc._decorator;

@ccclass
export default class MoveTime extends GameLogic {

    private _speed: number = 100;
    public get speed(): number {
        return this._speed;
    }
    public set speed(value: number) {
        this._speed = value;
    }

    private _dirction: cc.Vec2 = cc.v2(0, 0);
    public get dirction(): cc.Vec2 {
        return this._dirction;
    }
    public set dirction(value: cc.Vec2) {
        this._dirction = value;
    }

    private _overTime: number = 0;
    public get overTime(): number {
        return this._overTime;
    }
    public set overTime(value: number) {
        this._overTime = value;
    }

    startTime = 0;
    call:Function = null;
    gameUpdate(dt: number): void {
        this.node.x += this.speed * dt * this.dirction.x;
        this.node.y += this.speed * dt * this.dirction.y;

        this.startTime += dt;
        if(this.startTime >= this._overTime){
            this.call && this.call();
            this.destroy();
        }
    }

}