コード例 #1
0
ファイル: GameManager.cs プロジェクト: adrianit0/Juego-qw
    /// <summary>
    /// Crea una estructura en el mapa.
    /// </summary>
    public void AddBuildInMap(int x, int y, Estructura estructura)
    {
        if (x < 0 || y < 0 || x >= totalSize.x || y >= totalSize.y)
        {
            return;
        }

        if (!map[x, y].CreateBuild(estructura))
        {
            Debug.LogWarning("No se ha podido crear la estructura.");
            return;
        }

        //Busca si existe el tipo a crear
        //Si no existe, lo crea
        ESTRUCTURA _tipo = estructura.GetBuildType();

        if (builds.ContainsKey(_tipo))
        {
            if (!builds[_tipo].Contains(estructura))
            {
                builds[_tipo].Add(estructura);
            }
        }
        else
        {
            builds.Add(_tipo, new List <Estructura>());
        }

        IUpdatable[] _update = estructura.GetComponents <IUpdatable>();
        if (_update != null)
        {
            time.AddUpdatable(_update);
        }
    }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: adrianit0/Juego-qw
    /// <summary>
    /// Busca la construcción más cercana.
    /// </summary>
    public Vector2 _GetNearBuild(Vector2 initialPos, ESTRUCTURA buildType)
    {
        if (!ExistBuild(buildType))
        {
            return(Vector3.zero);
        }

        List <Estructura> builds  = this.builds[buildType];
        Vector2           nearest = Vector3.zero;
        int foundCount            = 0;

        for (int i = 0; i < builds.Count; i++)
        {
            if (builds[i].GetBuildType() == buildType && (foundCount == 0 || Vector2.Distance(builds[i].transform.position, initialPos) < Vector2.Distance(nearest, initialPos)))
            {
                nearest = builds[i].transform.position;

                foundCount++;
            }
        }

        if (foundCount == 0)
        {
            Debug.LogWarning("No ha encontrado ninguna construcción cercana");
        }

        return(nearest);
    }
コード例 #3
0
ファイル: GameManager.cs プロジェクト: adrianit0/Juego-qw
    /// <summary>
    /// Busca una estructura y dice si existe o no.
    /// </summary>
    public bool ExistBuild(ESTRUCTURA buildType)
    {
        if (!builds.ContainsKey(buildType) || builds[buildType] == null)
        {
            return(false);
        }

        return(builds[buildType].Count > 0);
    }
コード例 #4
0
ファイル: GameManager.cs プロジェクト: adrianit0/Juego-qw
    /// <summary>
    /// Elimina una estructura, devolviendo un porcentaje de lo que costaba su creación
    /// El valor va del 0 al 1.
    /// </summary>
    public void RemoveBuildInMap(int x, int y, float devolver = 0)
    {
        Estructura _build = map[x, y].GetBuild();

        if (_build == null)
        {
            return;
        }

        ResourceInfo[] items = build.getObjetoConstrucción(_build.nombre);

        ESTRUCTURA _tipo = _build.GetBuildType();

        if (ExistBuild(_tipo) && builds[_tipo] != null && builds[_tipo].Contains(_build))
        {
            builds[_tipo].Remove(_build);
        }

        IUpdatable[] update = _build.GetComponents <IUpdatable>();

        if (update != null)
        {
            time.RemoveUpdatable(update);
        }

        map[x, y].RemoveBuild();

        if (devolver > 0 && items != null && items.Length > 0)
        {
            int total = 0;
            for (int i = 0; i < items.Length; i++)
            {
                items[i].quantity = Mathf.RoundToInt(items[i].quantity * devolver);
                total            += items[i].quantity;
            }

            if (total > 0)
            {
                CrearSaco(new IntVector2(x, y), items);
            }
        }

        Destroy(_build.gameObject);
    }
コード例 #5
0
ファイル: Construccion.cs プロジェクト: adrianit0/Juego-qw
    public Sprite CompareNeighbour(IntVector2 position, int selectID, bool compareNeighbours = true)
    {
        ObjetoTienda objeto   = construcciones[selectID];
        ESTRUCTURA   thisType = manager.GetNode(position).build.GetBuildType();


        //Si no dispone de sprite, devuelve error.
        if (objeto.spriteObjeto == null || objeto.spriteObjeto.Length == 0)
        {
            Debug.LogWarning("Construccion::CompareNeighbour error: " + objeto.nombre + " no tiene sprites asignados.");
            return(null);
        }

        if (objeto.spriteObjeto.Length == 1)
        {
            return(objeto.spriteObjeto[0]);
        }

        if (thisType == ESTRUCTURA.Ninguno)
        {
            Debug.LogWarning("Construccion::CompareNeighbour error: No es ningun tipo de estructura.");
            return(objeto.spriteObjeto[0]);
        }

        string name = objeto.nombre + "_";
        Node   node = manager.GetNode(position.x, position.y + 1);

        if (node != null && node.build != null && node.build.GetBuildType() == thisType)
        {
            name += "N";
            if (compareNeighbours)
            {
                node.build.ChangeSprite(CompareNeighbour(node.GetPosition(), selectID, false));
            }
        }

        node = manager.GetNode(position.x + 1, position.y);
        if (node != null && node.build != null && node.build.GetBuildType() == thisType)
        {
            name += "E";
            if (compareNeighbours)
            {
                node.build.ChangeSprite(CompareNeighbour(node.GetPosition(), selectID, false));
            }
        }

        node = manager.GetNode(position.x, position.y - 1);
        if (node != null && node.build != null && node.build.GetBuildType() == thisType)
        {
            name += "S";
            if (compareNeighbours)
            {
                node.build.ChangeSprite(CompareNeighbour(node.GetPosition(), selectID, false));
            }
        }

        node = manager.GetNode(position.x - 1, position.y);
        if (node != null && node.build != null && node.build.GetBuildType() == thisType)
        {
            name += "W";
            if (compareNeighbours)
            {
                node.build.ChangeSprite(CompareNeighbour(node.GetPosition(), selectID, false));
            }
        }

        for (int i = 0; i < objeto.spriteObjeto.Length; i++)
        {
            if (objeto.spriteObjeto[i].name == name)
            {
                return(objeto.spriteObjeto[i]);
            }
        }

        return(objeto.spriteObjeto[0]);
    }