Beispiel #1
0
 /// <summary>
 ///     Get the opposite <see cref="EDirection4"/> of the given value
 /// </summary>
 /// <param name="dir"></param>
 /// <returns></returns>
 public static EDirection4 Opposite(this EDirection4 dir)
 {
     if (dir == EDirection4.None)
     {
         return(EDirection4.None);
     }
     return((EDirection4)(((int)dir + 1) % 4 + 1));
 }
Beispiel #2
0
 /// <summary>
 ///     Converts a <see cref="EDirection4"/> to <see cref="EDirection8"/>
 /// </summary>
 /// <param name="dir4"></param>
 /// <returns></returns>
 public static EDirection8 To8(this EDirection4 dir4)
 {
     if (dir4 == EDirection4.None)
     {
         return(EDirection8.None);
     }
     return((EDirection8)((int)dir4 * 2 - 1));
 }
Beispiel #3
0
    /// <summary>
    ///     Converts a <see cref="EDirection4"/> to a <see cref="EDirection2"/>.
    /// </summary>
    /// <param name="dir4"></param>
    /// <returns></returns>
    public static EDirection2 To2(this EDirection4 dir4)
    {
        switch (dir4)
        {
        case EDirection4.None:
            return(EDirection2.None);

        case EDirection4.Up:
        case EDirection4.Down:
            return(EDirection2.Vertical);

        case EDirection4.Right:
        case EDirection4.Left:
            return(EDirection2.Horizontal);

        default:
            throw new ArgumentOutOfRangeException("dir4", dir4, null);
        }
    }
Beispiel #4
0
    protected override void InternalEvent(Entry e)
    {
        base.InternalEvent(e);

        // 双击冲刺
        ComboClick combo = e.INPUT.Keyboard.GetComboClick((int)PCKeys.A);

        if (combo != null && combo.IsDoubleClick)
        {
            running = true;
        }
        else
        {
            combo = e.INPUT.Keyboard.GetComboClick((int)PCKeys.D);
            if (combo != null && combo.IsDoubleClick)
            {
                running = true;
            }
        }
        // 按照最后按下的方向键移动
        int[]       keys      = e.INPUT.Keyboard.Current.GetPressedKey();
        bool        doMove    = false;
        EDirection4 direction = EDirection4.Up;

        for (int i = keys.Length - 1; i >= 0; i--)
        {
            if (keys[i] == (int)PCKeys.A)
            {
                flip = EFlip.FlipHorizontally;
                if (jumpSpeed.Y == 0)
                {
                    CheckMoveX(-SPEED * (running ? RUNNING : 1));
                    //Action(T动作.ET动作Action.蒲公英_移动);
                }
                else
                {
                    jumpSpeed.X -= FLY;
                }
                doMove    = true;
                direction = EDirection4.Left;
                break;
            }
            else if (keys[i] == (int)PCKeys.D)
            {
                flip = EFlip.None;
                if (jumpSpeed.Y == 0)
                {
                    CheckMoveX(SPEED * (running ? RUNNING : 1));
                    //Action(T动作.ET动作Action.蒲公英_移动);
                }
                else
                {
                    jumpSpeed.X += FLY;
                }
                doMove    = true;
                direction = EDirection4.Right;
                break;
            }
        }

        // 单击跳跃
        if (jumpSpeed.Y == 0 && e.INPUT.Keyboard.IsPressed(PCKeys.W))
        {
            Action(T动作.ET动作Action.蒲公英_起跳);
            jumpSpeed.Y = JUMP;
            if (doMove)
            {
                jumpSpeed.X = SPEED;
                if (running)
                {
                    jumpSpeed.X *= RUNNING;
                }
                if (direction == EDirection4.Left)
                {
                    jumpSpeed.X = -jumpSpeed.X;
                }
            }
            else
            {
                jumpSpeed.X = 0;
            }
        }
        if (!doMove)
        {
            running = false;
            //if (jumpSpeed.Y == 0 && anime.Sequence.Name == T动作.ET动作Action.蒲公英_移动.ToString())
            //    Action(T动作.ET动作Action.蒲公英_待机);
        }
    }
Beispiel #5
0
 /// <summary>
 ///     Get the direction as a <see cref="Vector2"/>
 /// </summary>
 /// <param name="dir"></param>
 /// <returns></returns>
 public static Vector2 ToVector2(this EDirection4 dir)
 {
     return(dir.To8().ToVector2());
 }
Beispiel #6
0
 /// <summary>
 ///     Check to see if both <see cref="EDirection4"/> are opposite to each other
 /// </summary>
 /// <param name="lhs"></param>
 /// <param name="rhs"></param>
 /// <returns>True if opposite</returns>
 public static bool IsOpposite(this EDirection4 lhs, EDirection4 rhs)
 {
     return(lhs.To8().IsOpposite(rhs.To8()));
 }