Ejemplo n.º 1
0
        public override void Update(GameManager game, float delta)
        {
            if (Input.GetKey(KeyCode.A))
            {
                MoveAction a = MoveAction.Make(-1);
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }


            if (Input.GetKey(KeyCode.D))
            {
                MoveAction a = MoveAction.Make(1);
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }


            if (Input.GetKey(KeyCode.W))
            {
                MoveZAction a = MoveZAction.Make(1);
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }

            if (Input.GetKey(KeyCode.S))
            {
                MoveZAction a = MoveZAction.Make(-1);
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }


            if (Input.GetKeyDown(KeyCode.Space))
            {
                JumpAction a = JumpAction.Make();
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }


            if (Input.GetMouseButton(0))
            {
            }
        }
Ejemplo n.º 2
0
        public override void Update(GameManager game, float delta)
        {
            foreach (int entity in _entityList)
            {
                GAstarComponent astarComponent = game.Entities.GetComponentOf <GAstarComponent>(entity);
                GTransform      transform      = game.Entities.GetComponentOf <GTransform>(entity);
                ActionQueue     _actionQueue   = game.Entities.GetComponentOf <ActionQueue>(entity);
                Vector3         current        = astarComponent._current;
                bool            wait           = false;
                //Debug.Log("Astar value "  + astarComponent._path.ElementAt(astarComponent._index).Value);
                if (checkCollision(transform, current))
                {
                    if (!astarComponent._path.ElementAt(astarComponent._index).Value)
                    {
                        astarComponent._index++;
                        astarComponent._current = astarComponent._path.ElementAt(astarComponent._index).Key;
                    }
                }
                if (checkFullCollision(transform, current) && astarComponent._path.ElementAt(astarComponent._index).Value&& game.Entities.GetComponentOf <GMovement>(entity)._grounded)
                {
                    JumpAction a = JumpAction.Make();
                    a.Apply(game, transform.EntityID);
                    a.Recycle();
                    astarComponent._index++;
                    astarComponent._current = astarComponent._path.ElementAt(astarComponent._index).Key;
                }

                if (Mathf.Abs(transform._position.x - current.x) > 0.1f)
                {
                    MoveAction a = MoveAction.Make(current.x - transform._position.x);
                    a.Apply(game, transform.EntityID);
                    a.Recycle();
                }
                if (Mathf.Abs(transform._position.z - current.z) > 0.1f)
                {
                    //Debug.Log("Move Z " + Mathf.Sign(current.x - transform._position.x));
                    MoveZAction a = MoveZAction.Make(current.z - transform._position.z);
                    a.Apply(game, transform.EntityID);
                    a.Recycle();
                }
            }
        }