Beispiel #1
0
    /// <summary>
    /// Gathers input information from the player and stores it in an InputDir
    /// object, just to simplify input matters.
    /// </summary>
    /// <returns>An InputDir enum object holding the input information for
    /// this frame.</returns>
    private InputDir GetInputDir()
    {
        float hInput = Input.GetAxisRaw("Horizontal");
        float vInput = Input.GetAxisRaw("Vertical");

        InputDir input = InputDir.NONE;

        if (hInput < 0f)
        {
            input |= InputDir.LEFT;
        }
        else if (hInput > 0f)
        {
            input |= InputDir.RIGHT;
        }

        if (vInput > 0f)
        {
            input |= InputDir.UP;
        }
        else if (vInput < 0f)
        {
            input |= InputDir.DOWN;
        }

        return(input);
    }
Beispiel #2
0
        public void SendDir(InputDir dir)
        {
            var net            = this.world.GetModule <NetworkModule>();
            var playersFeature = this.world.GetFeature <PlayersFeature>();

            net.RPC(this, this.movePlayerRpcId, playersFeature.GetActivePlayerId(), dir);
        }
Beispiel #3
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.W))
        {
            movePref = InputDir.w;
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            movePref = InputDir.s;
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            movePref = InputDir.a;
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            movePref = InputDir.d;
        }

        if (player.transform.position == new Vector3(tileX, 0, tileY) + new Vector3(0.5f, 0.5f, 0.5f) || player.transform.position == new Vector3(tileX, tileY, 0) + new Vector3(0.5f, 0.5f, 0.5f))
        { /// misschien in range voor minder lag
            UpdateWalkPos(1, 1);
        }

        MoveTo(tileX, tileY);
        player.transform.GetChild(0).transform.localRotation = Quaternion.Euler(pacmanRot * 90);
    }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.W))
        {
            movePref = InputDir.w;
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            movePref = InputDir.s;
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            movePref = InputDir.a;
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            movePref = InputDir.d;
        }

        if (transform.position == new Vector3(tileX, 0, tileY))
        {
            UpdateWalkPos(1, 1);
        }
        else if (transform.position == new Vector3(tileX, tileY, 0))
        {
            UpdateWalkPos(1, 1);
            print("can update walk1");
        }


        #region

        /*
         *      if (Input.GetKeyDown(KeyCode.W)){
         *          if (TileMap.tiles[tileX, tileY - 1] == 0){
         *                  tileY -= 1;
         *          }
         *      }
         *      if (Input.GetKeyDown(KeyCode.S)){
         *          if (TileMap.tiles[tileX, tileY + 1] == 0){
         *                  tileY += 1;
         *          }
         *      }
         *      if (Input.GetKeyDown(KeyCode.A)){
         *          if (TileMap.tiles[tileX + 1, tileY] == 0){
         *                  tileX += 1;
         *          }
         *      }
         *      if (Input.GetKeyDown(KeyCode.D)){
         *          if (TileMap.tiles[tileX - 1, tileY] == 0){
         *                  tileX -= 1;
         *          }
         *      }
         */
        #endregion

        map.MoveTo(tileX, tileY);
    }
Beispiel #5
0
        private void MovePlayer_RPC(int actorId, InputDir dir)
        {
            var playersFeature = this.world.GetFeature <PlayersFeature>();
            var playerEntity   = playersFeature.GetEntityByActorId(actorId);

            playerEntity.SetData(new Example.Features.PlayerMovement.Components.MoveAction()
            {
                dir = dir.dir
            }, ComponentLifetime.NotifyAllSystems);
        }
Beispiel #6
0
        public void ReadAll()
        {
            ReadingFiles = true;
            ReadData.Clear();

            var results = InputDir.GetFiles(SearchPattern).Select(ReadFile);

            Task.WaitAll(results.ToArray());

            ReadingFiles = false;
        }
    public void SetInputDir(InputDir inputDir)
    {
        this.inputDir = inputDir;

        if (inputDir == InputDir.Left)
        {
            sr.flipX = true;
        }
        else if (inputDir == InputDir.Right)
        {
            sr.flipX = false;
        }
    }
Beispiel #8
0
    /// <summary>
    /// 获取朝向
    /// </summary>
    void GetInputDir()
    {
        m_InputDir = InputDir.NULL;
        if (Input.GetMouseButtonDown(0))
        {
            activeInput = true;
            m_mousePos  = Input.mousePosition;
        }
        if (Input.GetMouseButton(0) && activeInput)
        {
            Vector3 dir = Input.mousePosition - m_mousePos;
            if (dir.magnitude > 20)
            {
                if (Mathf.Abs(dir.x) > Mathf.Abs(dir.y) && dir.x > 0)
                {
                    m_InputDir = InputDir.RIGHT;
                }
                else if (Mathf.Abs(dir.x) > Mathf.Abs(dir.y) && dir.x < 0)
                {
                    m_InputDir = InputDir.LEFT;
                }
                else if (Mathf.Abs(dir.x) < Mathf.Abs(dir.y) && dir.y > 0)
                {
                    m_InputDir = InputDir.UP;
                }
                else if (Mathf.Abs(dir.x) < Mathf.Abs(dir.y) && dir.y < 0)
                {
                    m_InputDir = InputDir.DOWN;
                }
            }
            //print(m_InputDir.ToString());
        }

        if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.Space))
        {
            m_InputDir = InputDir.UP;
        }
        else if (Input.GetKeyDown(KeyCode.S))
        {
            m_InputDir = InputDir.DOWN;
        }
        else if (Input.GetKeyDown(KeyCode.A))
        {
            m_InputDir = InputDir.LEFT;
        }
        else if (Input.GetKeyDown(KeyCode.D))
        {
            m_InputDir = InputDir.RIGHT;
        }
    }
    private void UpdateWalkPos(int x, int y)
    {
        print("can update walk");
        if (movePref == InputDir.w && map.tiles[tileX, tileY - 1] == 0)
        {
            moveDir = InputDir.w;
        }
        if (movePref == InputDir.s && map.tiles[tileX, tileY + 1] == 0)
        {
            moveDir = InputDir.s;
        }
        if (movePref == InputDir.a && map.tiles[tileX + 1, tileY] == 0)
        {
            moveDir = InputDir.a;
        }
        if (movePref == InputDir.d && map.tiles[tileX - 1, tileY] == 0)
        {
            moveDir = InputDir.d;
        }

        if (moveDir == InputDir.w && map.tiles[tileX, tileY - 1] == 0)
        {
            if (map.tiles[tileX, tileY - 1] == map.tiles[tileX, -1])
            {
                map.GetTileForDirection(0, -1);
                print("d");
            }
            tileY -= y;
        }
        if (moveDir == InputDir.s && map.tiles[tileX, tileY + 1] == 0)
        {
            tileY += y;
        }
        if (moveDir == InputDir.a && map.tiles[tileX + 1, tileY] == 0)
        {
            tileX += 1;
        }
        if (moveDir == InputDir.d && map.tiles[tileX - 1, tileY] == 0)
        {
            tileX -= 1;
        }
    }
Beispiel #10
0
    void Update()
    {
        InputDir input = InputDir.NONE;

        if (!levelChanger.InputLocked)
        {
            input = GetInputDir();
        }

        if (state == PlayerState.IDLE || playerArrived)
        {
            SetInputTarget(input);
        }

        if (state == PlayerState.MOVING)
        {
            MovePlayer();
        }

        ManageAnim();
    }
Beispiel #11
0
    public void AnimManager(InputDir dir)
    {
        switch (dir)
        {
        case InputDir.LEFT:
            playAnim = PlayLeft;
            break;

        case InputDir.RIGHT:
            playAnim = PlayRight;
            break;

        case InputDir.UP:
            playAnim = PlayJump;
            break;

        case InputDir.DOWN:
            playAnim = PlayRoll;
            break;
        }
    }
Beispiel #12
0
 /// <summary>
 /// Attempts to migrate all sub-directories when the working directory is changed.
 /// Currently this only occurs in the GUI when a working directory has been changed.
 /// </summary>
 public void AttemptSubDirMigration(string newWDirAbs)
 {
     try
     {
         if (!newWDirAbs.EndsWith(DSStr))
         {
             newWDirAbs += DS;
         }
         string tempPath;
         if (!InputDir.StartsWith(".." + DS))
         {
             tempPath = newWDirAbs + InputDir;
             if (Directory.Exists(tempPath))
             {
                 iDir = tempPath;
                 if (!DefaultSeedFileName.StartsWith(".." + DS))
                 {
                     tempPath = iDir + DefaultSeedFileName;
                     if (File.Exists(tempPath))
                     {
                         defaultSeedFileName = tempPath;
                     }
                 }
             }
         }
         if (!OutputDir.StartsWith(".." + DS))
         {
             tempPath = newWDirAbs + OutputDir;
             if (Directory.Exists(tempPath))
             {
                 oDir = tempPath;
             }
         }
         if (!RulesDir.StartsWith(".." + DS))
         {
             tempPath = newWDirAbs + RulesDir;
             if (Directory.Exists(tempPath))
             {
                 rDir = tempPath;
                 if (!CompiledRuleFunctions.StartsWith(".." + DS))
                 {
                     tempPath = rDir + CustomShapesFile;
                     if (File.Exists(tempPath))
                     {
                         compiledRuleFunctions = tempPath;
                     }
                 }
                 var relRuleSets = DefaultRuleSets.Split(',');
                 for (var i = 0; i < relRuleSets.GetLength(0); i++)
                 {
                     if (!string.IsNullOrWhiteSpace(relRuleSets[i]) && !relRuleSets[i].StartsWith(".." + DS))
                     {
                         tempPath = rDir + relRuleSets[i];
                         if (File.Exists(tempPath))
                         {
                             defaultRSFileNames[i] = tempPath;
                         }
                     }
                 }
             }
         }
         if (!SearchDir.StartsWith(".." + DS))
         {
             tempPath = newWDirAbs + SearchDir;
             if (Directory.Exists(tempPath))
             {
                 sDir = tempPath;
             }
         }
         if (!GraphLayoutDir.StartsWith(".." + DS))
         {
             tempPath = newWDirAbs + GraphLayoutDir;
             if (Directory.Exists(tempPath))
             {
                 glDir = tempPath;
             }
         }
         if (!CustomShapesFile.StartsWith(".." + DS))
         {
             tempPath = newWDirAbs + CustomShapesFile;
             if (File.Exists(tempPath))
             {
                 customShapesFile = tempPath;
             }
         }
     }
     catch (Exception exc)
     {
         ErrorLogger.Catch(exc);
     }
 }
Beispiel #13
0
    private void UpdateWalkPos(int x, int y)
    {
        int ydir = 0;
        int xdir = 0;

        if (movePref == InputDir.w)
        {
            ydir = 1;
        }
        if (movePref == InputDir.s)
        {
            ydir = -1;
        }
        if (movePref == InputDir.a)
        {
            xdir = 1;
        }
        if (movePref == InputDir.d)
        {
            xdir = -1;
        }
        side = GetTileForDirection(xdir, ydir);

        int switchPosNeg = 1;

        if (side == tiles1)
        {
            switchPosNeg = -1;
        }
        else
        {
            switchPosNeg = 1;
        }

        if (movePref == InputDir.w && side[tileX, tileY - switchPosNeg] == 0)
        {
            moveDir = InputDir.w;
        }
        if (movePref == InputDir.s && side[tileX, tileY + switchPosNeg] == 0)
        {
            moveDir = InputDir.s;
        }
        if (movePref == InputDir.a && side[tileX + 1, tileY] == 0)
        {
            moveDir = InputDir.a;
        }
        if (movePref == InputDir.d && side[tileX - 1, tileY] == 0)
        {
            moveDir = InputDir.d;
        }

        if (moveDir == InputDir.w && side[tileX, tileY - switchPosNeg] == 0)
        {
            tileY    -= switchPosNeg;
            pacmanRot = Vector3.zero;
        }
        if (moveDir == InputDir.s && side[tileX, tileY + switchPosNeg] == 0)
        {
            tileY    += switchPosNeg;
            pacmanRot = Vector3.down * 2;
        }
        if (moveDir == InputDir.a && side[tileX + 1, tileY] == 0)
        {
            tileX    += x;
            pacmanRot = Vector3.down;
        }
        if (moveDir == InputDir.d && side[tileX - 1, tileY] == 0)
        {
            tileX    -= x;
            pacmanRot = Vector3.up;
        }
    }
        protected void ChangeInputDirection(InputDir direction)
        {
            if (S_Editor.SelectorType != SelectorType.Grid)
            {
                if (direction == InputDir.Left || direction == InputDir.Down)
                {
                    SelectNextItem(false);                                                                //Change to Previous item
                }
                if (direction == InputDir.Right || direction == InputDir.Up)
                {
                    SelectNextItem(true);                                                                 //Change to Next item
                }
            }
            else
            {
                #region GRID Selection
                int NextItemIndex = IndexSelected;

                int CurrentRow = IndexSelected / S_Editor.Grid;


                if (direction == InputDir.Left)                                        //Change Left
                {
                    NextItemIndex--;

                    NextItemIndex = (NextItemIndex % S_Editor.Grid) + (CurrentRow * S_Editor.Grid);

                    if (NextItemIndex >= Items.Count)
                    {
                        NextItemIndex = Items.Count - 1;
                    }
                    if (NextItemIndex < 0)
                    {
                        NextItemIndex = S_Editor.Grid - 1;
                    }
                }
                else if (direction == InputDir.Right)                                  //Change Right
                {
                    NextItemIndex++;

                    if (NextItemIndex == Items.Count)
                    {
                        NextItemIndex = GridTotal;
                    }

                    NextItemIndex = NextItemIndex % S_Editor.Grid + (CurrentRow * S_Editor.Grid);
                }
                else if (direction == InputDir.Up)                                     //Change UP
                {
                    NextItemIndex += S_Editor.Grid;

                    if (NextItemIndex >= Items.Count)
                    {
                        NextItemIndex = NextItemIndex % S_Editor.Grid;
                    }
                }
                else if (direction == InputDir.Down)
                {
                    NextItemIndex -= S_Editor.Grid;

                    if (NextItemIndex < 0)
                    {
                        if (GridTotal + NextItemIndex >= Items.Count)
                        {
                            NextItemIndex -= S_Editor.Grid;
                        }
                        NextItemIndex = GridTotal + NextItemIndex;
                    }
                }
                SelectNextItem(NextItemIndex);        //Change to Previous item
                #endregion
            }
        }
Beispiel #15
0
 public override int GetHashCode()
 {
     return(InputDir.GetHashCode() ^ OutputDir.GetHashCode());
 }
Beispiel #16
0
 public void method_22(InputDir inputDir_0)
 {
     this.method_43((byte)inputDir_0);
 }
Beispiel #17
0
    /// <summary>
    /// Translates input into an action target such as a movement destination.
    /// </summary>
    /// <param name="input">The InpurDir object from the current frame.</param>
    private void SetInputTarget(InputDir input)
    {
        // If we've arrived at a movement target and no input is being given,
        // force our state to idle
        if (playerArrived && input == InputDir.NONE)
        {
            state = PlayerState.IDLE;
            return;
        }

        if ((state == PlayerState.IDLE || playerArrived) &&
            !levelChanger.InputLocked)
        {
            // Handle direction change
            if (input.HasFlag(InputDir.LEFT))
            {
                if (faceDirection == PlayerDirection.LEFT)
                {
                    sameDirectionFrameCount++;
                }
                else
                {
                    sameDirectionFrameCount = 0;
                    faceDirection           = PlayerDirection.LEFT;
                }
            }
            else if (input.HasFlag(InputDir.RIGHT))
            {
                if (faceDirection == PlayerDirection.RIGHT)
                {
                    sameDirectionFrameCount++;
                }
                else
                {
                    sameDirectionFrameCount = 0;
                    faceDirection           = PlayerDirection.RIGHT;
                }
            }
            else if (input.HasFlag(InputDir.UP))
            {
                if (faceDirection == PlayerDirection.UP)
                {
                    sameDirectionFrameCount++;
                }
                else
                {
                    sameDirectionFrameCount = 0;
                    faceDirection           = PlayerDirection.UP;
                }
            }
            else if (input.HasFlag(InputDir.DOWN))
            {
                if (faceDirection == PlayerDirection.DOWN)
                {
                    sameDirectionFrameCount++;
                }
                else
                {
                    sameDirectionFrameCount = 0;
                    faceDirection           = PlayerDirection.DOWN;
                }
            }

            // Prevent any kind of crazy overflow nonsense
            sameDirectionFrameCount = Mathf.Clamp(sameDirectionFrameCount, 0, 1024);

            // Move if we're able
            if (sameDirectionFrameCount >= moveFrameDelay || (playerArrived && state == PlayerState.MOVING))
            {
                Vector3 potentialMovementTarget = transform.position;

                if (input.HasFlag(InputDir.LEFT))
                {
                    potentialMovementTarget = grid.CellToWorld(new Vector3Int(cellPos.x - 1, cellPos.y, cellPos.z)) + cellOffset;
                }
                else if (input.HasFlag(InputDir.RIGHT))
                {
                    potentialMovementTarget = grid.CellToWorld(new Vector3Int(cellPos.x + 1, cellPos.y, cellPos.z)) + cellOffset;
                }
                else if (input.HasFlag(InputDir.UP))
                {
                    potentialMovementTarget = grid.CellToWorld(new Vector3Int(cellPos.x, cellPos.y + 1, cellPos.z)) + cellOffset;
                }
                else if (input.HasFlag(InputDir.DOWN))
                {
                    potentialMovementTarget = grid.CellToWorld(new Vector3Int(cellPos.x, cellPos.y - 1, cellPos.z)) + cellOffset;
                }

                // Check we're not trying to move into a collidable cell
                if (!tilemapCollider.OverlapPoint(potentialMovementTarget) &&
                    potentialMovementTarget != transform.position)
                {
                    movementTarget = potentialMovementTarget;
                    movementOrigin = transform.position;
                    state          = PlayerState.MOVING;
                    playerArrived  = false;
                }
                else
                {
                    // Moving into a collidable should still be animated as
                    // walking on the spot
                    state = PlayerState.KABEDON;
                }
            }
        }
    }