Exemple #1
0
        private void GenerateNonReactiveAdjacents(TowerBlock block)
        {
            HashSet <Element> nonReactives = block.element.GetAllNonReactive();
            List <Vector3Int> validAdj     = block.GetValidAdjacentPositions();

            for (int i = 0; i < validAdj.Count; i++)
            {
                if (tower[validAdj[i]] != null)
                {
                    continue;
                }
                TowerBlock[] adjAdj = new TowerBlock[4];
                tower.GetFloorAdjacents(validAdj[i], ref adjAdj);
                for (int j = 0; j < adjAdj.Length; j++)
                {
                    if (adjAdj[j] == null)
                    {
                        continue;
                    }
                    nonReactives.IntersectWith(adjAdj[j].element.GetAllNonReactive());
                }
                TowerBlock adj = CreateTowerBlock(nonReactives.GetRandom(), validAdj[i], tower.blockSize);
                GenerateNonReactiveAdjacents(adj);
            }
        }
Exemple #2
0
        public void GenerateNonReactiveFloor()
        {
            Vector3Int originPos = new Vector3Int(0, level, 0);
            TowerBlock origin    = CreateRandomTowerBlock(originPos, tower.blockSize);

            GenerateNonReactiveAdjacents(origin);
        }
Exemple #3
0
 public void NotifyBlockDestroy(TowerBlock block)
 {
     if (OnBlockDestroyedEvent != null)
     {
         OnBlockDestroyedEvent.Invoke(block);
     }
 }
Exemple #4
0
 public void OnBlockDestroyed(TowerBlock block)
 {
     //if (block.element == Element.Paruflore) {
     //	neutralCount--;
     //	if (neutralCount == 0) {
     //		gameEnded = true;
     //	}
     //}
 }
Exemple #5
0
 public TowerBlock[] GetFloorAdjacents()
 {
     TowerBlock[] adjacents = new TowerBlock[4];
     adjacents[0] = tower[_position + new Vector3Int(0, 0, 1)];
     adjacents[1] = tower[_position + new Vector3Int(0, 0, -1)];
     adjacents[2] = tower[_position + new Vector3Int(1, 0, 0)];
     adjacents[3] = tower[_position + new Vector3Int(-1, 0, 0)];
     return(adjacents);
 }
Exemple #6
0
        private TowerBlock CreateTowerBlock(Element elem, Vector3Int pos, float blockSize)
        {
            GameObject go = Instantiate(elem.GetPrefab(), transform);

            go.transform.localPosition = new Vector3(pos.x * blockSize, blockSize / 2, pos.z * blockSize);
            TowerBlock block = go.GetComponent <TowerBlock>();

            block.Init(this, pos);
            return(block);
        }
Exemple #7
0
        public void TransformInto(Element element)
        {
            GameObject go = Instantiate(element.GetPrefab(), floor.transform);

            go.transform.localPosition = new Vector3(_position.x * tower.blockSize, tower.blockSize / 2, _position.z * tower.blockSize);
            TowerBlock block = go.GetComponent <TowerBlock>();

            block.Init(tower.GetFloor(_position.y), position);
            block.MarkReacted();
            Destroy(gameObject);
            GameManager.I.OnTransformation();
        }
Exemple #8
0
        private void Update()
        {
            if (locked)
            {
                if (targetedBlock != null)
                {
                    targetedBlock.GlowOff();
                    targetedBlock = null;
                }
                return;
            }

            Vector3    mPos = Input.mousePosition;
            Ray        ray  = cam.ScreenPointToRay(mPos);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 200f, LayerMask.GetMask("Blocks")))
            {
                TowerBlock block = hit.collider.GetComponent <TowerBlock>();
                if (block != targetedBlock)
                {
                    if (targetedBlock != null)
                    {
                        targetedBlock.GlowOff();
                    }
                    targetedBlock = block;
                    if (targetedBlock.element == Element.Paruflore)
                    {
                        targetedBlock.GlowValid();
                    }
                    else
                    {
                        targetedBlock.GlowInvalid();
                    }
                }
                if (Input.GetMouseButtonDown(0))
                {
                    if (targetedBlock.element == Element.Paruflore)
                    {
                        targetedBlock.DestroyBlock(false);
                    }
                }
            }
            else if (targetedBlock != null)
            {
                targetedBlock.GlowOff();
                targetedBlock = null;
            }
        }
Exemple #9
0
        public void ComputeReactions()
        {
            TowerBlock[] adjacents          = new TowerBlock[4];
            Element[]    adjacentsReactions = new Element[4];
            for (int y = 0; y < towerSize.y; y++)
            {
                for (int z = 0; z < towerSize.z; z++)
                {
                    for (int x = 0; x < towerSize.x; x++)
                    {
                        if (blocks[x, y, z] == null || !blocks[x, y, z].canReact)
                        {
                            continue;
                        }
                        blocks[x, y, z].GetFloorAdjacents(ref adjacents);

                        Element result = Element.None;
                        for (int i = 0; i < adjacents.Length; i++)
                        {
                            if (adjacents[i] == null || !adjacents[i].canReact)
                            {
                                continue;
                            }
                            Element adjResult = blocks[x, y, z].element.ReactWith(adjacents[i].element);
                            if (result == Element.None || result == adjResult)
                            {
                                result = adjResult;
                                adjacentsReactions[i] = result;
                            }
                        }

                        if (result == Element.None)
                        {
                            continue;
                        }
                        blocks[x, y, z].TransformInto(result);
                        for (int i = 0; i < adjacentsReactions.Length; i++)
                        {
                            if (adjacents[i] == null || adjacentsReactions[i] == Element.None)
                            {
                                continue;
                            }
                            adjacents[i].TransformInto(adjacentsReactions[i]);
                        }
                    }
                }
            }
        }
Exemple #10
0
 protected override void SubUpdate()
 {
     if (Time.time - spawnTime > tower.timeToExplode)
     {
         TowerBlock[] adjacents = new TowerBlock[6];
         GetCrossFloorAdjacents(ref adjacents);
         for (int i = 0; i < adjacents.Length; i++)
         {
             if (adjacents[i] == null || adjacents[i].element == Element.ExplodeElement || adjacents[i].isInTransit)
             {
                 continue;
             }
             adjacents[i].DestroyBlock();
         }
         GameManager.I.OnExplosion();
         DestroyBlock();
     }
 }
Exemple #11
0
 public void DestroyBlock(bool gainScore = true)
 {
     for (int y = position.y + 1; y < tower.towerSize.y; y++)
     {
         TowerBlock block = tower[new Vector3Int(position.x, y, position.z)];
         if (block == null)
         {
             break;
         }
         block.position += Vector3Int.down;
         block.StartDropTransition();
     }
     if (gainScore)
     {
         GameManager.I.OnUncontrolledDestroy();
     }
     tower.NotifyBlockDestroy(this);
     Destroy(gameObject);
     onDestroyEffect.transform.SetParent(transform.parent);
     onDestroyEffect.Play();
     onDestroyEffect.GetComponent <AutoDestroyParticleSystem>().enabled = true;
 }