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); } }
public void GenerateNonReactiveFloor() { Vector3Int originPos = new Vector3Int(0, level, 0); TowerBlock origin = CreateRandomTowerBlock(originPos, tower.blockSize); GenerateNonReactiveAdjacents(origin); }
public void NotifyBlockDestroy(TowerBlock block) { if (OnBlockDestroyedEvent != null) { OnBlockDestroyedEvent.Invoke(block); } }
public void OnBlockDestroyed(TowerBlock block) { //if (block.element == Element.Paruflore) { // neutralCount--; // if (neutralCount == 0) { // gameEnded = true; // } //} }
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); }
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); }
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(); }
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; } }
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]); } } } } }
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(); } }
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; }