Пример #1
0
    //###############
    //##  METHODS  ##
    //###############



    private void checkPlayerDistance()
    {
        float distance = Vector2.Distance(PlayerPosition.position, transform.position);

        if (distance < AggressionRange && distance > StoppingDistance)
        {
            moveTowardsPlayer();
        }
        else
        {
            mMoveHandler.Move(new Vector2(0, 0));
        }
    }
Пример #2
0
    private void FixedUpdate()
    {
        if (path != null)
        {
            // Check if we've reached the end of the path and stop execution if we have
            if (currentWaypoint >= path.vectorPath.Count)
            {
                reachedEndOfPath = true;
                return;
            }
            else
            {
                reachedEndOfPath = false;
            }

            if (path.GetTotalLength() < aggroRange)
            {
                // Calculate the direction to the current waypoint and move in it
                Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] - rb.position).normalized;
                controller.Move(direction);

                // Check if we're close enough to the waypoint to move onto the next one
                float distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]);

                if (distance < nextWaypointDistance)
                {
                    currentWaypoint++;
                }
            }
        }
    }
Пример #3
0
 public ActionResult Move(string playerId, T move)
 {
     lock (_game)
     {
         return(_game.Move(playerId, move));
     }
 }
Пример #4
0
 public static void MoveAtRandom(IMoveable moveable)
 {
     if (moveable.Position != null)
     {
         Point pos = moveable.Position;
         moveable.Move(new Point(Utilities.RandomNumber(pos.X - 1, pos.X + 1), Utilities.RandomNumber(pos.Y - 1, pos.Y + 1)));
     }
 }
Пример #5
0
 public static void MoveAwayFrom(IMoveable moveable, IMappable mapObject)
 {
     if (moveable.Position != null && mapObject.Position != null && OpenNeighbors(moveable).Any())
     {
         moveable.Move(OpenNeighbors(moveable).FirstOrDefault(p => MovementCost(moveable.Position,
                                                                                p, mapObject.Position) == GetMaxCost(moveable, mapObject)));
     }
 }
Пример #6
0
 public void MoveSelectItem(Vector newPos)
 {
     if (curSelect is null)
     {
         return;
     }
     curSelect.Move(newPos);
 }
Пример #7
0
        protected virtual void Update()
        {
            float move = InputManager.GetHorizontal();

            if (move != 0)
            {
                moveable.Move(Vector2.right * move);
            }
        }
Пример #8
0
 // Update is called once per frame
 void Update()
 {
     // We need the movement set up first before reading in inputs and moving the cursor.
     if (movement != null)
     {
         inputMove.ReadInput();
         movement.Move(inputMove.HorizontalInput, inputMove.VerticalInput);
     }
 }
    public void Move(InputAction.CallbackContext context)
    {
        if (isStunned)
        {
            mMovementHandler.Move(Vector2.zero);
            return;
        }

        Vector2 newMovement = context.action.ReadValue <Vector2>();

        if (newMovement == Vector2.zero)
        {
            // this makes no sense
            //mCachedDirection = mCurMovement;
        }

        mCurMovement = newMovement;
        mMovementHandler.Move(newMovement);
    }
Пример #10
0
 public static void MoveTowards(IMoveable moveable, Point position)
 {
     if (moveable.Position != null && OpenNeighbors(moveable).Any())
     {
         double minCost = OpenNeighbors(moveable).Min(p => MovementCost(moveable.Position, p,
                                                                        position));
         moveable.Move(OpenNeighbors(moveable).FirstOrDefault(p => MovementCost(moveable.Position,
                                                                                p, position) == minCost));
     }
 }
Пример #11
0
        //#############
        //##  INPUT  ##
        //#############

        public void OnMove(InputAction.CallbackContext context)
        {
            if (mMovementBlocked)
            {
                return;
            }

            Vector2 moveVal = context.ReadValue <Vector2>();

            mMovement.Move(moveVal);
        }
Пример #12
0
    /// <summary>
    /// Evaluates the current position of the enemy to decide whether to
    /// attack or not.
    /// </summary>
    void EvaluatePlayerPosition()
    {
        if (!player.healthProperties.alive)
        {
            return;
        }
        if (ProgressionManager.Instance.gameOver)
        {
            return;
        }

        Vector2 difference = player.transform.position - transform.position;

        var playerScreenPos = Camera.main.WorldToScreenPoint(
            player.transform.position
            );

        moveable.TurnToScreenPoint(playerScreenPos);

        if (weaponAttacker == null)
        {
            weaponAttacker = GetComponentInChildren <IWeaponAttacker>();
        }

        try
        {
            if (weaponAttacker.InRange(difference.magnitude))
            {
                combat.Attack();
            }
            else
            {
                moveable.Move(difference);
            }
        }
        catch (System.NullReferenceException)
        {
            Debug.LogWarning("It did it again");
            moveable.Move(difference);
        }
    }
Пример #13
0
    /// <summary>
    /// Moves object based on Horizontal and Vertical input axes.
    /// </summary>
    void ProcessMovementInput()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        if (h == 0 && v == 0)
        {
            return;
        }

        moveable.Move(new Vector2(h, v));
    }
Пример #14
0
    void Update()
    {
        if (!isMoveAllowed)
        {
            return;
        }

        direction  = DirectionToTarget();
        direction *= Time.deltaTime;

        moveable.Move(direction);
    }
Пример #15
0
        public void MoveHero(IMoveable hero, TimeSpan dt, Vector2 movementVector)
        {
            Contract.Assert(hero != null, "hero!=null");
            Contract.Assert(movementVector != null, "movementVector!=null");

            var distance = dt.TotalSeconds * hero.MovementSpeed;

            var dx = distance * movementVector.X;

            var dy = distance * movementVector.Y;

            hero.Move(dx, dy);
        }
Пример #16
0
        private void MoveSelectionObject()
        {
            for (int i = 0; i < listISelectables.Count; i++)
            {
                IMoveable moveObject = listISelectables[i].GetInterface <IMoveable>();
                if (moveObject != null)
                {
                    moveObject.Move(vectorList[i]);
                }
            }

            vectorList.Clear();
        }
Пример #17
0
        protected void TryToMove()
        {
            if (isMoveAllowed)
            {
                if (IsCame)
                {
                    EndMove();
                    return;
                }
                //transform.position = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime * speed);

                //step equal 1 * deltaTime
                Vector3 newPosition = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime);

                Vector3 direction = newPosition - transform.position;
                moveable.Move(direction);
            }
        }
Пример #18
0
            public static void MoveOnInput(IMoveable movable, Keys?[] keys, Vector2 speed)
            {
                //Check if the array contains 4 keys
                if (keys.Length != 4)
                {
                    throw new ArgumentException("The length of the key array must be 4", "keys");
                }

                //The amount to move the object
                Vector2 moveAmount = Vector2.Zero;

                for (int i = 0; i < 4; i++)
                {
                    //Check if the keys is not null and is pressed
                    if (keys[i].HasValue && KeyDown(keys[i].Value))
                    {
                        switch (i)
                        {
                        //Up, down, right, left
                        case 0:
                            moveAmount.Y -= speed.Y;
                            break;

                        case 1:
                            moveAmount.Y += speed.Y;
                            break;

                        case 2:
                            moveAmount.X += speed.X;
                            break;

                        case 3:
                            moveAmount.X -= speed.X;
                            break;
                        }
                    }
                }

                //Move the object
                moveAmount *= TimeF.DeltaTime;
                movable.Move(moveAmount);
            }
Пример #19
0
        static void Main()
        {
            List <Animal> animals = new List <Animal>
            {
                new Person("Person", 20),
                new Dog(5, 20)
            };

            foreach (Animal animal in animals)
            {
                animal.Talk();
                animal.TakeBreath();
            }
            List <IJumpable> jumpables = new List <IJumpable>
            {
                new Person("Person", 20),
                new Dog(5, 20)
            };

            foreach (IJumpable jumpable in jumpables)
            {
                jumpable.Jump(10);
            }

            List <IMoveable> moveables = new List <IMoveable>
            {
                new Person("Person", 20),
                new Dog(5, 20)
            };

            foreach (IMoveable moveable in moveables)
            {
                moveable.Move();
            }
            Person    person   = new Person("Person", 30);
            ISwimable swimable = person;

            swimable.Move();
            IMoveable moveable1 = person;

            moveable1.Move();
        }
Пример #20
0
        public State Move(State state, char direction)
        {
            switch (direction)
            {
            case 'u':
                return(_moveUp.Move(state, direction: direction));

            case 'd':
                return(_moveDown.Move(state, direction: direction));

            case 'l':
                return(_moveLeft.Move(state, direction: direction));

            case 'r':
                return(_moveRight.Move(state, direction: direction));

            default:
                return(null);
            }
        }
        private void Update()
        {
            if (_moveController == null)
            {
                Debug.LogError("[WASD Input] IMoveable interface must be implemented");
                return;
            }
            if (_rotateController == null)
            {
                Debug.LogError("[WASD Input] IRotateable interface must be implemented");
                return;
            }

            var direction = new Vector3(0, 0, Input.GetAxis("Vertical"));

            _moveController.Move(direction);

            var rotation = new Vector3(0, Input.GetAxis("Horizontal"), 0);

            _rotateController.Rotate(rotation);
        }
Пример #22
0
 public void MoveFromAtoB(IMoveable moveable)
 {
     moveable.Move();
     // System.Console.WriteLine($"Ride on {vehicle.NameVehicle}");
 }
Пример #23
0
 private void Move(IMoveable entity)
 {
     entity.Move();
 }
Пример #24
0
 // Update is called once per frame
 void Update()
 {
     moveable.Move(t);
 }
Пример #25
0
 public void Run()
 {
     _rover.Move();
 }
Пример #26
0
 private void FixedUpdate()
 {
     _moveBehavior.Move();
 }
Пример #27
0
        public bool MoveObject(Vector2 relativeFrom, Vector2 relativeDelta, CameraBase camera, bool tryToClone, [CanBeNull] out IMoveable cloned)
        {
            if (_keepHighlight)
            {
                tryToClone = false;
            }
            else
            {
                _keepHighlight = true;
            }

            if (_justCloned)
            {
                tryToClone = false;
            }

            cloned = null;

            if (_arrowHighlighted != default(Vector3))
            {
                var plane   = new Plane(ParentMatrix.GetTranslationVector(), -camera.Look);
                var rayFrom = camera.GetPickingRay(relativeFrom, new Vector2(1f, 1f));
                var rayTo   = camera.GetPickingRay(relativeFrom + relativeDelta, new Vector2(1f, 1f));
                if (!Ray.Intersects(rayFrom, plane, out var distanceFrom) ||
                    !Ray.Intersects(rayTo, plane, out var distanceTo))
                {
                    return(false);
                }

                var pointDelta = rayTo.Direction * distanceTo - rayFrom.Direction * distanceFrom;
                if (tryToClone)
                {
                    cloned      = _parent.Clone();
                    _justCloned = true;
                }

                var totalDistance  = pointDelta.Length();
                var resultMovement = new Vector3(
                    pointDelta.X * _arrowHighlighted.X,
                    pointDelta.Y * _arrowHighlighted.Y,
                    pointDelta.Z * _arrowHighlighted.Z);
                resultMovement.Normalize();
                resultMovement *= totalDistance;

                _parent.Move(resultMovement);
                UpdateBoundingBox();
                return(true);
            }

            if (_circleHighlighted != default(Vector3))
            {
                var rotationAxis = _circleHighlighted.X * _circleHighlighted.Y * _circleHighlighted.Z != 0f ?
                                   camera.Look : _circleHighlighted;

                if (tryToClone)
                {
                    cloned      = _parent.Clone();
                    _justCloned = true;
                }

                _parent.Rotate(Quaternion.RotationAxis(rotationAxis, relativeDelta.X * 10f));
                UpdateBoundingBox();
                return(true);
            }

            if (_scaleHighlighted)
            {
                var v = relativeDelta.X + relativeDelta.Y;
                _parent.Scale(new Vector3(v > 0f ? 1.01f : 1f / 1.01f));
                UpdateBoundingBox();
                return(true);
            }

            return(false);
        }
Пример #28
0
 public static void MoveObject(IMoveable obj)
 {
     obj.Move();
 }
Пример #29
0
 public void Move(Transform t)
 {
     moveable_impl.Move(t);
 }
Пример #30
0
 public void DoAction()
 {
     _move.Move();
 }