Beispiel #1
0
        public void Update()
        {
            LogicFrameBehaviour logic = Sim.GetBehaviour <LogicFrameBehaviour>();

            Entitas.Entity entity = Sim.GetEntityWorld().GetEntity(GameClientData.SelfControlEntityId);
            if (entity != null)
            {
                MoveComponent comp = entity.GetComponent <MoveComponent>();
                if (comp != null)
                {
                    Vector2 dir = comp.GetDirVector2();
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.A))
                    {
                        dir.x = -1;
                    }
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.S))
                    {
                        dir.y = -1;
                    }
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.W))
                    {
                        dir.y = 1;
                    }
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.D))
                    {
                        dir.x = 1;
                    }
                    if (!InputManager.Instance.IsAnyKeyCodeActive())
                    {
                        dir.x = 0;
                        dir.y = 0;
                    }
                    if (dir != comp.GetDirVector2())
                    {
                        Debug.Log(string.Format("keyframeIdx:{0} roleid:{1}", logic.CurrentFrameIdx, comp.EntityId));

                        //KeyFrameSender.AddFrameCommand(new FrameIdxInfo(logic.CurrentFrameIdx,FrameCommand.SYNC_MOVE,comp.EntityId,new string[] { dir.x + "", dir.y + "", "0" }));

                        KeyFrameSender.AddCurrentFrameCommand(FrameCommand.SYNC_MOVE, comp.EntityId, new string[] { dir.x + "", dir.y + "", "0" });
                    }

                    //bullet
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.Space))
                    {
                        KeyFrameSender.AddCurrentFrameCommand(FrameCommand.SYNC_CREATE_ENTITY, Common.Utils.GuidToString(), new string[] { ((int)EntityWorld.EntityOperationEvent.CreateBullet) + "", comp.EntityId });
                    }
                }
            }
        }
        public void Update()
        {
            LogicFrameBehaviour logic = Sim.GetBehaviour <LogicFrameBehaviour>();

            if (logic.CurrentFrameIdx % randomStepFrame == 0)
            {
                //randomStepFrame = new System.Random().Next(10, 30);
                Entitas.Entity entity = Sim.GetEntityWorld().GetEntity(GameClientData.SelfControlEntityId);
                if (entity != null)
                {
                    MoveComponent comp = entity.GetComponent <MoveComponent>();
                    if (comp != null)
                    {
                        Vector2 dir   = comp.GetDirVector2();
                        int     value = new System.Random().Next(0, 5);
                        if (value == 0)
                        {
                            dir.x = -1;
                        }
                        else if (value == 1)
                        {
                            dir.y = -1;
                        }
                        else if (value == 2)
                        {
                            dir.y = 1;
                        }
                        else if (value == 3)
                        {
                            dir.x = 1;
                        }
                        else if (value == 4)
                        {
                            dir.x = 0;
                            dir.y = 0;
                        }
                        if (dir != comp.GetDirVector2())
                        {
                            //Debug.Log(string.Format("keyframeIdx:{0} roleid:{1}", logic.CurrentFrameIdx, comp.EntityId));

                            KeyFrameSender.AddFrameCommand(new FrameIdxInfo(logic.CurrentFrameIdx, FrameCommand.SYNC_MOVE, comp.EntityId.ToString(), new string[] { dir.x + "", dir.y + "", "0" }));
                        }
                    }
                }
            }
        }
Beispiel #3
0
        //Tweener tweener;
        protected override void OnRender(Entitas.Entity entity)
        {
            base.OnRender(entity);

            TransformComponent com_Pos  = entity.GetComponent <TransformComponent>();
            MoveComponent      com_Move = entity.GetComponent <MoveComponent>();

            if (com_Pos != null)
            {
                double lerp    = SimulationManager.Instance.GetFrameLerp() * SimulationManager.Instance.GetFrameMsLength() / 1000;/// Time.deltaTime;
                var    pos1    = com_Pos.GetPositionVector2();
                var    nextPos = pos1 + com_Move.GetDirVector2() * (com_Move.GetSpeed() * (float)(Time.deltaTime / SimulationManager.Instance.GetFrameMsLength() / 1000));

                //if (tweener != null)
                //    tweener.Kill();
                //tweener = null;

                transform.DOLocalMove(Vector2.Lerp(pos1, nextPos, (float)lerp), .5f, false);

                //transform.localPosition = Vector2.Lerp(transform.position, nextPos, (float)lerp);
            }
        }