示例#1
0
 public static bool IsTileIncludedInYourKingdom(HexTile hexTile)
 {
     if (!hexTile.isCity)
     {
         return(true);
     }
     else
     {
         if (hexTile.GetComponent <CityTileTest>().cityAttributes.kingdomTile == null)
         {
             return(true);
         }
         else
         {
             CityTileTest otherCity = hexTile.GetComponent <CityTileTest>();
             if (otherCity.cityAttributes.id == targetCity.id)
             {
                 return(true);
             }
             else
             {
                 if (targetCity.kingdomTile.kingdom.cities.Contains(otherCity))
                 {
                     return(false);
                 }
                 else
                 {
                     return(true);
                 }
             }
         }
     }
     return(true);
 }
示例#2
0
    public void ChangeColorClientRpc(int r, int q, int life)
    {
        HexTile currentHex = map.tileArray[r, q];

        if (life == 2)
        {
            currentHex.GetComponent <Renderer>().material.color = currentHex.color2life;
        }
        else if (life == 1)
        {
            currentHex.GetComponent <Renderer>().material.color = currentHex.color1life;
        }
    }
示例#3
0
    void Start()
    {
        Hexes = new Dictionary <Vector3Int, HexTile>();
        Renderer hex = HexPrefab.GetComponent <Renderer>();

        hexWidth  = hex.bounds.size.x;
        hexHeight = hex.bounds.size.y;
        Build();
    }
示例#4
0
    public void TestCombatPathfinding()
    {
        Utilities.targetCity = targetHexTile.GetComponent <CityTileTest> ().cityAttributes;
        List <Tile> path = GetPath(startingHexTile.tile, targetHexTile.tile, PATHFINDING_MODE.COMBAT).ToList();

        for (int i = 0; i < path.Count; i++)
        {
            path [i].hexTile.SetTileColor(Color.red);
        }
    }
示例#5
0
    public bool IsCoastal()
    {
        HexTile neighbor = null;

        foreach (HexCoordinate hc in Directions)
        {
            neighbor = GetNeighbor(hc);
            if (neighbor && neighbor.GetComponent <HexTile>().IsWater)
            {
                CoastalTile = true;
                return(true);
            }
        }
        CoastalTile = false;
        return(false);
    }
示例#6
0
    // This method moves our current tile to the new one
    public void MoveTile(HexTile hexTile)
    {
        if (activeTile)
        {
            activeTile.GetComponent <HexTile>().isActive = false;                                                    // deactivate our current tile (so other players could move to it later)
            hexTile.transform.gameObject.GetComponentInChildren <SpriteRenderer>().sprite = Util.ResourceSprites[0]; // set the tiles visual sprite to be desert (barren)
        }

        hexTile.isActive   = true;                                                                    // set our new tile to be active
        activeTile         = hexTile;                                                                 // set our current tile to be the new tile
        transform.position = hexTile.transform.position;                                              // move our piece to the new tile

        soundController = GameObject.FindGameObjectWithTag("Music").GetComponent <SoundController>(); // play the sound associated with the resource type of that tile
        if (soundController)
        {
            soundController.PlayMovePieceSound();
        }
    }
示例#7
0
    void Build()
    {
        Spaces = new Dictionary <Vector3Int, bool>();
        for (int x = -Size; x <= Size; x++)
        {
            for (int y = -Size; y <= Size; y++)
            {
                Vector2Int point = new Vector2Int(x, y);
                if (InMap(point, Size))
                {
                    HexTile hex = Instantiate(HexPrefab);
                    hex.GetComponent <SpriteRenderer>().color = Colour;
                    Vector3Int v3i = ConvertToVector3(point);
                    hex.transform.position = GetWorldPosition(v3i);
                    hex.Coordinates        = v3i;
                    Hexes[v3i]             = hex;

                    // Added bits around altitude and humidity
                    Vector2 v2       = new Vector2(x, y);
                    float   altitude = Noise.Generate2DNoiseValue(v2, altitudeSeed1) +
                                       Noise.Generate2DNoiseValue(v2, altitudeSeed2);
                    float humidity = Noise.Generate2DNoiseValue(v2, humiditySeed1) +
                                     Noise.Generate2DNoiseValue(v2, humiditySeed2);
                    hex.altitude = altitude;
                    if (altitude < mapPresets.seaLevel)
                    {
                        Spaces[v3i] = false;
                    }
                    else
                    {
                        Spaces[v3i] = true;
                    }
                    hex.humidity = humidity;
                    hex.ColourSwitch(mapPresets);
                }
            }
        }
        GenerateWitchBase(new Vector3Int(0, 0, 0));
    }
示例#8
0
    void OnSelectSpaceship(HexTile tile)
    {
        // bool valid = BuildingsManager.GetInstance().CanBuild(spaceship, platform.coordinate);
        bool valid = true;

        if (valid)
        {
            _selectedTile = tile;
            if (!_selectionIndicator)
            {
                _selectionIndicator = GameObject.Instantiate(selectionIndicatorPrefab, tile.transform.position, tile.transform.rotation);
            }


            _selectionIndicator.transform.position = tile.transform.position + new Vector3(0, 0.01f, 0);
            _selectionIndicator.GetComponent <Renderer>().material = tile.GetComponent <Renderer>().material;
            _selectionIndicator.GetComponent <Renderer>().material.SetFloat("_OutlineWidth", 1.2f);
        }
        else
        {
            UIManager.Message("Cannot build here");
        }
    }
示例#9
0
    public void CreateTerrain()
    {
        Clear();

        Terrain terrain = GetComponent <Terrain>();

        width  = (int)((terrain.terrainData.size.x - 2 * border) / _tileSize);
        height = (int)((terrain.terrainData.size.z - 2 * border) / (0.866025404f * _tileSize));

        tiles = new HexTile[width * height];

        tileWidth     = instance._tileSize;
        tileHeight    = 0.75f * instance._tileSize / 0.866025404f;
        tileHalfWidth = instance._tileSize / 2.0f;
        tileC         = tileHeight / 4.0f;
        tileM         = tileC / tileHalfWidth;

        float scale = _tileSize / (hexTextureWidth / 100.0f);

        int indexCounter = 0;

        for (int z = 0; z < height; z++)
        {
            for (int x = 0; x < width - (z % 2); x++)
            {
                HexTile hexTile      = Instantiate(hexTilePrefab);
                Vector3 tilePosition = new Vector3(border + 0.5f * _tileSize +
                                                   _tileSize * x + 0.5f * _tileSize * (z % 2),
                                                   0.0f,
                                                   z * _tileSize * 0.866025404f + border + 0.5f * _tileSize * (1.0f / 0.866025404f));

                hexTile.x     = x;
                hexTile.y     = z;
                hexTile.index = indexCounter++;
                hexTile.transform.SetParent(transform);
                hexTile.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f);
                hexTile.transform.localPosition    = tilePosition;
                hexTile.gameObject.isStatic        = true;

                hexTile.GetComponent <LineHexagon>().thickness = lineThickness;
                hexTile.GetComponent <LineHexagon>().scale     = _tileSize;
                hexTile.GetComponent <LineHexagon>().CreateMesh();
                // hexTile.gameObject.hideFlags = HideFlags.HideInHierarchy;

                Ray tileRay    = new Ray(hexTile.transform.position + sampleHeight * Vector3.up, Vector3.down);
                int layer_mask = LayerMask.GetMask("Terrain");

                RaycastHit info;

                if (Physics.Raycast(tileRay, out info, 1000.0f, layer_mask))
                {
                    hexTile.transform.position = new Vector3(hexTile.transform.position.x,
                                                             terrain.transform.position.y + sampleHeight - info.distance, hexTile.transform.position.z);
                }
                else
                {
                    hexTile.isOccluded = true;
                }

                // hexTile.GetComponent<SpriteRenderer>().sprite = spriteHexTileSolid;

                tiles[z * width + x] = hexTile;
            }
        }

        findNeighbors();

        DisableOccluded();
    }
示例#10
0
 public void Infect(HexTile hexTile)
 {
     hexTile.GetComponent <Renderer>().material.SetColor("_Color", infectionColor);
 }