|
@@ -13,7 +13,7 @@
|
|
|
GameConfig.screenMode = "none";
|
|
|
GameConfig.alignV = "top";
|
|
|
GameConfig.alignH = "left";
|
|
|
- GameConfig.startScene = "MainGameView.scene";
|
|
|
+ GameConfig.startScene = "InGameView.scene";
|
|
|
GameConfig.sceneRoot = "";
|
|
|
GameConfig.debug = false;
|
|
|
GameConfig.stat = false;
|
|
@@ -99,6 +99,16 @@
|
|
|
}
|
|
|
EventManager.instance = new Laya.EventDispatcher();
|
|
|
|
|
|
+ var Vector3 = Laya.Vector3;
|
|
|
+ class Transform3DHelper {
|
|
|
+ static getForward(transform) {
|
|
|
+ let forward = new Vector3(0, 0, 0);
|
|
|
+ transform.getForward(forward);
|
|
|
+ Laya.Vector3.scale(forward, -1, forward);
|
|
|
+ Laya.Vector3.normalize(forward, forward);
|
|
|
+ return forward;
|
|
|
+ }
|
|
|
+ }
|
|
|
class GameTools {
|
|
|
constructor() {
|
|
|
GameTools.ins = this;
|
|
@@ -296,9 +306,6 @@
|
|
|
this.Prop = new ResDic();
|
|
|
this.Stone = new ResDic();
|
|
|
this.Tree = new ResDic();
|
|
|
- this.RedRay = new ResDic();
|
|
|
- this.BlueRay = new ResDic();
|
|
|
- this.GreenRay = new ResDic();
|
|
|
AssetManager.ins = this;
|
|
|
EventManager.EventOn(EventState.LoadComplete, this, this.Init);
|
|
|
}
|
|
@@ -332,7 +339,7 @@
|
|
|
ResourcesPath.Prop = "Game/res/Prop/LayaScene_Prop/Conventional/Prop.lh";
|
|
|
|
|
|
var Sprite3D = Laya.Sprite3D;
|
|
|
- var Vector3 = Laya.Vector3;
|
|
|
+ var Vector3$1 = Laya.Vector3;
|
|
|
class modelConfig {
|
|
|
constructor(model) {
|
|
|
this.modelcur = model;
|
|
@@ -408,7 +415,7 @@
|
|
|
modelnum.push(new modelConfig(model));
|
|
|
this.modelpool[poolname] = modelnum;
|
|
|
}
|
|
|
- model.transform.position = new Vector3(0, 0, -10000);
|
|
|
+ model.transform.position = new Vector3$1(0, 0, -10000);
|
|
|
model.removeSelf();
|
|
|
model.active = false;
|
|
|
}
|
|
@@ -423,7 +430,7 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- var Vector3$1 = Laya.Vector3;
|
|
|
+ var Vector3$2 = Laya.Vector3;
|
|
|
var CharacterState;
|
|
|
(function (CharacterState) {
|
|
|
CharacterState[CharacterState["Run"] = 0] = "Run";
|
|
@@ -435,17 +442,22 @@
|
|
|
class Runner extends Laya.Script3D {
|
|
|
constructor() {
|
|
|
super();
|
|
|
+ this.m_raydistance = 20;
|
|
|
this.canmove = false;
|
|
|
this._speed = 1;
|
|
|
this._press = false;
|
|
|
this.DownHit = new Laya.HitResult();
|
|
|
this.FowardHit = new Laya.HitResult();
|
|
|
this.curspeed = 0;
|
|
|
- this.currotV = new Vector3$1();
|
|
|
+ this.currotV = new Vector3$2();
|
|
|
this.currot = new Laya.Quaternion;
|
|
|
- this.NormalizeSpeed = new Vector3$1();
|
|
|
- this.curpos = new Vector3$1();
|
|
|
- this.offest = new Vector3$1();
|
|
|
+ this.NormalizeSpeed = new Vector3$2();
|
|
|
+ this.curpos = 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() {
|
|
|
if (Runner.ins) {
|
|
@@ -458,7 +470,10 @@
|
|
|
onAwake() {
|
|
|
this.m_player = this.owner;
|
|
|
this.m_animator = this.owner.getComponent(Laya.Animator);
|
|
|
- this.m_horseanimator = this.owner.getChildAt(2).getComponent(Laya.Animator);
|
|
|
+ this.m_arrowpos = this.owner.getChildByName("arrowpos");
|
|
|
+ this.m_raypos = this.owner.getChildByName("raypos");
|
|
|
+ this.m_archerpos = this.owner.getChildByName("archerpos");
|
|
|
+ this.m_horseanimator = this.owner.getChildByName("Horse").getComponent(Laya.Animator);
|
|
|
this.ChangeState(CharacterState.Idle);
|
|
|
EventManager.StageOn(StageState.Start, this, this.Begin);
|
|
|
}
|
|
@@ -467,26 +482,27 @@
|
|
|
this.ChangeState(CharacterState.Run);
|
|
|
}
|
|
|
onUpdate() {
|
|
|
- let ray = this.m_player.getChildByName("raypos");
|
|
|
- console.log("玩家的位置---", this.m_player.transform.position);
|
|
|
- console.log("ray的位置---", ray.transform.position);
|
|
|
+ if (this.m_animator.getCurrentAnimatorPlayState(0).normalizedTime >= 1) {
|
|
|
+ this.m_animator.play("Idle");
|
|
|
+ GameManager.Instance.CreatArrow(this.m_arrowpos.transform.position.clone(), this.m_arrowpos.transform.rotationEuler.clone(), this.m_arrowpos);
|
|
|
+ }
|
|
|
if (this.canmove) {
|
|
|
if (this._press) {
|
|
|
this._speed = 2;
|
|
|
}
|
|
|
- this.Move(new Vector3$1(0, 0, 1), this._speed);
|
|
|
+ this.Move(new Vector3$2(0, 0, 1), this._speed);
|
|
|
}
|
|
|
this.RayCheck();
|
|
|
}
|
|
|
MoveX(_speed) {
|
|
|
_speed *= 0.07;
|
|
|
- this.m_player.transform.translate(new Vector3$1(_speed, 0, 0));
|
|
|
+ this.m_player.transform.translate(new Vector3$2(_speed, 0, 0));
|
|
|
}
|
|
|
TurnDir(_dir) {
|
|
|
if (_dir.x != 0) {
|
|
|
- Vector3$1.lerp(this.currotV, _dir, 0.35, _dir);
|
|
|
+ Vector3$2.lerp(this.currotV, _dir, 0.35, _dir);
|
|
|
this.currotV = _dir;
|
|
|
- Laya.Quaternion.rotationLookAt(_dir, new Vector3$1(0, 1, 0), this.currot);
|
|
|
+ Laya.Quaternion.rotationLookAt(_dir, new Vector3$2(0, 1, 0), this.currot);
|
|
|
Laya.Quaternion.slerp(this.m_player.transform.rotation, this.currot, 0.025, this.currot);
|
|
|
this.currot = new Laya.Quaternion(0, this.currot.y, 0);
|
|
|
this.m_player.transform.rotation = this.currot;
|
|
@@ -500,10 +516,10 @@
|
|
|
Move(_dir, _speed) {
|
|
|
var sp = GameTools.Instance.lerp(this.curspeed, _speed, 0.1);
|
|
|
this.curspeed = sp;
|
|
|
- Vector3$1.scale(_dir, this.curspeed, this.offest);
|
|
|
- Vector3$1.add(this.m_player.transform.position, this.offest, this.curpos);
|
|
|
- Vector3$1.lerp(this.m_player.transform.position, this.curpos, 0.15, this.curpos);
|
|
|
- this.curpos = new Vector3$1(this.curpos.x, this.curpos.y, this.curpos.z);
|
|
|
+ Vector3$2.scale(_dir, this.curspeed, this.offest);
|
|
|
+ Vector3$2.add(this.m_player.transform.position, this.offest, this.curpos);
|
|
|
+ Vector3$2.lerp(this.m_player.transform.position, this.curpos, 0.15, this.curpos);
|
|
|
+ this.curpos = new Vector3$2(this.curpos.x, this.curpos.y, this.curpos.z);
|
|
|
this.m_player.transform.position = this.curpos;
|
|
|
}
|
|
|
ChangeState(_state) {
|
|
@@ -559,8 +575,8 @@
|
|
|
}
|
|
|
get DownRayCheck() {
|
|
|
var isDownHit = false;
|
|
|
- var startPos = new Vector3$1(this.m_player.transform.position.x, this.m_player.transform.position.y + 1.5, this.m_player.transform.position.z + 0.5);
|
|
|
- var direction = new Vector3$1(0, -1, 0);
|
|
|
+ var startPos = new Vector3$2(this.m_player.transform.position.x, this.m_player.transform.position.y + 1.5, this.m_player.transform.position.z + 0.5);
|
|
|
+ var direction = new Vector3$2(0, -1, 0);
|
|
|
var DownRay = new Laya.Ray(startPos, direction);
|
|
|
if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.DownHit, 100)) {
|
|
|
if (this.DownHit.collider.collisionGroup == 100) {
|
|
@@ -571,8 +587,8 @@
|
|
|
}
|
|
|
get FowardRayCheck() {
|
|
|
var isFowardHit = false;
|
|
|
- var startPos = new Vector3$1(this.m_player.transform.position.x, this.m_player.transform.position.y + 1.5, this.m_player.transform.position.z + 0.5);
|
|
|
- var direction = new Vector3$1(0, 0, 1);
|
|
|
+ var startPos = new Vector3$2(this.m_player.transform.position.x, this.m_player.transform.position.y + 1.5, this.m_player.transform.position.z + 0.5);
|
|
|
+ var direction = new Vector3$2(0, 0, 1);
|
|
|
var DownRay = new Laya.Ray(startPos, direction);
|
|
|
if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.FowardHit, 1)) {
|
|
|
if (this.FowardHit.collider.collisionGroup == 100) {
|
|
@@ -581,21 +597,37 @@
|
|
|
}
|
|
|
return isFowardHit;
|
|
|
}
|
|
|
+ Archery() {
|
|
|
+ this.m_animator.play("aimshoot");
|
|
|
+ let arrow = this.m_arrowpos.getChildAt(this.m_arrowpos.numChildren - 1);
|
|
|
+ let ray = this.owner.getChildByName("raypos").getChildAt(0);
|
|
|
+ let forw = Transform3DHelper.getForward(ray.transform);
|
|
|
+ let testRay = new Laya.Ray(this.m_raypos.transform.position, forw);
|
|
|
+ let hitRes = new Laya.HitResult();
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ ArrowMove(_arrow, _dir) {
|
|
|
+ Laya.timer.frameLoop(1, this, () => {
|
|
|
+ _arrow.transform.translate(_dir);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
var Vector2 = Laya.Vector2;
|
|
|
- var Vector3$2 = Laya.Vector3;
|
|
|
+ var Vector3$3 = Laya.Vector3;
|
|
|
class PlayerControl {
|
|
|
constructor() {
|
|
|
this.DownHit = new Laya.HitResult();
|
|
|
this.canmove = true;
|
|
|
this.speed = 1;
|
|
|
this.press = false;
|
|
|
- this.offset = new Vector3$2(0, 0, 0);
|
|
|
+ this.offset = new Vector3$3(0, 0, 0);
|
|
|
this.offestx = 0;
|
|
|
- this.poschazhi = new Vector3$2();
|
|
|
- this.gengsuipos = new Vector3$2();
|
|
|
- this.lllpos = new Vector3$2();
|
|
|
+ this.poschazhi = new Vector3$3();
|
|
|
+ this.gengsuipos = new Vector3$3();
|
|
|
+ this.lllpos = new Vector3$3();
|
|
|
this.hights = 0;
|
|
|
this.wights = 0;
|
|
|
PlayerControl.ins = this;
|
|
@@ -611,10 +643,10 @@
|
|
|
Init(_player) {
|
|
|
this.Player = _player;
|
|
|
this._runner = this.Player.addComponent(Runner);
|
|
|
- this.Player.transform.position = new Vector3$2();
|
|
|
+ this.Player.transform.position = new Vector3$3();
|
|
|
this.Camera = AssetManager.Instance.maincamera;
|
|
|
- this.Camera.transform.position = new Vector3$2(0, 10, -15);
|
|
|
- this.Camera.transform.localRotationEuler = new Vector3$2(-5, 0, 0);
|
|
|
+ this.Camera.transform.position = new Vector3$3(0, 10, -15);
|
|
|
+ this.Camera.transform.localRotationEuler = new Vector3$3(-5, 0, 0);
|
|
|
Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.onMouseDown);
|
|
|
this.CameraFollow();
|
|
|
}
|
|
@@ -623,7 +655,7 @@
|
|
|
return;
|
|
|
this._runner._press = true;
|
|
|
this.mouseDownTime = Laya.Browser.now();
|
|
|
- this.startMousePos = new Vector3$2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
|
|
|
+ this.startMousePos = new Vector3$3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
|
|
|
var startpoint = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
|
|
|
this.curMousePos = this.startMousePos.clone();
|
|
|
this.curMousePos1 = startpoint.clone();
|
|
@@ -636,7 +668,7 @@
|
|
|
var offestX = MousePos.x - this.curMousePos1.x;
|
|
|
this.offestx = GameTools.Instance.lerp(this.offestx, offestX, 0.015);
|
|
|
this._runner.MoveX(-this.offestx);
|
|
|
- var dir = new Vector3$2(-offestX * 0.005, 0, 0);
|
|
|
+ var dir = new Vector3$3(-offestX * 0.005, 0, 0);
|
|
|
this._runner.TurnDir(dir);
|
|
|
this.curMousePos1 = new Vector2(MousePos.x, MousePos.y);
|
|
|
}
|
|
@@ -651,9 +683,10 @@
|
|
|
Laya.stage.off(Laya.Event.MOUSE_OUT, this, this.onMouseUp);
|
|
|
let now = Laya.Browser.now();
|
|
|
let interval = now - this.mouseDownTime;
|
|
|
- this.endMousePos = new Vector3$2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
|
|
|
+ this.endMousePos = new Vector3$3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
|
|
|
let dist = Laya.Vector3.distance(this.endMousePos, this.startMousePos);
|
|
|
if (dist < 50 && interval < 200) {
|
|
|
+ this._runner.Archery();
|
|
|
console.log("shoot--");
|
|
|
}
|
|
|
this.mouseDownTime = now;
|
|
@@ -661,29 +694,29 @@
|
|
|
CameraFollow() {
|
|
|
this.hights = 0;
|
|
|
this.wights = 0;
|
|
|
- Vector3$2.subtract(this.Player.transform.position, this.Camera.transform.position, this.poschazhi);
|
|
|
+ Vector3$3.subtract(this.Player.transform.position, this.Camera.transform.position, this.poschazhi);
|
|
|
Laya.timer.frameLoop(1, this, this.GenSui);
|
|
|
}
|
|
|
GenSui() {
|
|
|
- Vector3$2.subtract(this.Player.transform.position, this.poschazhi, this.gengsuipos);
|
|
|
+ Vector3$3.subtract(this.Player.transform.position, this.poschazhi, this.gengsuipos);
|
|
|
this.hights = GameTools.Instance.lerp(this.hights, 1.0, 0.03);
|
|
|
this.wights = GameTools.Instance.lerp(this.wights, 0.8, 0.02);
|
|
|
- this.gengsuipos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y, this.gengsuipos.z - this.wights);
|
|
|
- Vector3$2.lerp(this.Camera.transform.position, this.gengsuipos, 0.25, this.lllpos);
|
|
|
- this.lllpos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y, this.lllpos.z);
|
|
|
- this.lllpos = new Vector3$2(this.gengsuipos.x, this.lllpos.y, this.lllpos.z);
|
|
|
+ this.gengsuipos = new Vector3$3(this.gengsuipos.x, this.gengsuipos.y, this.gengsuipos.z - this.wights);
|
|
|
+ Vector3$3.lerp(this.Camera.transform.position, this.gengsuipos, 0.25, this.lllpos);
|
|
|
+ this.lllpos = new Vector3$3(this.gengsuipos.x, this.gengsuipos.y, this.lllpos.z);
|
|
|
+ this.lllpos = new Vector3$3(this.gengsuipos.x, this.lllpos.y, this.lllpos.z);
|
|
|
this.Camera.transform.position = this.lllpos;
|
|
|
var qqqwe = new Laya.Quaternion();
|
|
|
- var eyePos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y - 0.8, this.gengsuipos.z);
|
|
|
- Laya.Quaternion.lookAt(eyePos, this.Player.transform.position, new Vector3$2(0, 1, 0), qqqwe);
|
|
|
+ var eyePos = new Vector3$3(this.gengsuipos.x, this.gengsuipos.y - 0.8, this.gengsuipos.z);
|
|
|
+ Laya.Quaternion.lookAt(eyePos, this.Player.transform.position, new Vector3$3(0, 1, 0), qqqwe);
|
|
|
qqqwe.invert(qqqwe);
|
|
|
Laya.Quaternion.slerp(this.Camera.transform.rotation, qqqwe, 0.1, qqqwe);
|
|
|
this.Camera.transform.rotation = qqqwe;
|
|
|
}
|
|
|
get DownRayCheck() {
|
|
|
var isDownHit = false;
|
|
|
- var startPos = new Vector3$2(this.Player.transform.position.x, this.Player.transform.position.y + 1.5, this.Player.transform.position.z + 0.5);
|
|
|
- var direction = new Vector3$2(0, -1, 0);
|
|
|
+ var startPos = new Vector3$3(this.Player.transform.position.x, this.Player.transform.position.y + 1.5, this.Player.transform.position.z + 0.5);
|
|
|
+ var direction = new Vector3$3(0, -1, 0);
|
|
|
var DownRay = new Laya.Ray(startPos, direction);
|
|
|
if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.DownHit, 100)) {
|
|
|
if (this.DownHit.collider.collisionGroup == 100) {
|
|
@@ -868,11 +901,15 @@
|
|
|
var playermodel = GamePool.Instance.GetModel(AssetManager.Instance.Player.get(1), "");
|
|
|
var horsemodel = GamePool.Instance.GetModel(AssetManager.Instance.Horse.get(1), "");
|
|
|
playermodel.addChild(horsemodel);
|
|
|
- var raypos = playermodel.getChildByName("raypos");
|
|
|
- this.CreatRay(raypos.transform.position.clone(), raypos.transform.rotationEuler.clone(), raypos);
|
|
|
playermodel.transform.position = new Laya.Vector3(0, 0, 0);
|
|
|
horsemodel.transform.localScale = new Laya.Vector3(1, 1, 1);
|
|
|
horsemodel.transform.localPosition = new Laya.Vector3(0, 0, 0);
|
|
|
+ var raypos = playermodel.getChildByName("raypos");
|
|
|
+ var archerpos = playermodel.getChildByName("archerpos");
|
|
|
+ var arrowpos = playermodel.getChildByName("arrowpos");
|
|
|
+ this.CreatRay(raypos.transform.position.clone(), raypos.transform.rotationEuler.clone(), raypos);
|
|
|
+ this.CreatArcher(archerpos.transform.position.clone(), archerpos.transform.rotationEuler.clone(), archerpos);
|
|
|
+ this.CreatArrow(arrowpos.transform.position.clone(), arrowpos.transform.rotationEuler.clone(), arrowpos);
|
|
|
PlayerControl.Instance.Init(playermodel);
|
|
|
AssetManager.Instance.mainscene.addChild(playermodel);
|
|
|
}
|
|
@@ -881,17 +918,34 @@
|
|
|
CreatRay(pos, euler, raypos) {
|
|
|
var ray = this.CreatRayPrefab();
|
|
|
raypos.addChild(ray);
|
|
|
- ray.transform.position = pos;
|
|
|
- ray.transform.rotationEuler = euler;
|
|
|
+ ray.transform.position = new Laya.Vector3(pos.x - 0.3, pos.y, pos.z + 0.5);
|
|
|
+ ray.transform.rotationEuler = new Laya.Vector3(-90, euler.y, euler.z);
|
|
|
let scale = ray.transform.scale.clone();
|
|
|
- scale.z = 5;
|
|
|
- scale.x = 1;
|
|
|
+ scale.z = 0.1;
|
|
|
+ scale.y = 3;
|
|
|
+ scale.x = 2;
|
|
|
ray.transform.scale = scale;
|
|
|
}
|
|
|
CreatRayPrefab() {
|
|
|
- var ray = GamePool.Instance.GetModel(AssetManager.Instance.GreenRay.get(1), "");
|
|
|
+ var ray = GamePool.Instance.GetModel(AssetManager.Instance.Prop.get(8), "");
|
|
|
return ray;
|
|
|
}
|
|
|
+ CreatArcher(_pos, _euler, archerpos) {
|
|
|
+ var archer = GamePool.Instance.GetModel(AssetManager.Instance.Prop.get(6), "");
|
|
|
+ archerpos.addChild(archer);
|
|
|
+ archer.transform.position = _pos;
|
|
|
+ archer.transform.rotationEuler = new Laya.Vector3(-90, 0, 0);
|
|
|
+ var scale = archer.transform.scale.clone();
|
|
|
+ scale.z = 0.8;
|
|
|
+ archer.transform.scale = scale;
|
|
|
+ }
|
|
|
+ CreatArrow(_pos, _euler, arrowpos) {
|
|
|
+ var arrow = GamePool.Instance.GetModel(AssetManager.Instance.Prop.get(5), "");
|
|
|
+ arrowpos.addChild(arrow);
|
|
|
+ arrow.transform.position = _pos;
|
|
|
+ var euler = _euler;
|
|
|
+ arrow.transform.rotationEuler = new Laya.Vector3(-90, euler.y, euler.z);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class LoadView {
|
|
@@ -990,12 +1044,6 @@
|
|
|
tree.active = false;
|
|
|
AssetManager.Instance.Tree.set(i + 1, tree);
|
|
|
}
|
|
|
- var Blue = _prop.getChildByName("bulletB");
|
|
|
- AssetManager.Instance.BlueRay.set(1, Blue);
|
|
|
- var Red = _prop.getChildByName("bulletR");
|
|
|
- AssetManager.Instance.RedRay.set(1, Red);
|
|
|
- var Green = _prop.getChildByName("bulletG");
|
|
|
- AssetManager.Instance.GreenRay.set(1, Green);
|
|
|
Laya.loader.clearRes(ResourcesPath.Prop);
|
|
|
console.log("道具资源加载完毕---");
|
|
|
this.LoadComplete();
|