AIDef.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. this.AI()
  42. if (this.sprite.isWalk) {
  43. let moveV2 = this.sprite.moveV2;
  44. this.sprite.mRigidBody.applyLinearImpulse(
  45. cc.v2(moveV2.x * this.speedN * dt, moveV2.y * this.speedN * dt),
  46. this.sprite.mRigidBody.getWorldCenter(),
  47. true
  48. );
  49. }
  50. }
  51. public AI(){
  52. if(this.target && this.target.node.isValid && this.target.isActive){
  53. }else{
  54. }
  55. }
  56. }