Exemplo n.º 1
0
    public void Move()
    {
        if (animator != null)
        {
            animator.SetInteger("State", 0);
        }
        Isle_Behaviour target_field;
        int            general_direction;
        int            src_x;
        int            src_y;
        Isle_Behaviour temp;


        if (isReturning)
        {
            src_x = initial_position.field.x;
            src_y = initial_position.field.y;
        }
        else
        {
            src_x = player_position.field.x;
            src_y = player_position.field.y;
        }
        general_direction = 1 * Sign(src_x - coord_x) + 3 * Sign((coord_y - src_y));
        if (src_x != coord_x || src_y != coord_y)
        {
            //Debug.Log("General direction " + general_direction + " src x y " + src_x + " " +src_y + " cordx cordy " + coord_x + " " + coord_y );
            if (general_direction > 0)
            {
                if (general_direction > 2)
                {
                    if (general_direction == 4)
                    {
                        //prawo
                        temp = map_generator.FindFieldOfXandY(coord_x + 1, coord_y);
                        if (isFieldAvaible(temp))
                        {
                            MoveFromTo(current_position.gameObject, temp.gameObject);
                        }
                        else
                        {
                            //góra
                            temp = map_generator.FindFieldOfXandY(coord_x, coord_y - 1);
                            if (isFieldAvaible(temp))
                            {
                                MoveFromTo(current_position.gameObject, temp.gameObject);
                            }
                        }
                    }
                    //general dir == 3
                    else
                    {
                        //góra
                        temp = map_generator.FindFieldOfXandY(coord_x, coord_y - 1);
                        if (isFieldAvaible(temp))
                        {
                            MoveFromTo(current_position.gameObject, temp.gameObject);
                        }
                    }
                }
                else
                {
                    if (general_direction == 2)
                    {
                        // lewo
                        temp = map_generator.FindFieldOfXandY(coord_x - 1, coord_y);
                        if (isFieldAvaible(temp))
                        {
                            MoveFromTo(current_position.gameObject, temp.gameObject);
                        }
                        else
                        {
                            //gora
                            temp = map_generator.FindFieldOfXandY(coord_x, coord_y - 1);
                            if (isFieldAvaible(temp))
                            {
                                MoveFromTo(current_position.gameObject, temp.gameObject);
                            }
                        }
                    }

                    //general dir == 1
                    else
                    {
                        //prawo
                        temp = map_generator.FindFieldOfXandY(coord_x + 1, coord_y);
                        if (isFieldAvaible(temp))
                        {
                            MoveFromTo(current_position.gameObject, temp.gameObject);
                        }
                    }
                }
            }
            else
            {
                if (general_direction < -2)
                {
                    if (general_direction == -4)
                    {
                        //lewo
                        temp = map_generator.FindFieldOfXandY(coord_x - 1, coord_y);
                        if (isFieldAvaible(temp))
                        {
                            MoveFromTo(current_position.gameObject, temp.gameObject);
                        }
                        else
                        {
                            //dół
                            temp = map_generator.FindFieldOfXandY(coord_x, coord_y + 1);
                            if (isFieldAvaible(temp))
                            {
                                MoveFromTo(current_position.gameObject, temp.gameObject);
                            }
                        }
                    }
                    //general dir == -3
                    else
                    {
                        //dół
                        temp = map_generator.FindFieldOfXandY(coord_x, coord_y + 1);
                        if (isFieldAvaible(temp))
                        {
                            MoveFromTo(current_position.gameObject, temp.gameObject);
                        }
                    }
                }
                else
                {
                    if (general_direction == -2)
                    {
                        //prawo
                        temp = map_generator.FindFieldOfXandY(coord_x + 1, coord_y);
                        if (isFieldAvaible(temp))
                        {
                            MoveFromTo(current_position.gameObject, temp.gameObject);
                        }
                        else
                        {
                            //dół
                            temp = map_generator.FindFieldOfXandY(coord_x, coord_y + 1);
                            if (isFieldAvaible(temp))
                            {
                                MoveFromTo(current_position.gameObject, temp.gameObject);
                            }
                        }
                    }
                    //general dir == -1
                    else
                    {
                        //lewo
                        temp = map_generator.FindFieldOfXandY(coord_x - 1, coord_y);
                        if (isFieldAvaible(temp))
                        {
                            MoveFromTo(current_position.gameObject, temp.gameObject);
                        }
                    }
                }
            }
        }
    }