public void HideDoublePointsOnAllZaps() { List <Zap> lucrativeZaps = m_CurrZapGrid.GetLucrativeZaps(); for (int i = 0; i < lucrativeZaps.Count; i++) { Zap currZap = lucrativeZaps[i]; currZap.HideAllDoublePointsPopUpText(); } }
private float CalculateZapWidth(Zap zap, int numCols) { float height = Camera.main.orthographicSize * 2; float width = height * Screen.width / Screen.height; // basically height * screen aspect ratio Sprite s = zap.GetComponent <SpriteRenderer>().sprite; float unitWidth = s.textureRect.width / s.pixelsPerUnit; float unitHeight = s.textureRect.height / s.pixelsPerUnit; return(width / unitWidth / numCols); }
// replaces zap at location i j with zap public IEnumerator DestroyAndReplaceZap(int i, int j, Zap zap, float transitionTime, AutoTurretBullet bullet) { // get previous zap and all data from it into new zap Zap previousZap = GetZap(i, j); zap.IsDangerousZap = previousZap.IsDangerousZap; zap.SetWidth(m_ZapWidth); zap.SetHeight(m_ZapHeight); zap.SetOffsetDistance(m_OffsetDistance); zap.Row = i; zap.Col = j; // remove previous zap from dangerous zaps and destroy it if (previousZap.IsDangerousZap) { m_DangerousZaps.Remove(previousZap); } // Scale new zap until size of old zap and then delete old zap Vector3 startNewZapScale = new Vector3(0, zap.transform.localScale.y, zap.transform.localScale.z); float currTime = 0; while (currTime < transitionTime) { // if the zap gets broken while it is lerping if (zap == null) { break; } currTime += Time.deltaTime; zap.transform.localScale = Vector3.Lerp(startNewZapScale, previousZap.transform.localScale, currTime / transitionTime); zap.m_SpriteRenderer.sortingOrder = previousZap.m_SpriteRenderer.sortingOrder + 1; yield return(null); } // destroy old zap and set new zap as zap in the new place of old zap in zap grid Destroy(previousZap.gameObject); /// make sure zap wasnt destroyed while lerping size if (zap != null) { m_ZapGrid[i][j] = zap; } Destroy(bullet.gameObject); }
protected void BreakZap(Collision2D col) { if (col.contacts != null && col.contacts.Length > 0) { Vector3 contactPoint = new Vector3(col.contacts[0].point.x, this.transform.position.y, this.transform.position.z); Vector3 zapPositionBotLeft = this.transform.position; Vector3 zapPositionBotRight = this.transform.position + new Vector3(this.Width, 0, 0); // get new widths of zaps to spawn float widthFirstSection = Vector3.Distance(zapPositionBotLeft, contactPoint); float widthSecondSection = Vector3.Distance(contactPoint, zapPositionBotRight); float entireWidth = widthFirstSection + widthSecondSection; float percentageFirstSection = widthFirstSection / entireWidth; float percentageSecondSection = widthSecondSection / entireWidth; // Get width of a zap ZapGrid zapGrid = GameMaster.Instance.m_ZapManager.GetZapGrid(); if (zapGrid != null) { float zapWidth = zapGrid.GetZapWidth(); if (m_BS._breakSound != null) { AudioManager.Instance.Spawn2DAudio(m_BS._breakSound, true); } // Instantiate splitting zaps Zap zap1 = Instantiate(this, this.transform.position, Quaternion.identity); zap1.SetWidth(zapWidth * percentageFirstSection); zap1.ApplyForce(false); zap1.DisableCollision(); zap1.FadeThenDestroy(); Zap zap2 = Instantiate(this, contactPoint, Quaternion.identity); zap2.SetWidth(zapWidth * percentageSecondSection); zap2.ApplyForce(true); zap2.DisableCollision(); zap2.FadeThenDestroy(); //Destroy(this.gameObject); } } }
public Zap GetRandomZapPrefab() { if (m_ZapPrefabs == null || m_ZapPrefabs.Count <= 0) { return(null); } Zap resZapPrefab = null; float randPercent = Random.Range(0, 1.0f); float lowerBound = 0.0f; float upperBound = 1.0f; for (int i = 0; i < m_ZapPrefabChance.Count; i++) { upperBound = m_ZapPrefabChance[i] + lowerBound; if (randPercent >= lowerBound && randPercent <= upperBound) { resZapPrefab = m_ZapPrefabs[i]; } lowerBound = upperBound; } return(resZapPrefab); }
public void Init() { // pre fill the zap grid before shuffling. m_ZapGrid = new List <List <Zap> >(); for (int i = 0; i < m_Rows + 1; i++) { List <Zap> zapRowToFill = new List <Zap>(); if (i >= m_Rows) { for (int j = 0; j < m_Cols; j++) { zapRowToFill.Add(m_EndZapPrefab); } } else { // spawn all required zaps for this row int totalForcedPrefabsAdded = 0; for (int j = 0; j < m_ZapPrefabsForced.Count; j++) { int numOfPrefabToSpawn = m_ZapPrefabsForced[j]; Zap prefabToSpawn = m_ZapPrefabs[j]; for (int k = 0; k < numOfPrefabToSpawn; k++) { zapRowToFill.Add(prefabToSpawn); totalForcedPrefabsAdded++; } } for (int j = totalForcedPrefabsAdded; j < m_Cols; j++) { // spawn zap Zap zapPrefab = GetRandomZapPrefab(); zapRowToFill.Add(zapPrefab); } // shuffle the zaps in each row for (int k = 0; k < zapRowToFill.Count; k++) { Zap temp = zapRowToFill[k]; int randomIndex = (int)Random.Range(0, zapRowToFill.Count - 1); zapRowToFill[k] = zapRowToFill[randomIndex]; zapRowToFill[randomIndex] = temp; } } m_ZapGrid.Add(zapRowToFill); } // Do one time calculations for grid before spawning zaps. Vector3 topLeftInWorldSpace = Camera.main.ScreenToWorldPoint( new Vector3(0, 1.5f * ScreenUtilities.GetDistanceInWS(1.0f), 0)); Vector3 origin = topLeftInWorldSpace; origin.z = 1.0f; this.transform.position = origin; m_ZapWidth = CalculateZapWidth(m_EndZapPrefab, m_Cols); for (int i = 0; i < m_Rows + 1; i++) { Vector3 spawnPos = Vector3.zero; for (int j = 0; j < m_Cols; j++) { // set position accordingly relative to previous zap. if (j > 0) { Zap prevZap = m_ZapGrid[i][j - 1]; spawnPos = prevZap.transform.position + new Vector3(prevZap.Width, 0, 0); } else // spawn start zap in row { spawnPos = origin + new Vector3(0, i * m_RowGapDistance, 0); } Zap zapPrefab = m_ZapGrid[i][j]; if (zapPrefab != null) { Zap zap = (Zap)Instantiate(zapPrefab, this.transform); if (zap.IsDangerousZap) { m_DangerousZaps.Add(zap); } if (zap.m_HasPoints && zap.m_Points > 0) { m_LucrativeZaps.Add(zap); } zap.transform.position = spawnPos; zap.SetWidth(m_ZapWidth); zap.SetHeight(m_ZapHeight); zap.SetOffsetDistance(m_OffsetDistance); zap.Row = i; zap.Col = j; m_ZapGrid[i][j] = zap; // spawn things randomly on zap // SpawnRandomObstacle(i, j, m_ChanceOfObstacle); } } } // randomly determine if there is zap money on this zap for (int i = 0; i < m_MaxZapMoneys; i++) { float randomPercentChance = Random.Range(0.0f, 1.0f); if (randomPercentChance <= m_ZapMoneyProbability) { Zap randomZap = GetRandomZap(); if (randomZap != null && !randomZap.GetIsOccupied()) { ZapMoney zapMoney = Instantiate( m_ZapMoneyPrefab, randomZap.GetOffsetPosition(), Quaternion.identity, this.transform); randomZap.SetOccupied(true); } } } }