コード例 #1
0
 void OnMovementKeyPressed(MovementKey key)
 {
     if (MovementKeyPressed != null)
     {
         MovementKeyPressed(key);
     }
 }
コード例 #2
0
        Vector2 OffsetToPosition(MovementKey movementKey)
        {
            Rect    r = transform.parent.GetComponent <RectTransform>().rect;
            Vector2 p = originalPosition;

            switch (movementKey.align)
            {
            case ParentAlign.BottomToTop:
                p.y += r.height;
                break;

            case ParentAlign.TopToBottom:
                p.y -= r.height;
                break;

            case ParentAlign.LeftToRight:
                p.x += r.width;
                break;

            case ParentAlign.RightToLeft:
                p.x -= r.width;
                break;
            }
            return(p + movementKey.offset);
        }
コード例 #3
0
 public void InvokeMovementKeyUnPressed(MovementKey movementKey)
 {
     if (movementKeyUnPressed != null)
     {
         movementKeyUnPressed.Invoke(movementKey);
     }
 }
コード例 #4
0
 public ControlInputPackage(MovementKey movement)
 {
     MovementKey     = movement;
     ClickedObjectId = -1;
     CtrlKeyState    = InputKeyState.KeyUp;
     ShiftKeyState   = InputKeyState.KeyUp;
     AltKeyState     = InputKeyState.KeyUp;
 }
コード例 #5
0
 public ControlInputPackage(MovementKey movement, int clickedObjectId, InputKeyState ctrl, InputKeyState shift,
                            InputKeyState alt)
 {
     MovementKey     = movement;
     ClickedObjectId = clickedObjectId;
     CtrlKeyState    = ctrl;
     ShiftKeyState   = shift;
     AltKeyState     = alt;
 }
コード例 #6
0
ファイル: TankMovementV1.cs プロジェクト: Wysepka/HangTanks
    public override void ApplyMovement(MovementKey movementKey)
    {
        //Debug.Log("MovementKey: " + movementKey.ToString());
        if (movementKey == MovementKey.LeftArrow)
        {
            if (leftRightValue > -1f)
            {
                leftRightValue -= 0.05f * leftRightMultiplier * Time.deltaTime;
            }
            else
            {
                leftRightValue = -1f;
            }

            if (LeftRightPressedValue > -1f)
            {
                LeftRightPressedValue -= leftRightMultiplier * Time.deltaTime;
            }
            else
            {
                LeftRightPressedValue = -1f;
            }
        }
        else if (movementKey == MovementKey.RightArrow)
        {
            if (leftRightValue < 1f)
            {
                leftRightValue += 0.05f * leftRightMultiplier * Time.deltaTime;
            }
            else
            {
                leftRightValue = 1f;
            }

            if (LeftRightPressedValue < 1f)
            {
                LeftRightPressedValue += leftRightMultiplier * Time.deltaTime;
            }
            else
            {
                LeftRightPressedValue = 1f;
            }
        }
        else
        {
            LeftRightPressedValue += (0 - LeftRightPressedValue) * Time.deltaTime;
        }

        UpdatePosition(
            new Vector3().Lerp(mapHandler.LeftMaxMovement.position
                               , mapHandler.RightMaxMovement.position, leftRightValue)
            );
    }
コード例 #7
0
    void HandleMovementKey(MovementKey keyPressed)
    {
        float movement = Settings.Instance.TargetMovementSpeed;

        switch (keyPressed)
        {
        case MovementKey.Up:
            currentLocation.y += movement;
            break;

        case MovementKey.Down:
            currentLocation.y -= movement;
            break;

        case MovementKey.Left:
            currentLocation.x -= movement;
            break;

        case MovementKey.Right:
            currentLocation.x += movement;
            break;
        }
    }
コード例 #8
0
        public void OnNextFrame()
        {
            InputKeyState ctrl  = Keyboard.IsKeyPressed(Keyboard.Key.LControl) ? InputKeyState.KeyDown : InputKeyState.KeyUp;
            InputKeyState shift = Keyboard.IsKeyPressed(Keyboard.Key.LShift) ? InputKeyState.KeyDown : InputKeyState.KeyUp;
            InputKeyState alt   = Keyboard.IsKeyPressed(Keyboard.Key.LAlt) ? InputKeyState.KeyDown : InputKeyState.KeyUp;

            /*
             * InputKeyState up = Keyboard.IsKeyPressed(Keyboard.Key.W) ? InputKeyState.KeyDown : InputKeyState.KeyUp;
             * InputKeyState right = Keyboard.IsKeyPressed(Keyboard.Key.D) ? InputKeyState.KeyDown : InputKeyState.KeyUp;
             * InputKeyState down = Keyboard.IsKeyPressed(Keyboard.Key.S) ? InputKeyState.KeyDown : InputKeyState.KeyUp;
             * InputKeyState left = Keyboard.IsKeyPressed(Keyboard.Key.A) ? InputKeyState.KeyDown : InputKeyState.KeyUp;
             */
            MovementKey movementKey = MovementKey.None;

            if (Keyboard.IsKeyPressed(Keyboard.Key.W))
            {
                movementKey = MovementKey.Up;
            }
            else if (Keyboard.IsKeyPressed(Keyboard.Key.D))
            {
                movementKey = MovementKey.Right;
            }
            else if (Keyboard.IsKeyPressed(Keyboard.Key.S))
            {
                movementKey = MovementKey.Down;
            }
            else if (Keyboard.IsKeyPressed(Keyboard.Key.A))
            {
                movementKey = MovementKey.Left;
            }

            if (movementKey != MovementKey.None)
            {
                ControlInputPackage updatePackage = new ControlInputPackage(movementKey);
                ClientNetworkManager.Instance?.SendUserInput(updatePackage, Reliability.Unreliable);
            }
        }
コード例 #9
0
    //===========================================================================//

    public void ApplyTankMovement(MovementKey movementKey)
    {
        tank.TankMovement.ApplyMovement(movementKey);
    }
コード例 #10
0
 public void RegisterToMovementApplied(MovementKey movementKey)
 {
     this.eventHandler.ApplyTankMovement(movementKey);
 }
コード例 #11
0
        public void Move(MovementKey movement)
        {
            //LogManager.RuntimeLogger.Log("Movement: " + movement);
            if (Scene == null || InstanceId == -1)
            {
                //LogManager.RuntimeLogger.LogError("Trying to move mob that is not instantiated!");
                return;
            }

            if (!CanMove)
            {
                //LogManager.RuntimeLogger.Log("Mob cannot move!");
                return;
            }

            if (_isMoving)
            {
                //LogManager.RuntimeLogger.Log("Mob is already moving!");
                return;
            }

            int deltaX = 0, deltaY = 0;

            switch (movement)
            {
            case MovementKey.None:
                break;

            case MovementKey.Up:
                deltaY      = -1; // TODO Project Y axis
                _activeIcon = UpFacingIcon;
                break;

            case MovementKey.Right:
                deltaX      = 1;
                _activeIcon = RightFacingIcon;
                break;

            case MovementKey.Down:
                _activeIcon = DownFacingIcon;
                deltaY      = 1;
                break;

            case MovementKey.Left:
                _activeIcon = LeftFacingIcon;
                deltaX      = -1;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(movement), movement, null);
            }

            Vector2Int nextCell = Position + new Vector2Int(deltaX, deltaY);

            //LogManager.RuntimeLogger.Log("Next cell: " + nextCell);
            if (!Scene.IsInBounds(nextCell))
            {
                //LogManager.RuntimeLogger.Log("Next cell not in bounds!");
                return;
            }

            if (Scene.IsInBounds(nextCell))
            {
                if (!IgnoreObstacles)
                {
                    if (Scene.IsPassable(nextCell))
                    {
                        //LogManager.RuntimeLogger.Log("MoveInternal:" + nextCell);
                        MoveInternal(nextCell);
                    }
                    else
                    {
                        Scene.SendTryPass(nextCell, this);
                    }
                }
                else
                {
                    MoveInternal(nextCell);
                }
            }
        }
コード例 #12
0
ファイル: TankMovement.cs プロジェクト: Wysepka/HangTanks
 public virtual void ApplyMovement(MovementKey movementKey)
 {
 }