AIDef.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import FSprite from "../FSprite";
  2. /**
  3. * 默认的AI
  4. * 警戒范围内
  5. * 追击范围
  6. * 仇恨转移
  7. */
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class AIDef extends cc.Component {
  11. /**
  12. * 移动速度
  13. */
  14. @property({
  15. displayName: '移动速度'
  16. })
  17. public speedN = 80000;
  18. /**
  19. * 移动速度
  20. */
  21. @property({
  22. displayName: '警戒范围'
  23. })
  24. public dis = 500;
  25. /**
  26. * 当前AI控制的精灵
  27. */
  28. public sprite:FSprite = null;
  29. /**
  30. * 当前仇恨目标
  31. */
  32. public target:FSprite = null;
  33. onLoad () {
  34. this.sprite = this.node.getComponent(FSprite);
  35. this.sprite.mRigidBody.linearDamping = 60;
  36. }
  37. update (dt) {
  38. if (this.sprite.gamePause) {
  39. return;
  40. }
  41. if (this.sprite.isWalk) {
  42. let moveV2 = this.sprite.moveV2;
  43. this.sprite.mRigidBody.applyLinearImpulse(
  44. cc.v2(moveV2.x * this.speedN * dt, moveV2.y * this.speedN * dt),
  45. this.sprite.mRigidBody.getWorldCenter(),
  46. true
  47. );
  48. }
  49. }
  50. }