"use strict";
cc._RF.push(module, '74e87iK2h9AvYXQaqRFQdb+', 'Z_04_syys_NodeFish');
// Z_04_syys/prefabs/Z_04_syys_NodeFish.js

"use strict";

var _Z_04_syys_utils = require("../script/Z_04_syys_utils");

// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({
  "extends": cc.Component,
  properties: {
    targetPosList: [],
    currentTargetIdx: 0,
    speed: 3,
    offsetX: 0,
    offsetY: 0
  },
  // LIFE-CYCLE CALLBACKS:
  // onLoad () {},
  start: function start() {},
  update: function update(dt) {
    var targetPos = this.targetPosList[this.currentTargetIdx];

    if (!targetPos) {
      return;
    }

    this.node.x += this.speed;
    this.node.y += this.speed * Math.tan(this.node.angle * Math.PI / 180);
    var sideX = targetPos.x + this.offsetX - this.node.x;
    var sideY = targetPos.y + this.offsetY - this.node.y;

    if (targetPos.x - this.node.x <= this.speed) {
      this.currentTargetIdx++;
    }

    var newAngle = Math.atan(sideY / sideX) * 180 / Math.PI;

    if (newAngle < -45) {
      newAngle += 90;
    }

    this.node.angle += (0, _Z_04_syys_utils.Between)(-1, newAngle - this.node.angle, 1);
  }
});

cc._RF.pop();