12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import FSprite from "../FSprite";
- /**
- * 默认的AI
- * 警戒范围内
- * 追击范围
- * 仇恨转移
- */
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class AIDef extends cc.Component {
- /**
- * 移动速度
- */
- @property({
- displayName: '移动速度'
- })
- public speedN = 80000;
- /**
- * 移动速度
- */
- @property({
- displayName: '警戒范围'
- })
- public dis = 500;
- /**
- * 当前AI控制的精灵
- */
- public sprite:FSprite = null;
- /**
- * 当前仇恨目标
- */
- public target:FSprite = null;
- onLoad () {
- this.sprite = this.node.getComponent(FSprite);
- this.sprite.mRigidBody.linearDamping = 60;
- }
-
- update (dt) {
- if (this.sprite.gamePause) {
- return;
- }
- if (this.sprite.isWalk) {
- let moveV2 = this.sprite.moveV2;
- this.sprite.mRigidBody.applyLinearImpulse(
- cc.v2(moveV2.x * this.speedN * dt, moveV2.y * this.speedN * dt),
- this.sprite.mRigidBody.getWorldCenter(),
- true
- );
- }
- }
- }
|