|
@@ -144,6 +144,13 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ EnemySetCollider(setNode, collisionGroup) {
|
|
|
|
+ var collider = setNode.getChildByName("collider");
|
|
|
|
+ var physicsCollider = setNode.getComponent(Laya.PhysicsCollider);
|
|
|
|
+ if (physicsCollider) {
|
|
|
|
+ physicsCollider.collisionGroup = collisionGroup;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
static RandomNumber(from, to) {
|
|
static RandomNumber(from, to) {
|
|
if (from >= to) {
|
|
if (from >= to) {
|
|
return 0;
|
|
return 0;
|
|
@@ -442,7 +449,7 @@
|
|
class Runner extends Laya.Script3D {
|
|
class Runner extends Laya.Script3D {
|
|
constructor() {
|
|
constructor() {
|
|
super();
|
|
super();
|
|
- this.m_raydistance = 20;
|
|
|
|
|
|
+ this.m_raydistance = 1000;
|
|
this.canmove = false;
|
|
this.canmove = false;
|
|
this._speed = 1;
|
|
this._speed = 1;
|
|
this._press = false;
|
|
this._press = false;
|
|
@@ -454,10 +461,6 @@
|
|
this.NormalizeSpeed = new Vector3$2();
|
|
this.NormalizeSpeed = new Vector3$2();
|
|
this.curpos = new Vector3$2();
|
|
this.curpos = new Vector3$2();
|
|
this.offest = new Vector3$2();
|
|
this.offest = new Vector3$2();
|
|
- this.arspeed = 0;
|
|
|
|
- this.arrowspeed = 2;
|
|
|
|
- this.offsetpos = new Vector3$2();
|
|
|
|
- this.curpos2 = new Vector3$2();
|
|
|
|
}
|
|
}
|
|
static get Instance() {
|
|
static get Instance() {
|
|
if (Runner.ins) {
|
|
if (Runner.ins) {
|
|
@@ -507,11 +510,6 @@
|
|
this.currot = new Laya.Quaternion(0, this.currot.y, 0);
|
|
this.currot = new Laya.Quaternion(0, this.currot.y, 0);
|
|
this.m_player.transform.rotation = this.currot;
|
|
this.m_player.transform.rotation = this.currot;
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- Laya.Quaternion.slerp(this.m_player.transform.rotation, new Laya.Quaternion(0, 0, 0, 0), 0.1, this.currot);
|
|
|
|
- this.currot = new Laya.Quaternion(0, this.currot.y, 0);
|
|
|
|
- this.m_player.transform.rotation = this.currot;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
Move(_dir, _speed) {
|
|
Move(_dir, _speed) {
|
|
var sp = GameTools.Instance.lerp(this.curspeed, _speed, 0.1);
|
|
var sp = GameTools.Instance.lerp(this.curspeed, _speed, 0.1);
|
|
@@ -561,16 +559,19 @@
|
|
this.m_animator.play("Horse_Run");
|
|
this.m_animator.play("Horse_Run");
|
|
}
|
|
}
|
|
RayCheck() {
|
|
RayCheck() {
|
|
- if (this.DownRayCheck) ;
|
|
|
|
|
|
+ if (this.DownRayCheck) {
|
|
|
|
+ this.m_player.transform.position = new Vector3$2(this.m_player.transform.position.x, this.DownHit.point.y, this.m_player.transform.position.z);
|
|
|
|
+ }
|
|
if (this.FowardRayCheck) {
|
|
if (this.FowardRayCheck) {
|
|
|
|
+ console.log("射线打到了---", this.FowardHit.collider.owner.name);
|
|
this.CrashBarrier();
|
|
this.CrashBarrier();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
CrashBarrier() {
|
|
CrashBarrier() {
|
|
var target = this.FowardHit.collider.owner;
|
|
var target = this.FowardHit.collider.owner;
|
|
if (target.name == "") ;
|
|
if (target.name == "") ;
|
|
- else if (target.name == "") ;
|
|
|
|
- else if (target.name == "") ;
|
|
|
|
|
|
+ else if (target.name == "fire") ;
|
|
|
|
+ else if (target.name == "fence") ;
|
|
else if (target.name == "") ;
|
|
else if (target.name == "") ;
|
|
}
|
|
}
|
|
get DownRayCheck() {
|
|
get DownRayCheck() {
|
|
@@ -605,8 +606,15 @@
|
|
let testRay = new Laya.Ray(this.m_raypos.transform.position, forw);
|
|
let testRay = new Laya.Ray(this.m_raypos.transform.position, forw);
|
|
let hitRes = new Laya.HitResult();
|
|
let hitRes = new Laya.HitResult();
|
|
let isHit = AssetManager.Instance.mainscene.physicsSimulation.rayCast(testRay, hitRes, this.m_raydistance);
|
|
let isHit = AssetManager.Instance.mainscene.physicsSimulation.rayCast(testRay, hitRes, this.m_raydistance);
|
|
- let foward = Transform3DHelper.getForward(arrow.transform).clone();
|
|
|
|
- this.ArrowMove(arrow, new Vector3$2(-foward.x, -foward.y, -foward.z));
|
|
|
|
|
|
+ if (isHit) {
|
|
|
|
+ let target = hitRes.collider.owner;
|
|
|
|
+ let pos = target.transform.position.clone();
|
|
|
|
+ arrow.transform.translate(pos);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ let foward = Transform3DHelper.getForward(arrow.transform).clone();
|
|
|
|
+ this.ArrowMove(arrow, new Vector3$2(-foward.x, -foward.y, -foward.z));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
ArrowMove(_arrow, _dir) {
|
|
ArrowMove(_arrow, _dir) {
|
|
Laya.timer.frameLoop(1, this, () => {
|
|
Laya.timer.frameLoop(1, this, () => {
|
|
@@ -873,9 +881,126 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ var Vector3$4 = Laya.Vector3;
|
|
|
|
+ var NpcState;
|
|
|
|
+ (function (NpcState) {
|
|
|
|
+ NpcState[NpcState["Attack"] = 0] = "Attack";
|
|
|
|
+ NpcState[NpcState["Ilde"] = 1] = "Ilde";
|
|
|
|
+ NpcState[NpcState["Win"] = 2] = "Win";
|
|
|
|
+ NpcState[NpcState["Pursue"] = 3] = "Pursue";
|
|
|
|
+ NpcState[NpcState["Run"] = 4] = "Run";
|
|
|
|
+ })(NpcState || (NpcState = {}));
|
|
|
|
+ class NpcRunner extends Laya.Script {
|
|
|
|
+ constructor() {
|
|
|
|
+ super();
|
|
|
|
+ this.m_distance = 30;
|
|
|
|
+ this.m_distanceatk = 15;
|
|
|
|
+ this.DIE = false;
|
|
|
|
+ this.m_npcspeed = 1;
|
|
|
|
+ this.canmove = false;
|
|
|
|
+ this.offest = new Vector3$4();
|
|
|
|
+ this.curpos = new Vector3$4();
|
|
|
|
+ NpcRunner.ins = this;
|
|
|
|
+ EventManager.StageOn(StageState.Start, this, this.Begin);
|
|
|
|
+ }
|
|
|
|
+ static get Instance() {
|
|
|
|
+ if (NpcRunner.ins) {
|
|
|
|
+ return NpcRunner.ins;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return new NpcRunner();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ onAwake() {
|
|
|
|
+ this.m_npcmodel = this.owner;
|
|
|
|
+ this.m_npcanimator = this.owner.getComponent(Laya.Animator);
|
|
|
|
+ this.player = GameManager.Instance.CharacterArray[0];
|
|
|
|
+ }
|
|
|
|
+ Begin() {
|
|
|
|
+ this.ChangeState(NpcState.Ilde);
|
|
|
|
+ }
|
|
|
|
+ onUpdate() {
|
|
|
|
+ var distance = Vector3$4.distance(this.player.transform.position, this.m_npcmodel.transform.position);
|
|
|
|
+ if (distance < this.m_distance && distance > this.m_distanceatk) {
|
|
|
|
+ this.canmove = true;
|
|
|
|
+ this.ChangeState(NpcState.Run);
|
|
|
|
+ }
|
|
|
|
+ else if (distance <= this.m_distanceatk) {
|
|
|
|
+ this.canmove = false;
|
|
|
|
+ this.ChangeState(NpcState.Attack);
|
|
|
|
+ }
|
|
|
|
+ this.Move(new Vector3$4(0, 0, -1), 1);
|
|
|
|
+ }
|
|
|
|
+ Move(_dir, _speed) {
|
|
|
|
+ if (this.canmove) {
|
|
|
|
+ var sp = GameTools.Instance.lerp(this.m_npcspeed, _speed, 0.1);
|
|
|
|
+ this.m_npcspeed = sp;
|
|
|
|
+ Vector3$4.scale(_dir, this.m_npcspeed, this.offest);
|
|
|
|
+ Vector3$4.add(this.m_npcmodel.transform.position, this.offest, this.curpos);
|
|
|
|
+ Vector3$4.lerp(this.m_npcmodel.transform.position, this.curpos, 0.15, this.curpos);
|
|
|
|
+ this.curpos = new Vector3$4(this.curpos.x, this.curpos.y, this.curpos.z);
|
|
|
|
+ this.m_npcmodel.transform.position = this.curpos;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ChangeState(_state) {
|
|
|
|
+ if (this.npc_state == _state)
|
|
|
|
+ return;
|
|
|
|
+ this.npc_state = _state;
|
|
|
|
+ switch (this.npc_state) {
|
|
|
|
+ case NpcState.Attack:
|
|
|
|
+ this.Attack();
|
|
|
|
+ break;
|
|
|
|
+ case NpcState.Pursue:
|
|
|
|
+ this.Pursue();
|
|
|
|
+ break;
|
|
|
|
+ case NpcState.Win:
|
|
|
|
+ this.Win();
|
|
|
|
+ break;
|
|
|
|
+ case NpcState.Ilde:
|
|
|
|
+ this.Idle();
|
|
|
|
+ break;
|
|
|
|
+ case NpcState.Run:
|
|
|
|
+ this.Run();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Idle() {
|
|
|
|
+ this.m_npcanimator.play("Idle");
|
|
|
|
+ }
|
|
|
|
+ Attack() {
|
|
|
|
+ this.m_npcanimator.play("JumpOver");
|
|
|
|
+ }
|
|
|
|
+ Win() {
|
|
|
|
+ this.m_npcanimator.play("Victory Idle");
|
|
|
|
+ }
|
|
|
|
+ Pursue() {
|
|
|
|
+ }
|
|
|
|
+ Run() {
|
|
|
|
+ this.m_npcanimator.play("run");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ class NpcControl {
|
|
|
|
+ constructor() {
|
|
|
|
+ NpcControl.ins = this;
|
|
|
|
+ }
|
|
|
|
+ static get Instance() {
|
|
|
|
+ if (NpcControl.ins) {
|
|
|
|
+ return NpcControl.ins;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return new NpcControl();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Init(_npc) {
|
|
|
|
+ this.m_npcmodel = _npc;
|
|
|
|
+ this.m_npcrunner = this.m_npcmodel.addComponent(NpcRunner);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
class GameManager {
|
|
class GameManager {
|
|
constructor() {
|
|
constructor() {
|
|
- this.EnemyArray = [];
|
|
|
|
|
|
+ this.CharacterArray = [];
|
|
GameManager.ins = this;
|
|
GameManager.ins = this;
|
|
EventManager.EventOn(EventState.SceneInit, this, this.Init);
|
|
EventManager.EventOn(EventState.SceneInit, this, this.Init);
|
|
}
|
|
}
|
|
@@ -912,8 +1037,21 @@
|
|
this.CreatArrow(arrowpos.transform.position.clone(), arrowpos.transform.rotationEuler.clone(), arrowpos);
|
|
this.CreatArrow(arrowpos.transform.position.clone(), arrowpos.transform.rotationEuler.clone(), arrowpos);
|
|
PlayerControl.Instance.Init(playermodel);
|
|
PlayerControl.Instance.Init(playermodel);
|
|
AssetManager.Instance.mainscene.addChild(playermodel);
|
|
AssetManager.Instance.mainscene.addChild(playermodel);
|
|
|
|
+ this.CharacterArray.push(playermodel);
|
|
}
|
|
}
|
|
CreatEnemy() {
|
|
CreatEnemy() {
|
|
|
|
+ for (let i = 0; i < 5; i++) {
|
|
|
|
+ var enemymodel = GamePool.Instance.GetModel(AssetManager.Instance.Enemy.get(1), "");
|
|
|
|
+ let posX = GameTools.RandomANumber(-20, 20);
|
|
|
|
+ let posZ = GameTools.RandomANumber(20, 100);
|
|
|
|
+ enemymodel.transform.position = new Laya.Vector3(posX, 0, posZ);
|
|
|
|
+ enemymodel.transform.localScale = new Laya.Vector3(1.5, 1.5, 1.5);
|
|
|
|
+ enemymodel.transform.rotationEuler = new Laya.Vector3(0, 180, 0);
|
|
|
|
+ NpcControl.Instance.Init(enemymodel);
|
|
|
|
+ AssetManager.Instance.mainscene.addChild(enemymodel);
|
|
|
|
+ GameTools.Instance.EnemySetCollider(enemymodel, 100);
|
|
|
|
+ this.CharacterArray.push(enemymodel);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
CreatRay(pos, euler, raypos) {
|
|
CreatRay(pos, euler, raypos) {
|
|
var ray = this.CreatRayPrefab();
|
|
var ray = this.CreatRayPrefab();
|