예제 #1
0
        /// <summary>
        ///     Porusza graczem uwzględniając możliwe kierunki ruchu zawarte w parametrze wejściowym.
        /// </summary>
        /// <param name="moves">Poprawne kierunki ruchu.</param>
        protected virtual void Move(byte moves)
        {
            if (ActualRows.Count != 0)
            {
                ActualRows.Clear();
            }

            if (ActualColumns.Count != 0)
            {
                ActualColumns.Clear();
            }

            if (Keyboard.IsKeyDown(Key.Left) && (moves & Left) == Left)
            {
                X -= _speed;
            }

            else if (Keyboard.IsKeyDown(Key.Right) && (moves & Right) == Right)
            {
                X += _speed;
            }

            else if (Keyboard.IsKeyDown(Key.Up) && (moves & Up) == Up)
            {
                Y -= _speed;
            }

            else if (Keyboard.IsKeyDown(Key.Down) && (moves & Down) == Down)
            {
                Y += _speed;
            }

            ActualRows.Add((int)(Y / TileSize));
            if ((int)((Y + ObjectSize) / TileSize) != ActualRows.FirstOrDefault())
            {
                ActualRows.Add((int)((Y + ObjectSize) / TileSize));
            }

            ActualColumns.Add((int)(X / TileSize));
            if ((int)((X + ObjectSize) / TileSize) != ActualColumns.FirstOrDefault())
            {
                ActualColumns.Add((int)((X + ObjectSize) / TileSize));
            }
        }
예제 #2
0
        /// <summary>
        ///     Wykonuje ruch wroga biorąc pod uwagę dostępne aktualnie ruchy.
        /// </summary>
        /// <param name="moves">Dostępne aktualnie kierunki ruchów.</param>
        protected virtual void Move(byte moves)
        {
            if (ActualRows.Count != 0)
            {
                ActualRows.Clear();
            }

            if (ActualColumns.Count != 0)
            {
                ActualColumns.Clear();
            }

            if ((moves & _direction) == _direction)
            {
                switch (_direction)
                {
                case Right:
                    if ((moves & Right) == Right)
                    {
                        X += 1;
                    }
                    break;

                case Left:
                    if ((moves & Left) == Left)
                    {
                        X -= 1;
                    }
                    break;

                case Up:
                    if ((moves & Up) == Up)
                    {
                        Y -= 1;
                    }
                    break;

                case Down:
                    if ((moves & Down) == Down)
                    {
                        Y += 1;
                    }
                    break;
                }
            }
            else
            {
                var direction = StaticRandom.Rand.Next() % 4;
                switch (direction)
                {
                case 0:
                    _direction = Right;
                    break;

                case 1:
                    _direction = Left;
                    break;

                case 2:
                    _direction = Up;
                    break;

                case 3:
                    _direction = Down;
                    break;
                }
            }

            ActualRows.Add((int)(Y / TileSize));
            if ((int)((Y + ObjectSize) / TileSize) != ActualRows.FirstOrDefault())
            {
                ActualRows.Add((int)((Y + ObjectSize) / TileSize));
            }

            ActualColumns.Add((int)(X / TileSize));
            if ((int)((X + ObjectSize) / TileSize) != ActualColumns.FirstOrDefault())
            {
                ActualColumns.Add((int)((X + ObjectSize) / TileSize));
            }
        }