예제 #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;
        }
예제 #2
0
파일: Grid.cs 프로젝트: JustASadPenguin/4x
 public Tile this[Axial axial] {
     get {
         return((Tile)tiles[axial.q][axial.r]);
     }
     set {
         SetTile(axial, value);
     }
 }
예제 #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);
     }
 }
예제 #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;
            }
        }
예제 #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);
 }
예제 #6
0
파일: Grid.cs 프로젝트: JustASadPenguin/4x
        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]);
        }
예제 #7
0
파일: Grid.cs 프로젝트: JustASadPenguin/4x
        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);
        }
예제 #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);
                    }
                }
            }
        }
예제 #9
0
 public static Axial operator /(Axial lhs, float scalar)
 {
     return(Axial.Round(lhs.q / scalar, lhs.r / scalar));
 }
예제 #10
0
 public static Axial operator *(float scalar, Axial rhs)
 {
     return(Axial.Round(rhs.q * scalar, rhs.r * scalar));
 }
예제 #11
0
 public override bool CanBePlaced(Grid grid, Axial position)
 {
     return(grid.TEMPplayerInfluence[position.q][position.r] > 0);
 }
예제 #12
0
파일: Grid.cs 프로젝트: JustASadPenguin/4x
 public bool IsWithinBounds(Axial position)
 {
     return(position.q >= 0 && position.q < width && position.r >= 0 && position.r < height);
 }
예제 #13
0
파일: Grid.cs 프로젝트: JustASadPenguin/4x
        public TileComponent GetTileComponentAt(Axial axial)
        {
            var tileComponent = tileTypes[tiles[axial.q][axial.r]];

            return(tileComponent);
        }
예제 #14
0
 public virtual bool CanBePlaced(Grid grid, Axial position)
 {
     return(true);
 }
예제 #15
0
 public virtual void InfluenceUpdated(Grid grid, Axial position)
 {
 }