|
@@ -1,4 +1,4 @@
|
|
-import { _decorator, Node, Tween, Vec3, ProgressBar, UIOpacity, tween, Label, SkeletalAnimation, Animation, SphereCollider, CylinderCollider, MeshCollider, Collider} from 'cc';
|
|
|
|
|
|
+import { _decorator, Node, Tween, Vec3, ProgressBar, UIOpacity, tween, Label, SkeletalAnimation, Animation, SphereCollider, CylinderCollider, MeshCollider, Collider, PhysicsRayResult} from 'cc';
|
|
import { Game } from './Game';
|
|
import { Game } from './Game';
|
|
import { Player } from './Player';
|
|
import { Player } from './Player';
|
|
import { Utils } from '../utils/Utils';
|
|
import { Utils } from '../utils/Utils';
|
|
@@ -123,6 +123,8 @@ export class Enemy extends BaseExp {
|
|
public angle: number = 0;
|
|
public angle: number = 0;
|
|
//新增警戒状态属性
|
|
//新增警戒状态属性
|
|
public isAlert: boolean = false;
|
|
public isAlert: boolean = false;
|
|
|
|
+ //子弹击中的的位置
|
|
|
|
+ public raycastResults:PhysicsRayResult = null;
|
|
|
|
|
|
start() {
|
|
start() {
|
|
this.hurt_num.active = false;
|
|
this.hurt_num.active = false;
|
|
@@ -167,7 +169,6 @@ export class Enemy extends BaseExp {
|
|
this.hpBar.progress = 1;
|
|
this.hpBar.progress = 1;
|
|
this.hpBar.node.active = false;
|
|
this.hpBar.node.active = false;
|
|
this.endFire();
|
|
this.endFire();
|
|
- this.schedule(this.updateAAAA.bind(this),0.016199);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -401,6 +402,24 @@ export class Enemy extends BaseExp {
|
|
*/
|
|
*/
|
|
public showHurt(hpStr: string) {
|
|
public showHurt(hpStr: string) {
|
|
if(Game.I.isGameOver || this.isDead) return;
|
|
if(Game.I.isGameOver || this.isDead) return;
|
|
|
|
+ //敌人流血特效
|
|
|
|
+ if(this.raycastResults){
|
|
|
|
+ ResUtil.playParticle(
|
|
|
|
+ `effects/Prefabs/blood`,
|
|
|
|
+ 1,
|
|
|
|
+ new Vec3(0.2,0.2,0.2),
|
|
|
|
+ (blood) => {
|
|
|
|
+ blood.active = true;
|
|
|
|
+ blood.setParent(this.raycastResults.collider.node.parent);
|
|
|
|
+ blood.worldPosition = this.raycastResults.hitPoint.add(this.raycastResults.hitNormal.multiplyScalar(0.01));
|
|
|
|
+ blood.forward = this.raycastResults.hitNormal.multiplyScalar(-1);
|
|
|
|
+ /*blood.active = true;
|
|
|
|
+ blood.parent = this.enemyNode.parent;
|
|
|
|
+ const targetPos: Vec3 = this.enemyNode.worldPosition.clone();
|
|
|
|
+ blood.worldPosition = new Vec3(targetPos.x,targetPos.y - 0.2,targetPos.z);*/
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }
|
|
//创建3D伤害数字
|
|
//创建3D伤害数字
|
|
const n = PoolManager.getNode(this.hurt_num, this.hurt_num.parent);
|
|
const n = PoolManager.getNode(this.hurt_num, this.hurt_num.parent);
|
|
let label:Label = n.getComponent(Label);
|
|
let label:Label = n.getComponent(Label);
|
|
@@ -520,7 +539,7 @@ export class Enemy extends BaseExp {
|
|
/**
|
|
/**
|
|
* 更新敌人行走和变化方向
|
|
* 更新敌人行走和变化方向
|
|
*/
|
|
*/
|
|
- protected updateAAAA(dt: number): void {
|
|
|
|
|
|
+ protected update(dt: number): void {
|
|
if(Game.I.isGameOver
|
|
if(Game.I.isGameOver
|
|
|| Game.I.isPause
|
|
|| Game.I.isPause
|
|
|| !this.data
|
|
|| !this.data
|
|
@@ -528,7 +547,7 @@ export class Enemy extends BaseExp {
|
|
const targetPos = this.pathList[this.curMoveIndex];
|
|
const targetPos = this.pathList[this.curMoveIndex];
|
|
if(!targetPos)return;
|
|
if(!targetPos)return;
|
|
//保持速度调节逻辑
|
|
//保持速度调节逻辑
|
|
- dt = dt / Game.I.map.multiplySpeed();
|
|
|
|
|
|
+ //dt = dt / Game.I.map.multiplySpeed();
|
|
const currentPos = this.node.worldPosition.clone();
|
|
const currentPos = this.node.worldPosition.clone();
|
|
const toTarget = targetPos.clone().subtract(currentPos);
|
|
const toTarget = targetPos.clone().subtract(currentPos);
|
|
//敌人移动
|
|
//敌人移动
|
|
@@ -540,14 +559,15 @@ export class Enemy extends BaseExp {
|
|
if(moveDistance > 0) {
|
|
if(moveDistance > 0) {
|
|
//使用标准化方向向量 + 实际移动距离
|
|
//使用标准化方向向量 + 实际移动距离
|
|
const newPos = currentPos.add(toTarget.normalize().multiplyScalar(moveDistance));
|
|
const newPos = currentPos.add(toTarget.normalize().multiplyScalar(moveDistance));
|
|
|
|
+ this.node.worldPosition = newPos;
|
|
//添加移动平滑过渡 平滑系数 10-15比较好 值越大越平滑
|
|
//添加移动平滑过渡 平滑系数 10-15比较好 值越大越平滑
|
|
- const smoothFactor = 20;
|
|
|
|
|
|
+ /*const smoothFactor = 10;
|
|
this.node.worldPosition = Vec3.lerp(
|
|
this.node.worldPosition = Vec3.lerp(
|
|
new Vec3(),
|
|
new Vec3(),
|
|
currentPos,
|
|
currentPos,
|
|
newPos,
|
|
newPos,
|
|
Math.min(1, dt * smoothFactor)
|
|
Math.min(1, dt * smoothFactor)
|
|
- );
|
|
|
|
|
|
+ );*/
|
|
//更新方向
|
|
//更新方向
|
|
const isLastPathPoint = this.curMoveIndex == this.pathList.length - 1;
|
|
const isLastPathPoint = this.curMoveIndex == this.pathList.length - 1;
|
|
const dirTarget = isLastPathPoint
|
|
const dirTarget = isLastPathPoint
|