Esempio n. 1
0
        public virtual void SetUpTile(Grid grid, Axial position, Transform root)
        {
            var copy = Instantiate <GameObject>(gameObject);

            copy.transform.SetParent(root);
            copy.transform.localPosition = Vector3.zero;
        }
Esempio n. 2
0
 public Tile this[Axial axial] {
     get {
         return((Tile)tiles[axial.q][axial.r]);
     }
     set {
         SetTile(axial, value);
     }
 }
Esempio n. 3
0
 public virtual void RemoveTile(Grid grid, Axial position, Transform root)
 {
     // By default just remove all children from the root
     for (int i = 0; i < root.childCount; ++i)
     {
         Destroy(root.GetChild(i).gameObject);
     }
 }
Esempio n. 4
0
        public override void InfluenceUpdated(Grid grid, Axial position)
        {
            var renderers = grid.tileRoots[position.q][position.r].GetComponentsInChildren <MeshRenderer>();

            foreach (var renderer in renderers)
            {
                renderer.material = grid.TEMPplayerInfluence[position.q][position.r] > 0 ? positive : negative;
            }
        }
Esempio n. 5
0
 public                       Axial[] GetNeighbours()
 {
     Axial[] neighbours = new Axial[Neighbours.Length];
     Array.Copy(Neighbours, neighbours, neighbours.Length);
     for (int i = 0; i < neighbours.Length; ++i)
     {
         neighbours[i] += this;
     }
     return(neighbours);
 }
Esempio n. 6
0
        void SetTile(Axial pos, Tile tile)
        {
            // TODO: Check bounds
            var currentType = tiles[pos.q][pos.r];

            tileTypes[currentType].RemoveTile(this, pos, tileRoots[pos.q][pos.r]);

            var newID = (int)tile;

            tiles[pos.q][pos.r] = newID;
            tileTypes[newID].SetUpTile(this, pos, tileRoots[pos.q][pos.r]);
        }
Esempio n. 7
0
        public bool Raycast(Ray ray, out Axial position)
        {
            Plane horizontalPlane = new Plane(Vector3.up, transform.position);

            float distance = 0.0f;

            if (horizontalPlane.Raycast(ray, out distance))
            {
                Vector3 hitWorldPosition = ray.origin + ray.direction * distance;
                Vector3 hitLocalPosition = transform.InverseTransformPoint(hitWorldPosition);

                float q = (Mathf.Sqrt(3.0f) / 3.0f * hitLocalPosition.x - 1.0f / 3.0f * hitLocalPosition.z) / HexSize;
                float r = (2.0f / 3.0f * hitLocalPosition.z) / HexSize;
                position = Axial.Round(q, r);
                return(IsWithinBounds(position));
            }
            position = new Axial();
            return(false);
        }
Esempio n. 8
0
        public override void RemoveTile(Grid grid, Axial position, Transform root)
        {
            base.RemoveTile(grid, position, root);

            Queue <Axial> toVisit = new Queue <Axial>();

            foreach (Axial neighbour in position.GetNeighbours())
            {
                toVisit.Enqueue(neighbour);
            }

            HashSet <Axial> visited = new HashSet <Axial>();

            while (toVisit.Count > 0)
            {
                Axial neighbour = toVisit.Dequeue();
                if (visited.Contains(neighbour))
                {
                    continue;
                }

                visited.Add(neighbour);

                if (grid.IsWithinBounds(neighbour))
                {
                    grid.TEMPAddInfluence(neighbour, -Mathf.FloorToInt(centerInfluence * (1.0f - Axial.Distance(neighbour, position) / (float)radius)));
                }

                foreach (Axial next in neighbour.GetNeighbours())
                {
                    if (Axial.Distance(next, position) < radius)
                    {
                        toVisit.Enqueue(next);
                    }
                }
            }
        }
Esempio n. 9
0
 public static Axial operator /(Axial lhs, float scalar)
 {
     return(Axial.Round(lhs.q / scalar, lhs.r / scalar));
 }
Esempio n. 10
0
 public static Axial operator *(float scalar, Axial rhs)
 {
     return(Axial.Round(rhs.q * scalar, rhs.r * scalar));
 }
Esempio n. 11
0
 public override bool CanBePlaced(Grid grid, Axial position)
 {
     return(grid.TEMPplayerInfluence[position.q][position.r] > 0);
 }
Esempio n. 12
0
 public bool IsWithinBounds(Axial position)
 {
     return(position.q >= 0 && position.q < width && position.r >= 0 && position.r < height);
 }
Esempio n. 13
0
        public TileComponent GetTileComponentAt(Axial axial)
        {
            var tileComponent = tileTypes[tiles[axial.q][axial.r]];

            return(tileComponent);
        }
Esempio n. 14
0
 public virtual bool CanBePlaced(Grid grid, Axial position)
 {
     return(true);
 }
Esempio n. 15
0
 public virtual void InfluenceUpdated(Grid grid, Axial position)
 {
 }