Example #1
0
 /// <summary>
 /// Method to reset player properties.
 /// </summary>
 /// <param name="direction">Initial player direction.</param>
 /// <param name="row">Initial player row.</param>
 /// <param name="col">Initial player column.</param>
 public virtual void Reset(PlayerDirections direction, int row, int col)
 {
     // Reset player properties
     Direction = direction;
     Row       = row;
     Column    = col;
 }
Example #2
0
 /// <summary>
 /// Player Constructor to initiliase player properties
 /// </summary>
 /// <param name="direction">Initial player direction.</param>
 /// <param name="column">Initial player column.</param>
 /// <param name="row">Initial player row.</param>
 public Player(PlayerDirections direction, int column, int row)
 {
     // Initialise player properties
     Direction = direction;
     Column    = column;
     Row       = row;
     Score     = 0;
 }
Example #3
0
    void SetRotation(float horizontal, float vertical)
    {
        float angle = 0.0f;

        if (horizontal > 0.0f)
        {
            if (vertical > 0.0f)
            {
                direction = PlayerDirections.NE;
                angle     = -45.0f;
            }
            else if (vertical < 0.0f)
            {
                direction = PlayerDirections.SE;
                angle     = -135.0f;
            }
            else
            {
                direction = PlayerDirections.E;
                angle     = -90.0f;
            }
        }
        else if (horizontal < 0.0f)
        {
            if (vertical > 0.0f)
            {
                direction = PlayerDirections.NW;
                angle     = 45.0f;
            }
            else if (vertical < 0.0f)
            {
                direction = PlayerDirections.SW;
                angle     = 135.0f;
            }
            else
            {
                direction = PlayerDirections.W;
                angle     = 90.0f;
            }
        }
        else
        {
            if (vertical > 0.0f)
            {
                direction = PlayerDirections.N;
                angle     = 0.0f;
            }
            else if (vertical < 0.0f)
            {
                direction = PlayerDirections.S;
                angle     = 180.0f;
            }
        }

        transform.rotation = Quaternion.Euler(0.0f, 0.0f, angle);
    }
Example #4
0
 private void Respawn()
 {
     move       = false;
     sr.enabled = false;
     Debug.Log("Respawn");
     transform.position          = spawnPosition;
     GameManager.i.simulationRun = false;
     direction = originalDirection;
     GameManager.i.RestartSimulation();
 }
Example #5
0
 private void Awake()
 {
     rb                              = GetComponent <Rigidbody2D>();
     stats                           = GetComponent <PlayerStats>();
     sr                              = GetComponent <SpriteRenderer>();
     spawnPosition                   = transform.position;
     originalDirection               = direction;
     Game_UI.onPlayButtonClicked    += Game_UI_onPlayButtonClicked;
     Game_UI.onRestartButtonClicked += Respawn;
     sr.enabled                      = false;
     Flag.onFlagEntered             += Flag_onFlagEntered;
 }
Example #6
0
 /// <summary>
 /// Method that sets a random direction according to a certain probability.
 /// </summary>
 /// <param name="dir1">One of the possible Directions.</param>
 /// <param name="dir2">Other Direction.</param>
 private void SetRandomDirection(PlayerDirections dir1, PlayerDirections dir2)
 {
     // Probability to change direction is 5% for each direction
     if (rnd.NextDouble() <= 0.05f)
     {
         Direction = dir1;
     }
     else if (rnd.NextDouble() <= 0.05f)
     {
         Direction = dir2;
     }
 }
Example #7
0
    private void MovementBlock_onSpriteChangedLeft()
    {
        int index = (int)direction;

        if ((int)direction < 1)
        {
            index = Enum.GetValues(typeof(PlayerDirections)).Length - 1;
        }
        else
        {
            index--;
        }
        direction = (PlayerDirections)index;
        SetSprite();
    }
Example #8
0
    public void MoveTo(Vector2 destination)
    {
        this.destination = destination;

        if (destination.x < transform.position.x)
        {
            Facing = PlayerDirections.Left;
        }
        else if (destination.x > transform.position.y)
        {
            Facing = PlayerDirections.Right;
        }

        Moving = true;
    }
Example #9
0
        public AI(bool[,] gameWorld, int xDim, int yDim, PlayerDirections direction, int column, int row)
            : base(direction, column, row)
        {
            /// Initialise references to world and x and y sizes
            this.xDim      = xDim;
            this.yDim      = yDim;
            this.gameWorld = gameWorld;

            // Array positions corresponding to the verification array
            // isStepped[0] = up left
            // isStepped[1] = left
            // isStepped[2] = down left
            // isStepped[3] = up
            // isStepped[4] = AI player position
            // isStepped[5] = down
            // isStepped[6] = up right
            // isStepped[7] = right
            // isStepped[8] = down right
            isStepped = new bool[9];
        }
Example #10
0
    void CoordsInDirection(int x, int y, PlayerDirections dir, out int newX, out int newY)
    {
        newX = x;
        newY = y;

        switch (dir)
        {
        case PlayerDirections.N: newY--; break;

        case PlayerDirections.NE: newX++;  newY--; break;

        case PlayerDirections.E: newX++; break;

        case PlayerDirections.SE: newX++;  newY++; break;

        case PlayerDirections.S: newY++; break;

        case PlayerDirections.SW: newX--;  newY++; break;

        case PlayerDirections.W: newX--; break;

        case PlayerDirections.NW: newX--; newY--; break;
        }
    }
        public static Position GetThePlayersBarNewPosition(PlayerDirections direction)
        {
            int index = (int)direction;

            return(AvailablePositions[index]);
        }
Example #12
0
 public void SetAvailableDirection(PlayerDirections direction)
 {
     if (!directionsAvailable.Contains(direction))
         directionsAvailable.Add(direction);
 }
Example #13
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(values[0] is TileType))
            {
                throw new Exception("First Binding must be of type TileType");
            }
            if (!(values[1] is bool))
            {
                throw new Exception("Second Binding must be of type bool");
            }
            if (!(values[2] is bool))
            {
                throw new Exception("Third Binding must be of type bool");
            }
            if (!(values[3] is PlayerDirections))
            {
                throw new Exception("Fourth Binding must be of type playerDirecion");
            }
            if (values.Length > 4)
            {
                throw new Exception("too many bindings.");
            }

            TileType         chosenType   = (TileType)values[0];
            bool             isPlayerHere = (bool)values[1];
            bool             visible      = (bool)values[2];
            PlayerDirections playerFacing = (PlayerDirections)values[3];

            BitmapImage ImageSource = new BitmapImage();

            if (!visible)
            {
                ImageSource.BeginInit();
                ImageSource.UriSource = new Uri("Resources/FogTile_25x25.png", UriKind.Relative);
                ImageSource.EndInit();
            }
            else if (chosenType == TileType.closed)
            {
                ImageSource.BeginInit();
                ImageSource.UriSource = new Uri("Resources/ClosedTile_25x25.png", UriKind.Relative);
                ImageSource.EndInit();
            }
            else if (chosenType == TileType.decoration)
            {
                ImageSource.BeginInit();
                ImageSource.UriSource = new Uri("Resources/box.png", UriKind.Relative);
                ImageSource.EndInit();
            }
            else if (chosenType == TileType.counter)
            {
                Random rGen = new Random();

                ImageSource.BeginInit();
                switch (rGen.Next(1, 5))
                {
                case 1:
                    ImageSource.UriSource = new Uri("Resources/CounterTop.png", UriKind.Relative);
                    break;

                case 2:
                    ImageSource.UriSource = new Uri("Resources/CounterTop_1.png", UriKind.Relative);
                    break;

                case 3:
                    ImageSource.UriSource = new Uri("Resources/CounterTop_2.png", UriKind.Relative);
                    break;

                case 4:
                    ImageSource.UriSource = new Uri("Resources/CounterTop_3.png", UriKind.Relative);
                    break;
                }
                ImageSource.EndInit();
            }
            else if (chosenType == TileType.decoration)
            {
                ImageSource.BeginInit();
                ImageSource.UriSource = new Uri("Resources/box.png", UriKind.Relative);
                ImageSource.EndInit();
            }
            else if (chosenType == TileType.counter)
            {
                Random rGen = new Random();

                ImageSource.BeginInit();
                switch (rGen.Next(1, 5))
                {
                case 1:
                    ImageSource.UriSource = new Uri("Resources/CounterTop.png", UriKind.Relative);
                    break;

                case 2:
                    ImageSource.UriSource = new Uri("Resources/CounterTop_1.png", UriKind.Relative);
                    break;

                case 3:
                    ImageSource.UriSource = new Uri("Resources/CounterTop_2.png", UriKind.Relative);
                    break;

                case 4:
                    ImageSource.UriSource = new Uri("Resources/CounterTop_3.png", UriKind.Relative);
                    break;
                }
                ImageSource.EndInit();
            }
            else if (chosenType == TileType.end)
            {
                ImageSource.BeginInit();
                ImageSource.UriSource = new Uri("Resources/EndTile_25x25.png", UriKind.Relative);
                ImageSource.EndInit();
            }
            else if (chosenType == TileType.monster)
            {
                ImageSource.BeginInit();

                if (isPlayerHere)
                {
                    if (playerFacing == PlayerDirections.North)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_north.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.East)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_east.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.South)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_south.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.West)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_west.png", UriKind.Relative);
                    }
                }
                else
                {
                    ImageSource.UriSource = new Uri("Resources/MonsterTile_25x25.png", UriKind.Relative);
                }

                ImageSource.EndInit();
            }
            else if (chosenType == TileType.trap)
            {
                ImageSource.BeginInit();

                if (isPlayerHere)
                {
                    if (playerFacing == PlayerDirections.North)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_north.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.East)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_east.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.South)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_south.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.West)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_west.png", UriKind.Relative);
                    }
                }
                else
                {
                    ImageSource.UriSource = new Uri("Resources/OpenTile_25x25.png", UriKind.Relative);
                }

                ImageSource.EndInit();
            }
            else if (chosenType == TileType.triggeredTrap)
            {
                ImageSource.BeginInit();

                if (isPlayerHere)
                {
                    if (playerFacing == PlayerDirections.North)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_north_trap.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.East)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_east_trap.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.South)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_south_trap.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.West)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_west_trap.png", UriKind.Relative);
                    }
                }
                else
                {
                    ImageSource.UriSource = new Uri("Resources/TrapTile_25x25.png", UriKind.Relative);
                }

                ImageSource.EndInit();
            }
            else if (chosenType == TileType.open)
            {
                ImageSource.BeginInit();

                if (isPlayerHere)
                {
                    if (playerFacing == PlayerDirections.North)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_north.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.East)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_east.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.South)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_south.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.West)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_west.png", UriKind.Relative);
                    }
                }
                else
                {
                    ImageSource.UriSource = new Uri("Resources/OpenTile_25x25.png", UriKind.Relative);
                }

                ImageSource.EndInit();
            }
            else if (chosenType == TileType.start)
            {
                ImageSource.BeginInit();

                if (isPlayerHere)
                {
                    if (playerFacing == PlayerDirections.North)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_north.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.East)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_east.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.South)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_south.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.West)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_west.png", UriKind.Relative);
                    }
                }
                else
                {
                    ImageSource.UriSource = new Uri("Resources/OpenTile_25x25.png", UriKind.Relative);
                }

                ImageSource.EndInit();
            }
            else if (chosenType == TileType.store)
            {
                ImageSource.BeginInit();

                if (isPlayerHere)
                {
                    if (playerFacing == PlayerDirections.North)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_north.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.East)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_east.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.South)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_south.png", UriKind.Relative);
                    }
                    else if (playerFacing == PlayerDirections.West)
                    {
                        ImageSource.UriSource = new Uri("Resources/Player_west.png", UriKind.Relative);
                    }
                }
                else
                {
                    ImageSource.UriSource = new Uri("Resources/OpenTile_25x25.png", UriKind.Relative);
                }

                ImageSource.EndInit();
            }
            else if (chosenType == TileType.npc)
            {
                ImageSource.BeginInit();


                ImageSource.UriSource = new Uri("Resources/Shopkeeper_25x25.png", UriKind.Relative);

                ImageSource.EndInit();
            }
            else
            {
                ImageSource.BeginInit();
                ImageSource.UriSource = new Uri("Resources/ErrorTile.jpg", UriKind.Relative);
                ImageSource.EndInit();
            }

            ImageBrush boolImageBrush = new ImageBrush(ImageSource);

            return(boolImageBrush);
        }
Example #14
0
 /// <summary>
 /// Override the Reset Method from the player to be able to reset the
 /// isStepped array.
 /// </summary>
 /// <param name="direction">Initial player direction.</param>
 /// <param name="row">Initial player row.</param>
 /// <param name="col">Initial player column.</param>
 public override void Reset(PlayerDirections direction, int row, int col)
 {
     base.Reset(direction, row, col);
     ResetCheckArray();
 }
Example #15
0
 private void UpdateDirection()
 {
     direction = (PlayerDirections)directionIndex;
     FindSprite();
 }
Example #16
0
 public Player2D MoveEmulate(PlayerDirections direction)
 {
     Player2D t = new Player2D(this);
     t.Move(direction);
     t.AnimatedTexture.Update(null);
     return t;
 }
    public void Shoot(PlayerDirections direction)
    {
        if (!IsReady)
        {
            return;
        }
        _currentCooldown = _cooldown;

        var inputVector = Vector2.zero;

        switch (direction)
        {
        case PlayerDirections.None:
            return;

        case PlayerDirections.Up:
            ApplyUp();
            break;

        case PlayerDirections.Down:
            ApplyDown();
            break;

        case PlayerDirections.Left:
            ApplyLeft();
            break;

        case PlayerDirections.Right:
            ApplyRight();
            break;

        case PlayerDirections.UpLeft:
            ApplyUp();
            ApplyLeft();
            break;

        case PlayerDirections.UpRight:
            ApplyUp();
            ApplyRight();
            break;

        case PlayerDirections.DownLeft:
            ApplyDown();
            ApplyLeft();
            break;

        case PlayerDirections.DownRight:
            ApplyDown();
            ApplyRight();
            break;
        }
        var transformCache = transform;

        LookAt2d(inputVector);
        var bla = Instantiate(_bulletPrefab, transformCache.position, transformCache.rotation);

        void ApplyRight() => inputVector.x = 1;
        void ApplyLeft() => inputVector.x = -1;
        void ApplyDown() => inputVector.y = -1;
        void ApplyUp() => inputVector.y = 1;
    }
Example #18
0
 public void SwitchDirection(PlayerDirections direction)
 {
     this.direction = direction;
 }
    // Update is called once per frame
    private void Update()
    {
        if (Input.GetKey(_moveUpKey) && !Input.GetKey(_moveDownKey))
        {
            _moveDirections |= PlayerDirections.Up;
        }
        else
        {
            _moveDirections &= ~PlayerDirections.Up;
        }

        if (Input.GetKey(_moveDownKey) && !Input.GetKey(_moveUpKey))
        {
            _moveDirections |= PlayerDirections.Down;
        }
        else
        {
            _moveDirections &= ~PlayerDirections.Down;
        }

        if (Input.GetKey(_moveLeftKey) && !Input.GetKey(_moveRightKey))
        {
            _moveDirections |= PlayerDirections.Left;
        }
        else
        {
            _moveDirections &= ~PlayerDirections.Left;
        }

        if (Input.GetKey(_moveRightKey) && !Input.GetKey(_moveLeftKey))
        {
            _moveDirections |= PlayerDirections.Right;
        }
        else
        {
            _moveDirections &= ~PlayerDirections.Right;
        }

        if (Input.GetKey(_shootUpKey) && !Input.GetKey(_shootDownKey))
        {
            _shootDirections |= PlayerDirections.Up;
        }
        else
        {
            _shootDirections &= ~PlayerDirections.Up;
        }

        if (Input.GetKey(_shootDownKey) && !Input.GetKey(_shootUpKey))
        {
            _shootDirections |= PlayerDirections.Down;
        }
        else
        {
            _shootDirections &= ~PlayerDirections.Down;
        }

        if (Input.GetKey(_shootLeftKey) && !Input.GetKey(_shootRightKey))
        {
            _shootDirections |= PlayerDirections.Left;
        }
        else
        {
            _shootDirections &= ~PlayerDirections.Left;
        }

        if (Input.GetKey(_shootRightKey) && !Input.GetKey(_shootLeftKey))
        {
            _shootDirections |= PlayerDirections.Right;
        }
        else
        {
            _shootDirections &= ~PlayerDirections.Right;
        }
    }
Example #20
0
        public void Move(PlayerDirections direction)
        {
            this.direction = direction;

            switch (direction)
            {
                case PlayerDirections.Up:
                {
                    if (!directionsAvailable.Contains(PlayerDirections.Up))
                        break;

                    if (EnableAnimation)
                    {
                        AnimatedTexture.SetRegion("up");
                        AnimatedTexture.IncrementFrame();
                    }
                    if (EnableMovement) AnimatedTexture.Position = new Vector2(AnimatedTexture.Position.X, AnimatedTexture.Position.Y - 10);
                    break;
                }
                case PlayerDirections.Down:
                {
                    if (!directionsAvailable.Contains(PlayerDirections.Down))
                        break;

                    if (EnableAnimation)
                    {
                        AnimatedTexture.SetRegion("down");
                        AnimatedTexture.IncrementFrame();
                    }
                    if (EnableMovement) AnimatedTexture.Position = new Vector2(AnimatedTexture.Position.X, AnimatedTexture.Position.Y + 10);
                    break;
                }
                case PlayerDirections.Left:
                {
                    if (!directionsAvailable.Contains(PlayerDirections.Left))
                        break;

                    if (EnableAnimation)
                    {
                        AnimatedTexture.SetRegion("left");
                        AnimatedTexture.IncrementFrame();
                    }
                    if (EnableMovement) AnimatedTexture.Position = new Vector2(AnimatedTexture.Position.X - 10, AnimatedTexture.Position.Y);
                    break;
                }
                case PlayerDirections.Right:
                {
                    if (!directionsAvailable.Contains(PlayerDirections.Right))
                        break;

                    if (EnableAnimation)
                    {
                        AnimatedTexture.SetRegion("right");
                        AnimatedTexture.IncrementFrame();
                    }
                    if (EnableMovement) AnimatedTexture.Position = new Vector2(AnimatedTexture.Position.X + 10, AnimatedTexture.Position.Y);
                    break;
                }
            }
        }