Ejemplo n.º 1
0
 public void Initiate(Isle_Behaviour initial_position)
 {
     this.initial_position = initial_position;
     current_position      = initial_position;
     coord_x = current_position.field.x;
     coord_y = current_position.field.y;
     onLocationChange(current_position.gameObject);
     //UpdatePlayerPosition();
     isInitiated = true;
 }
Ejemplo n.º 2
0
 public bool isFieldAvaible(Isle_Behaviour target_field)
 {
     if (target_field.field.evaluate() == 1 && target_field.isPassable && target_field != player_position)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
    public void onLocationChange(GameObject new_location)
    {
        current_position = new_location.GetComponent <Isle_Behaviour>();
        GameObject location = current_position.gameObject;

        coord_x = current_position.field.x;
        coord_y = current_position.field.y;
        new_location.GetComponent <Enemy_Container>().occupation  = this;
        new_location.GetComponent <Enemy_Container>().isOccupated = true;
        transform.position = new Vector3(location.transform.position.x, location.transform.position.y, -1);
        transform.SetParent(new_location.transform);
    }
Ejemplo n.º 4
0
    public void setGoal(Field field)
    {
        int        x          = field.x;
        int        y          = field.y;
        GameObject randomTile = map_array[x, y].gameObject;
        GameObject goal_field = Instantiate(goal);

        goal_field.transform.position = randomTile.transform.position;
        randomTile.SetActive(false);
        goal_field.GetComponent <Isle_Behaviour>().field = new Goal_Behaviour(x, y);
        map_array[x, y] = goal_field.GetComponent <Isle_Behaviour>();
        goal_tile       = map_array[x, y];
    }
Ejemplo n.º 5
0
    public Isle_Behaviour GetUnoccupiedField()
    {
        Isle_Behaviour isle = map_array[Random.Range(0, map_Width), Random.Range(0, map_Height)];

        if (isle.isPassable && isle.field.evaluate() != 2 && isle.field.evaluate() != 10)
        {
            return(isle);
        }
        else
        {
            return(GetUnoccupiedField());
        }
    }
Ejemplo n.º 6
0
    // Update is called once per frame
    public void Cycle()
    {
        location           = player.location.GetComponent <Isle_Behaviour>();
        goal               = game.map_generator.goal_tile;
        transform.rotation = Quaternion.Euler(0, 0, 0);
        if (location != null && goal != null)
        {
            //Debug.Log(location.field.x + " + " + location.field.y + " | " + goal.field.x + " + " + goal.field.y);
            Vector2 location_vector = new Vector2(location.field.x, -location.field.y);
            Vector2 goal_vector     = new Vector2(goal.field.x, -goal.field.y);
            Vector2 true_vector     = new Vector2(goal.gameObject.transform.position.x, 0);

            if (goal.field.x - location.field.x != 0 && goal.field.y - location.field.y != 0)
            {
                if (goal.field.x - location.field.x > 0)
                {
                    //transform.rotation = Quaternion.identity * Quaternion.Euler(new Vector3(0, 0, Mathf.Pow(Mathf.Tan((goal_vector.y - location_vector.y) / (goal_vector.x - location_vector.x)), -1) * Mathf.Rad2Deg + 270));
                    transform.Rotate(new Vector3(0, 0, (Mathf.Atan2((goal_vector.y - location_vector.y), (goal_vector.x - location_vector.x)) * Mathf.Rad2Deg - 90)));
                }
                else
                {
                    //transform.rotation = Quaternion.identity * Quaternion.Euler(new Vector3(0, 0, -Mathf.Pow(Mathf.Tan((goal_vector.y - location_vector.y) / (goal_vector.x - location_vector.x)), -1) * Mathf.Rad2Deg + 90));
                    transform.Rotate(new Vector3(0, 0, (Mathf.Atan2((goal_vector.y - location_vector.y), (goal_vector.x - location_vector.x)) * Mathf.Rad2Deg - 90)));
                }
            }

            else if (goal.field.x - location.field.x == 0)
            {
                if (goal.field.y - location.field.y > 0)
                {
                    transform.rotation = Quaternion.Euler(0, 0, 180);
                }
                else
                {
                    transform.rotation = Quaternion.Euler(0, 0, 0);
                }
            }
            else if (goal.field.y - location.field.y == 0)
            {
                if (goal.field.x - location.field.x > 0)
                {
                    transform.rotation = Quaternion.Euler(0, 0, -90);
                }
                else
                {
                    transform.rotation = Quaternion.Euler(0, 0, 90);
                }
            }
        }
    }
Ejemplo n.º 7
0
 public void DeleteMap()
 {
     for (int i = 0; i < map_Width; i++)
     {
         for (int j = 0; j < map_Height; j++)
         {
             // Debug.Log(i + " " + j);
             map_array[i, j].gameObject.SetActive(false);
             map_array[i, j] = null;
         }
     }
     goal_tile = null;
     foreach (Enemy_Behaviour enemy in enemies)
     {
         if (enemy != null)
         {
             Destroy(enemy.gameObject);
         }
     }
     enemies.Clear();
 }
Ejemplo n.º 8
0
    public bool[] deepWaterNeighbours(Isle_Behaviour isle)
    {
        bool[] neighbours = new bool[4];

        bool left  = true;
        bool right = true;
        bool top   = true;
        bool down  = true;


        int x = isle.field.x;
        int y = isle.field.y;

        if (x - 1 < 0 || map_array[x - 1, y].field.evaluate() != 1)
        {
            left = false;
        }
        if (x + 1 > map_Width - 1 || map_array[x + 1, y].field.evaluate() != 1)
        {
            right = false;
        }
        if (y - 1 < 0 || map_array[x, y - 1].field.evaluate() != 1)
        {
            down = false;
        }
        if (y + 1 > map_Height - 1 || map_array[x, y + 1].field.evaluate() != 1)
        {
            top = false;
        }
        neighbours[0] = left;
        neighbours[1] = right;
        neighbours[2] = down;
        neighbours[3] = top;

        return(neighbours);
    }
Ejemplo n.º 9
0
 public void UpdatePlayerPosition()
 {
     player_position = player.location.GetComponent <Isle_Behaviour>();
 }