Exemple #1
0
 public virtual void Move(MoveEventArgs e)
 {
     if (e.distance == 0)
     {
         return;
     }
     lock (privateLock)
     {
         if (!this._movable)
         {
             return;
         }
         if ((DateTime.Now - lastMoveTime).TotalSeconds < 1 / _frameRate)
         {
             return;
         }
         MoveStart?.Invoke(this);
         XYPosition previousPosition = _position;
         _position = _position + new XYPosition(e.distance * Math.Cos(e.angle), e.distance * Math.Sin(e.angle));
         Debug(this, "Move from " + previousPosition.ToString() + " angle : " + e.angle + " distance : " + e.distance + " aim : " + _position.ToString());
         OnMove?.Invoke(this, e, previousPosition);
         Debug(this, "Move result poition : " + this._position.ToString());
         MoveComplete?.Invoke(this);
     }
 }
Exemple #2
0
    public override void SetModeMove(Vector3 vector)
    {
        RaycastHit hit;

        //Debug.DrawLine((transform.position + orientation), (transform.position + orientation) + Vector3.down, Color.blue, 10f);

        if (!Physics.Raycast((transform.position + orientation), Vector3.down, out hit, 1f))
        {
            return;
        }

        canReset = false;

        OnMove?.Invoke(orientation);

        RotationCheck();

        _elapsedTime = 0;

        direction     = transform.position + orientation;
        previousRot   = transform.rotation;
        addedRotation = previousRot * Quaternion.AngleAxis(90f, axis);
        previousPos   = transform.position;

        // init move
        StartMoveBehavior();

        DoAction = DoActionMove;
    }
        /// <inheritdoc />
        public override void HandleComponentState(ComponentState state)
        {
            var newState = (TransformComponentState)state;

            if (LocalRotation != newState.Rotation)
            {
                SetRotation(newState.Rotation);
                OnRotate?.Invoke(newState.Rotation);
            }

            if (_position != newState.LocalPosition || GridID != newState.GridID)
            {
                var oldPos = LocalPosition;
                // TODO: this is horribly broken if the parent changes too, because the coordinates are all messed up.
                // Help.
                OnMove?.Invoke(this, new MoveEventArgs(oldPos, LocalCoordinatesFor(newState.LocalPosition, newState.GridID)));
                SetPosition(newState.LocalPosition);
                GridID = newState.GridID;
            }

            var newParentId = newState.ParentID;

            if (Parent?.Owner?.Uid != newParentId)
            {
                DetachParent();

                if (!newParentId.HasValue || !newParentId.Value.IsValid())
                {
                    return;
                }

                var newParent = Owner.EntityManager.GetEntity(newParentId.Value);
                AttachParent(newParent.GetComponent <ITransformComponent>());
            }
        }
Exemple #4
0
        public void Reveal(int row, int col)
        {
            TestCoord(row, col, nameof(Reveal));

            if (UnsField[row, col] != Hidden)
            {
                return;
            }

            UnsField[row, col] = SolField[row, col];

            OnMove?.Invoke(this, new MoveArgs(row, col, Move.Reveal, UnsField[row, col]));

            if (UnsField[row, col] == Mine)
            {
                OnEnd?.Invoke(this, new ResultArgs(GameResult.Lost));
                return;
            }

            if (UnsField[row, col] == 0)
            {
                foreach ((int nRow, int nCol) in GetAdj(row, col))
                {
                    Reveal(nRow, nCol);
                }
            }

            if (Game.HasWon())
            {
                OnEnd?.Invoke(this, new ResultArgs(GameResult.Won));
            }
        }
Exemple #5
0
 private void onMove(Vector3 target)
 {
     if (CurrentDrag == Drag.None)
     {
         OnMove.Invoke(target);
     }
 }
        /// <summary>
        /// Updates the Movement.
        /// </summary>
        public override void Update()
        {
            base.Update();

            if (Freeze)
            {
                return;
            }

            TargetSpeed.MaxX = Speed.MaxX;
            TargetSpeed.MaxY = Speed.MaxY;

            if (Axis != null)
            {
                TargetSpeed.X = Axis.X * TargetSpeed.MaxX;
                TargetSpeed.Y = Axis.Y * TargetSpeed.MaxY;

                // Multiply by 1/sqrt(2) for circle clamp.
                if (CircleClamp && Math.Abs(TargetSpeed.X) == 1 && Math.Abs(TargetSpeed.Y) == 1)
                {
                    TargetSpeed.X *= .7071f;
                    TargetSpeed.Y *= .7071f;
                }
            }

            Speed.X = Util.Approach(Speed.X, TargetSpeed.X, Accel);
            Speed.Y = Util.Approach(Speed.Y, TargetSpeed.Y, Accel);

            MoveXY((int)Speed.X, (int)Speed.Y, Collider);

            OnMove?.Invoke();
        }
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                OnMove?.Invoke(Vector2Int.left);
            }
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                OnMove?.Invoke(Vector2Int.right);
            }
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                OnMove?.Invoke(Vector2Int.up);
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                OnMove?.Invoke(Vector2Int.down);
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                OnRestart?.Invoke();
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                OnEscape?.Invoke();
            }
        }
Exemple #8
0
        private void InitializePositionEvents()
        {
			MovFun = (Glfw.Window P, int X, int Y) =>
			{
				foreach (IMonitor monitor in Environment.Platform.AvaiableMonitors)
				{
					if (Position > monitor.Position && Position < monitor.Position + monitor.CurrentResolution.ResolutionSize)
						Monitor = monitor;
				}

				OnMove?.Invoke(this, new WindowMoveEventArgs { Position = new Vector2i(X, Y) });
			};

			SizFun = (Glfw.Window P, int W, int H) =>
			{
				foreach (IMonitor monitor in Environment.Platform.AvaiableMonitors)
				{
					if (Position > monitor.Position && Position < monitor.Position + monitor.CurrentResolution.ResolutionSize)
						Monitor = monitor;
				}

				OnResize?.Invoke(this, new WindowResizeEventArgs { Size = new Vector2i(W, H) });
			};

			Glfw.SetWindowPosCallback(Handle, MovFun);
			Glfw.SetWindowSizeCallback(Handle, SizFun);
        }
Exemple #9
0
 public void OnClickButton(string message)
 {
     if (message == "move")
     {
         if (OnAttack != null)
         {
             OnMove.Invoke(Actor);
         }
     }
     else if (message == "attack")
     {
         if (OnAttack != null)
         {
             OnAttack.Invoke(Actor);
         }
     }
     else if (message == "turn")
     {
         if (OnTurn != null)
         {
             OnTurn.Invoke(Actor);
         }
     }
     else if (message == "finish")
     {
         if (OnFinish != null)
         {
             OnFinish.Invoke(Actor);
         }
     }
 }
Exemple #10
0
    private void Update()
    {
        var hadAKeyPressed = keyPressed;

        keyPressed = false;
        var direction = Vector2.zero;

        if (Input.GetKey(up))
        {
            direction += new Vector2(0, 1);
        }
        if (Input.GetKey(down))
        {
            direction += new Vector2(0, -1);
        }
        if (Input.GetKey(left))
        {
            direction += new Vector2(-1, 0);
        }
        if (Input.GetKey(right))
        {
            direction += new Vector2(1, 0);
        }
        if (direction != Vector2.zero)
        {
            keyPressed = true;
        }
        if (hadAKeyPressed || keyPressed)
        {
            OnMove?.Invoke(direction);
        }
    }
Exemple #11
0
        /// <summary>
        /// Makes a new instance of <see cref="GlfwMouse"/> class.
        /// </summary>
        /// <param name="window">Current context.</param>
        public GlfwMouse(GlfwWindow window)
        {
            handler = window;

            handler.OnRestore += Handler_OnRestore;

            cursorCallback = (w, x, y) =>
            {
                OnMove?.Invoke(this, new MousePositiontEventArgs
                {
                    Position = new Vector2((float)x, (float)y)
                });
            };

            scrollCallback = (w, x, y) =>
            {
                OnScroll?.Invoke(this, new MouseOffsetEventArgs
                {
                    Offset = new Vector2((float)x, (float)y)
                });
            };

            buttonCallback = (w, button, action, modifiers) =>
            {
                OnButtonEvent?.Invoke(this, new MouseKeyEventArgs
                {
                    Key       = (MouseButton)button,
                    Action    = (KeyState)action,
                    Modifiers = (KeyModifier)modifiers
                });
            };
        }
Exemple #12
0
        public override void OnPointerDown(PointerEventData eventData)
        {
            base.OnPointerDown(eventData);
            joystickHandle.position = eventData.pressPosition;

            OnMove?.Invoke(this, input);
        }
Exemple #13
0
    void SetCellToStone(Cell prevCel, Cell newCell, Stone s, bool isBack = false)
    {
        if (newCell != null)
        {
            if (!isBack)
            {
                movesCount++;
            }
            else
            {
                movesCount--;
            }

            OnMove?.Invoke(movesCount);
            bool inPit = !s.Interactable;


            newCell.SetStone(s);

            prevCel.TakeStone();

            Debug.Log(" s.StartMove start");
            s.StartMove(newCell.transform, inPit, isBack);
            Debug.Log(" s.StartMove finish");
        }
    }
 public static void Attach(Transform target, Vector3 localPosition)
 {
     Instance.target = target;
     Instance.transform.SetParent(target);
     Instance.transform.localPosition = localPosition;
     OnMove.Invoke();
 }
Exemple #15
0
        /// <summary>
        /// Generates new position for idle move.
        /// </summary>
        /// <param name="normalStep">idle step</param>
        private void GenerateRandomIdlePosition(byte normalStep)
        {
            float x1 = PosX - normalStep;

            if (x1 < MoveArea.X1)
            {
                x1 = MoveArea.X1;
            }
            float x2 = PosX + normalStep;

            if (x2 > MoveArea.X2)
            {
                x2 = MoveArea.X2;
            }

            float z1 = PosZ - normalStep;

            if (z1 < MoveArea.Z1)
            {
                z1 = MoveArea.Z1;
            }
            float z2 = PosZ + normalStep;

            if (z2 < MoveArea.Z2)
            {
                z2 = MoveArea.Z2;
            }

            PosX = new Random().NextFloat(x1, x2);
            PosZ = new Random().NextFloat(z1, z2);

            //_logger.LogDebug($"Mob {Id} walks to new position x={PosX} y={PosY} z={PosZ}.");

            OnMove?.Invoke(this);
        }
Exemple #16
0
    void KeyboardMovement()
    {
        var position = boardMover.Position;
        int delta    = 0;

        if (Input.GetKeyDown(KeyCode.D))
        {
            delta--;
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            delta++;
        }
        if (delta != 0)
        {
            var newPosition = new RadialPosition(position.Lane + delta, 0);
            if (BoardController.Instance.TryMove(boardMover, newPosition))
            {
                Factory.Instance.PlaySound(MovementClip, pitchVariance.GetRandomPitch(), MovementVolume);
                sr.sprite = PlayerSprites[newPosition.Lane];
                OnMove?.Invoke(newPosition);
            }
            else
            {
                Factory.Instance.PlaySound(BlockedClip, pitchVariance.GetRandomPitch(), BlockedVolume);
            }
        }
    }
Exemple #17
0
    private void LateUpdate()
    {
        m_TimeRate     = Mathf.Lerp(m_MaxTimeRate, m_MinTimeRate, m_FoodAmount / m_MaxFoodAmount);
        m_ElapsedTime += Time.deltaTime;
        if (m_ElapsedTime < m_TimeRate)
        {
            return;
        }

        if (MoveUp > 0.0f)
        {
            m_Movement = new Vector3(0, 0, 1);
        }
        else if (MoveRight > 0.0f)
        {
            m_Movement = new Vector3(1, 0, 0);
        }
        else if (MoveDown > 0.0f)
        {
            m_Movement = new Vector3(0, 0, -1);
        }
        else if (MoveLeft > 0.0f)
        {
            m_Movement = new Vector3(-1, 0, 0);
        }

        OnMove?.Invoke();

        m_FirstBody.ChangePosition(transform.position);
        transform.position += m_Movement;

        Reset();
    }
        /// <inheritdoc />
        public override void HandleComponentState(ComponentState state)
        {
            var newState = (TransformComponentState)state;

            Rotation = newState.Rotation;

            if (_position != newState.Position || MapID != newState.MapID || GridID != newState.GridID)
            {
                OnMove?.Invoke(this, new MoveEventArgs(LocalPosition, new LocalCoordinates(newState.Position, newState.GridID, newState.MapID)));
                _position = newState.Position;
                MapID     = newState.MapID;
                GridID    = newState.GridID;
            }

            if (Parent?.Owner?.Uid != newState.ParentID)
            {
                DetachParent();
                if (!(newState.ParentID is int parentID))
                {
                    return;
                }
                var newParent = Owner.EntityManager.GetEntity(parentID);
                AttachParent(newParent.GetComponent <ITransformComponent>());
            }
        }
Exemple #19
0
            public void Move()
            {
                x = new Random().Next();
                y = new Random().Next();

                OnMove?.Invoke(x, y);
            }
        private void InvokeMoveEvents()
        {
            var event_args = new ElementMoveArgs(this, ActualRow, ActualColumn);

            OnMove?.Invoke(event_args);
            Grid.OnMove?.Invoke(event_args);
        }
Exemple #21
0
        /// <summary>
        /// Moves mob to the specified position.
        /// </summary>
        /// <param name="x">x coordinate</param>
        /// <param name="z">z coordinate</param>
        private void Move(float x, float z)
        {
            if (Math.Abs(PosX - x) < DELTA && Math.Abs(PosZ - z) < DELTA)
            {
                return;
            }

            if (_dbMob.ChaseStep == 0 || _dbMob.ChaseTime == 0)
            {
                return;
            }

            var now               = DateTime.UtcNow;
            var mobVector         = new Vector2(PosX, PosZ);
            var destinationVector = new Vector2(x, z);

            var normalizedVector  = Vector2.Normalize(destinationVector - mobVector);
            var deltaTime         = now.Subtract(_lastMoveUpdate);
            var deltaMilliseconds = deltaTime.TotalMilliseconds > 2000 ? 500 : deltaTime.TotalMilliseconds;
            var temp = normalizedVector * (float)(_dbMob.ChaseStep * 1.0 / _dbMob.ChaseTime * deltaMilliseconds);

            PosX += float.IsNaN(temp.X) ? 0 : temp.X;
            PosZ += float.IsNaN(temp.Y) ? 0 : temp.Y;

            _lastMoveUpdate = now;

            // Send update to players, that mob position has changed.
            if (DateTime.UtcNow.Subtract(_lastMoveUpdateSent).TotalMilliseconds > 1000)
            {
                OnMove?.Invoke(this);
                _lastMoveUpdateSent = now;
            }
        }
 private void Update()
 {
     if (target != null && target.hasChanged)
     {
         OnMove.Invoke();
         target.hasChanged = false;
     }
 }
Exemple #23
0
 internal void RegisterInputMove(PointerEventArgs args)
 {
     if (CountMovingAsDown)
     {
         downPointers.Add(args.RawTouchLocation.Id);
     }
     OnMove?.Invoke(this, args);
 }
Exemple #24
0
    void HandleMovementInput()
    {
        var normalizedRawInput =
            new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).NormalizeIfMagnitudeGreaterThanOne();
        var movementVector = CalculateMovementVector(normalizedRawInput);

        OnMove?.Invoke(movementVector);
    }
Exemple #25
0
        public virtual void MoveTo(Vector3Int destination)
        {
            Movement.CanMove = false;

            Position = destination;
            OnMove?.Invoke();
            UpdateVision();
        }
 protected override void OnDeltaChanged()
 {
     base.OnDeltaChanged();
     LatestMoveAmount = Delta - PreviousDelta;
     PreviousDelta    = Delta;
     OnMove?.Invoke(this, LatestMoveAmount);
     SkiaManager.InvalidCanvas();
 }
Exemple #27
0
 /// <summary>
 /// Checks if the object has moved.
 /// </summary>
 /// <param name="gameTime"></param>
 public virtual void Update(GameTime gameTime)
 {
     if (prevPosition != Holder.Position)
     {
         OnMove?.Invoke(this, args);
     }
     prevPosition          = Holder.Position;
     args.PreviousPosition = prevPosition;
 }
Exemple #28
0
    void Update()
    {
        if (Input.touches.Length < 0)
        {
            return;
        }

        if (Input.touches.Length > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
        {
            this._downPossition = Input.GetTouch(0).position;
        }

        if (this._downPossition == Vector2.zero)
        {
            return;
        }
        else if (this._dragTimer > 0)
        {
            this._dragTimer -= Time.deltaTime;
        }

        if (Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            this._currentPossiton = Input.GetTouch(0).position;
            float distance = this.GetSwipeDistance(this._downPossition, this._currentPossiton);

            if (distance != 0 && this._dragTimer > 0)
            {
                this._swiping = true;
                OnMove?.Invoke(distance);
            }
            else if (this._dragTimer <= 0 && !this._swiping)
            {
                OnDrag?.Invoke(this._currentPossiton);
            }
        }

        if (Input.GetTouch(0).phase == TouchPhase.Ended)
        {
            this._upPossition = Input.GetTouch(0).position;

            int direction = this.GetSwipeDirection(this._downPossition, this._upPossition);

            if (direction != 0)
            {
                this._swiping = false;
                OnSwipe?.Invoke(direction);
            }
            else if (!this._swiping)
            {
                OnTouch?.Invoke(this._downPossition);
            }

            this._dragTimer     = this._dragTimerReset;
            this._downPossition = Vector2.zero;
        }
    }
Exemple #29
0
        private void OnInputMovement(InputAction.CallbackContext context)
        {
            Vector2 movement = context.ReadValue <Vector2>();

            //Debug.Log($"{index}: Move {movement}");
            OnMove?.Invoke(movement);
            OnMoveHorizontal?.Invoke(movement.x);
            OnMoveVertical?.Invoke(movement.y);
        }
Exemple #30
0
        private void Update()
        {
            OnMove?.Invoke();

            if (Input.GetKeyDown(KeyCode.Space))
            {
                OnSpawnBomb?.Invoke();
            }
        }