|
@@ -13,7 +13,7 @@
|
|
|
GameConfig.screenMode = "none";
|
|
|
GameConfig.alignV = "top";
|
|
|
GameConfig.alignH = "left";
|
|
|
- GameConfig.startScene = "";
|
|
|
+ GameConfig.startScene = "MainGameView.scene";
|
|
|
GameConfig.sceneRoot = "";
|
|
|
GameConfig.debug = false;
|
|
|
GameConfig.stat = false;
|
|
@@ -324,6 +324,9 @@
|
|
|
ResourcesPath.Enemy = [
|
|
|
"Game/res/Role/LayaScene_Role/Conventional/enemy.lh"
|
|
|
];
|
|
|
+ ResourcesPath.Prop = [
|
|
|
+ "Game/res/Prop/LayaScene_Prop/Conventional/Archer"
|
|
|
+ ];
|
|
|
|
|
|
var Sprite3D = Laya.Sprite3D;
|
|
|
var Vector3 = Laya.Vector3;
|
|
@@ -418,13 +421,28 @@
|
|
|
}
|
|
|
|
|
|
var Vector3$1 = Laya.Vector3;
|
|
|
+ var CharacterState;
|
|
|
+ (function (CharacterState) {
|
|
|
+ CharacterState[CharacterState["Run"] = 0] = "Run";
|
|
|
+ CharacterState[CharacterState["Idle"] = 1] = "Idle";
|
|
|
+ CharacterState[CharacterState["Die"] = 2] = "Die";
|
|
|
+ CharacterState[CharacterState["Win"] = 3] = "Win";
|
|
|
+ CharacterState[CharacterState["Shoot"] = 4] = "Shoot";
|
|
|
+ })(CharacterState || (CharacterState = {}));
|
|
|
class Runner extends Laya.Script3D {
|
|
|
constructor() {
|
|
|
super();
|
|
|
+ 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.currot = new Laya.Quaternion;
|
|
|
this.NormalizeSpeed = new Vector3$1();
|
|
|
- this.turndir = new Vector3$1(1, 0, 0);
|
|
|
+ this.curpos = new Vector3$1();
|
|
|
+ this.offest = new Vector3$1();
|
|
|
}
|
|
|
static get Instance() {
|
|
|
if (Runner.ins) {
|
|
@@ -436,14 +454,27 @@
|
|
|
}
|
|
|
onAwake() {
|
|
|
this.m_player = this.owner;
|
|
|
+ this.m_animator = this.owner.getComponent(Laya.Animator);
|
|
|
+ this.m_horseanimator = this.owner.getChildAt(1).getComponent(Laya.Animator);
|
|
|
+ this.ChangeState(CharacterState.Idle);
|
|
|
+ EventManager.StageOn(StageState.Start, this, this.Begin);
|
|
|
+ }
|
|
|
+ Begin() {
|
|
|
+ this.canmove = true;
|
|
|
+ this.ChangeState(CharacterState.Run);
|
|
|
}
|
|
|
onUpdate() {
|
|
|
+ if (this.canmove) {
|
|
|
+ if (this._press) {
|
|
|
+ this._speed = 2;
|
|
|
+ }
|
|
|
+ this.Move(new Vector3$1(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.position = this.m_player.transform.position.x < -4.5 ? new Vector3$1(-4.5, this.m_player.transform.position.y, this.m_player.transform.position.z) : this.m_player.transform.position;
|
|
|
- this.m_player.transform.position = this.m_player.transform.position.x > 4.5 ? new Vector3$1(4.5, this.m_player.transform.position.y, this.m_player.transform.position.z) : this.m_player.transform.position;
|
|
|
}
|
|
|
TurnDir(_dir) {
|
|
|
if (_dir.x != 0) {
|
|
@@ -460,6 +491,90 @@
|
|
|
this.m_player.transform.rotation = this.currot;
|
|
|
}
|
|
|
}
|
|
|
+ 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);
|
|
|
+ this.m_player.transform.position = this.curpos;
|
|
|
+ }
|
|
|
+ ChangeState(_state) {
|
|
|
+ if (this.m_characterstate == _state)
|
|
|
+ return;
|
|
|
+ this.m_characterstate = _state;
|
|
|
+ switch (this.m_characterstate) {
|
|
|
+ case CharacterState.Idle:
|
|
|
+ this.Idle();
|
|
|
+ break;
|
|
|
+ case CharacterState.Run:
|
|
|
+ this.Run();
|
|
|
+ break;
|
|
|
+ case CharacterState.Die:
|
|
|
+ this.Die();
|
|
|
+ break;
|
|
|
+ case CharacterState.Win:
|
|
|
+ this.Win();
|
|
|
+ break;
|
|
|
+ case CharacterState.Shoot:
|
|
|
+ this.Shoot();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Idle() {
|
|
|
+ this.m_animator.play("Idle");
|
|
|
+ this.m_horseanimator.play("Horse_Idle");
|
|
|
+ }
|
|
|
+ Run() {
|
|
|
+ this.m_animator.play("Idle");
|
|
|
+ this.m_horseanimator.play("Horse_Run");
|
|
|
+ }
|
|
|
+ Die() {
|
|
|
+ }
|
|
|
+ Win() {
|
|
|
+ }
|
|
|
+ Shoot() {
|
|
|
+ this.m_animator.play("aimshoot");
|
|
|
+ this.m_animator.play("Horse_Run");
|
|
|
+ }
|
|
|
+ RayCheck() {
|
|
|
+ if (this.DownRayCheck) ;
|
|
|
+ if (this.FowardRayCheck) {
|
|
|
+ this.CrashBarrier();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CrashBarrier() {
|
|
|
+ var target = this.FowardHit.collider.owner;
|
|
|
+ if (target.name == "") ;
|
|
|
+ else if (target.name == "") ;
|
|
|
+ else if (target.name == "") ;
|
|
|
+ else if (target.name == "") ;
|
|
|
+ }
|
|
|
+ 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 DownRay = new Laya.Ray(startPos, direction);
|
|
|
+ if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.DownHit, 100)) {
|
|
|
+ if (this.DownHit.collider.collisionGroup == 100) {
|
|
|
+ isDownHit = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return isDownHit;
|
|
|
+ }
|
|
|
+ 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 DownRay = new Laya.Ray(startPos, direction);
|
|
|
+ if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.FowardHit, 1)) {
|
|
|
+ if (this.FowardHit.collider.collisionGroup == 100) {
|
|
|
+ isFowardHit = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return isFowardHit;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
var Vector2 = Laya.Vector2;
|
|
@@ -477,9 +592,6 @@
|
|
|
this.lllpos = new Vector3$2();
|
|
|
this.hights = 0;
|
|
|
this.wights = 0;
|
|
|
- this.rolepos = new Vector3$2;
|
|
|
- this.rundir = new Vector3$2;
|
|
|
- this.curspeed = 0;
|
|
|
PlayerControl.ins = this;
|
|
|
}
|
|
|
static get Instance() {
|
|
@@ -495,17 +607,19 @@
|
|
|
this._runner = this.Player.addComponent(Runner);
|
|
|
this.Player.transform.position = new Vector3$2();
|
|
|
this.Camera = AssetManager.Instance.maincamera;
|
|
|
- this.Camera.transform.position = new Vector3$2(0, 10, -10);
|
|
|
+ this.Camera.transform.position = new Vector3$2(0, 10, -15);
|
|
|
this.Camera.transform.localRotationEuler = new Vector3$2(-5, 0, 0);
|
|
|
Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.onMouseDown);
|
|
|
- Laya.timer.frameLoop(1, this, this.LateUpdate);
|
|
|
this.CameraFollow();
|
|
|
}
|
|
|
- MouseListen() {
|
|
|
- }
|
|
|
onMouseDown(e) {
|
|
|
+ if (!this._runner.canmove)
|
|
|
+ return;
|
|
|
+ this._runner._press = true;
|
|
|
+ this.mouseDownTime = Laya.Browser.now();
|
|
|
this.startMousePos = new Vector3$2(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();
|
|
|
Laya.timer.frameLoop(1, this, this.onMouseMove);
|
|
|
Laya.stage.on(Laya.Event.MOUSE_UP, this, this.onMouseUp);
|
|
@@ -514,8 +628,6 @@
|
|
|
onMouseMove() {
|
|
|
var MousePos = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
|
|
|
var offestX = MousePos.x - this.curMousePos1.x;
|
|
|
- offestX = offestX > 100 ? 100 : offestX;
|
|
|
- offestX = offestX < -100 ? -100 : offestX;
|
|
|
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);
|
|
@@ -525,6 +637,20 @@
|
|
|
onMouseUp() {
|
|
|
this.offestx = 0;
|
|
|
Laya.timer.clear(this, this.onMouseMove);
|
|
|
+ this._runner._press = false;
|
|
|
+ if (!this.startMousePos)
|
|
|
+ return;
|
|
|
+ Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.onMouseMove);
|
|
|
+ Laya.stage.off(Laya.Event.MOUSE_UP, this, this.onMouseUp);
|
|
|
+ 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);
|
|
|
+ let dist = Laya.Vector3.distance(this.endMousePos, this.startMousePos);
|
|
|
+ if (dist < 50 && interval < 200) {
|
|
|
+ console.log("shoot--");
|
|
|
+ }
|
|
|
+ this.mouseDownTime = now;
|
|
|
}
|
|
|
CameraFollow() {
|
|
|
this.hights = 0;
|
|
@@ -560,22 +686,151 @@
|
|
|
}
|
|
|
return isDownHit;
|
|
|
}
|
|
|
- Move() {
|
|
|
- if (this.canmove) {
|
|
|
- this.speed = this.press ? 1 : 0.5;
|
|
|
- this.curspeed = GameTools.Instance.lerp(this.curspeed, this.speed, 0.04);
|
|
|
- Vector3$2.scale(new Vector3$2(0, 0, 1), this.curspeed, this.rundir);
|
|
|
- Vector3$2.add(this.Player.transform.position, this.rundir, this.rolepos);
|
|
|
- Vector3$2.lerp(this.Player.transform.position, this.rolepos, 0.15, this.rolepos);
|
|
|
- this.Player.transform.position = this.rolepos;
|
|
|
+ }
|
|
|
+
|
|
|
+ var REG = Laya.ClassUtils.regClass;
|
|
|
+ var ui;
|
|
|
+ (function (ui) {
|
|
|
+ class InGameViewUI extends Laya.Scene {
|
|
|
+ constructor() { super(); }
|
|
|
+ createChildren() {
|
|
|
+ super.createChildren();
|
|
|
+ this.createView(InGameViewUI.uiView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ InGameViewUI.uiView = { "type": "Scene", "props": { "width": 720, "height": 1280 }, "compId": 2, "loadList": [], "loadList3D": [] };
|
|
|
+ ui.InGameViewUI = InGameViewUI;
|
|
|
+ REG("ui.InGameViewUI", InGameViewUI);
|
|
|
+ class MainGameViewUI extends Laya.Scene {
|
|
|
+ constructor() { super(); }
|
|
|
+ createChildren() {
|
|
|
+ super.createChildren();
|
|
|
+ this.createView(MainGameViewUI.uiView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MainGameViewUI.uiView = { "type": "Scene", "props": { "width": 720, "height": 1280 }, "compId": 2, "child": [{ "type": "Button", "props": { "y": 897, "x": 360, "width": 100, "var": "StartBtn", "stateNum": 1, "skin": "comp/button.png", "pivotY": 50, "pivotX": 50, "label": "label", "height": 100 }, "compId": 4 }], "loadList": ["comp/button.png"], "loadList3D": [] };
|
|
|
+ ui.MainGameViewUI = MainGameViewUI;
|
|
|
+ REG("ui.MainGameViewUI", MainGameViewUI);
|
|
|
+ })(ui || (ui = {}));
|
|
|
+
|
|
|
+ class MainGameView extends ui.MainGameViewUI {
|
|
|
+ constructor() {
|
|
|
+ super();
|
|
|
+ MainGameView.ins = this;
|
|
|
+ }
|
|
|
+ static get Instance() {
|
|
|
+ if (MainGameView.ins) {
|
|
|
+ return MainGameView.ins;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return new MainGameView();
|
|
|
}
|
|
|
}
|
|
|
- RayCheck() {
|
|
|
- if (this.DownRayCheck) {
|
|
|
- this.Player.transform.position = new Laya.Vector3(this.Player.transform.position.x, this.DownHit.point.y, this.Player.transform.position.z);
|
|
|
+ Show() {
|
|
|
+ this.StartBtn.clickHandler = Laya.Handler.create(this, this.ClickStart);
|
|
|
+ }
|
|
|
+ Close() {
|
|
|
+ }
|
|
|
+ ClickStart() {
|
|
|
+ EventManager.StageTrigger(StageState.Start);
|
|
|
+ ViewManager.Instance.ShowView(ViewType.IngameView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ class InGameView extends ui.InGameViewUI {
|
|
|
+ constructor() {
|
|
|
+ super();
|
|
|
+ InGameView.ins = this;
|
|
|
+ }
|
|
|
+ static get Instance() {
|
|
|
+ if (InGameView.ins) {
|
|
|
+ return InGameView.ins;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return new InGameView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Show() {
|
|
|
+ }
|
|
|
+ Close() {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var ViewType;
|
|
|
+ (function (ViewType) {
|
|
|
+ ViewType[ViewType["MainView"] = 0] = "MainView";
|
|
|
+ ViewType[ViewType["IngameView"] = 1] = "IngameView";
|
|
|
+ })(ViewType || (ViewType = {}));
|
|
|
+ class ViewManager {
|
|
|
+ constructor() {
|
|
|
+ this.showexportview = 0;
|
|
|
+ this.popViewDic = [];
|
|
|
+ this.ViewSprite = new Laya.Sprite();
|
|
|
+ this.OtherViewSprite = new Laya.Sprite();
|
|
|
+ ViewManager.ins = this;
|
|
|
+ Laya.stage.addChild(this.ViewSprite);
|
|
|
+ Laya.stage.addChild(this.OtherViewSprite);
|
|
|
+ }
|
|
|
+ static get Instance() {
|
|
|
+ if (ViewManager.ins) {
|
|
|
+ return ViewManager.ins;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return new ViewManager();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ShowView(_viewtype, data = null) {
|
|
|
+ if (this.curView != null) {
|
|
|
+ this.curView.Close();
|
|
|
+ this.curView.destroy();
|
|
|
+ this.curView.removeSelf();
|
|
|
+ }
|
|
|
+ this.curView = this.CreateView(_viewtype);
|
|
|
+ this.curView.name = ViewType[_viewtype];
|
|
|
+ this.ViewSprite.addChild(this.curView);
|
|
|
+ this.curView.Show(data);
|
|
|
+ }
|
|
|
+ CloseView() {
|
|
|
+ if (this.curView != null) {
|
|
|
+ this.curView.Close();
|
|
|
+ this.curView.destroy();
|
|
|
+ this.curView.removeSelf();
|
|
|
}
|
|
|
}
|
|
|
- LateUpdate() {
|
|
|
+ OpenPopView(viewType, data = null) {
|
|
|
+ var popView;
|
|
|
+ if (this.popViewDic[viewType]) {
|
|
|
+ popView = this.popViewDic[viewType];
|
|
|
+ this.OtherViewSprite.setChildIndex(popView, this.OtherViewSprite.numChildren - 1);
|
|
|
+ popView.visible = true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ popView = this.CreateView(viewType);
|
|
|
+ this.OtherViewSprite.addChild(popView);
|
|
|
+ this.popViewDic[viewType] = popView;
|
|
|
+ }
|
|
|
+ this.showexportview = 1;
|
|
|
+ popView.OnOpen(data);
|
|
|
+ }
|
|
|
+ ClosePopView(viewType) {
|
|
|
+ var popView = this.popViewDic[viewType];
|
|
|
+ if (popView == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ popView.OnHide();
|
|
|
+ popView.visible = false;
|
|
|
+ this.showexportview = 0;
|
|
|
+ }
|
|
|
+ ClearPopViews() {
|
|
|
+ }
|
|
|
+ CreateView(_viewtype) {
|
|
|
+ switch (_viewtype) {
|
|
|
+ case ViewType.MainView:
|
|
|
+ return new MainGameView();
|
|
|
+ case ViewType.IngameView:
|
|
|
+ return new InGameView();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -597,6 +852,7 @@
|
|
|
this.CreatCharacter();
|
|
|
this.mainscene = AssetManager.Instance.mainscene;
|
|
|
Laya.stage.addChildAt(this.mainscene, 0);
|
|
|
+ ViewManager.Instance.ShowView(ViewType.MainView);
|
|
|
}
|
|
|
CreatCharacter() {
|
|
|
this.CreatPlayer();
|
|
@@ -614,6 +870,8 @@
|
|
|
}
|
|
|
CreatEnemy() {
|
|
|
}
|
|
|
+ EventListen() {
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class LoadView {
|
|
@@ -638,8 +896,6 @@
|
|
|
EventManager.EventTrigger(EventState.LoadComplete);
|
|
|
}
|
|
|
LoadScene() {
|
|
|
- let abc = 0.15 * 18;
|
|
|
- console.log("abc---", abc);
|
|
|
Laya.Scene3D.load(ResourcesPath.MainScene, Laya.Handler.create(this, (scene) => {
|
|
|
this.scene = scene;
|
|
|
AssetManager.Instance.mainscene = this.scene;
|