protected IEnumerator ConstellationFlyAway(GameData.Constellation constellation) { var yDisplace = 0f; while (yDisplace < 100f && constellation.ConstellationParent != null) { var pos = constellation.ConstellationParent.transform.position; pos.y += Time.deltaTime * Speed; constellation.ConstellationParent.transform.position = pos; yDisplace += Time.deltaTime * Speed; yield return(null); } DestroyConstellation(constellation); }
protected void BreakStarLink(GameData.Constellation constellation, Guid starId) { var star = constellation.Stars[starId]; //Remove star from linked stars for (int i = 0; i < star.LinkedStars.Count; i++) { if (constellation.Stars.ContainsKey(star.LinkedStars[i])) { GameData.Star linkedStar = constellation.Stars[star.LinkedStars[i]]; linkedStar.LinkedStars.Remove(star.StarId); } } //Get all involved links List <GameData.Link> removedLinks = new List <GameData.Link>(); for (int i = 0; i < constellation.Links.Count; i++) { if (constellation.Links[i].StarIds.Contains(star.StarId)) { removedLinks.Add(constellation.Links[i]); } } //Destroy Link for (int i = 0; i < removedLinks.Count; i++) { GameData.Link link = removedLinks[i]; constellation.Stars[link.StarIds[0]].LinkedStars.Remove(constellation.Stars[link.StarIds[1]].StarId); constellation.Stars[link.StarIds[1]].LinkedStars.Remove(constellation.Stars[link.StarIds[0]].StarId); Destroy(link.LineComponent.gameObject); constellation.Links.Remove(link); } //Return to original layer star.Controller.UpdateLayerToStar(); //Remove star from constellation constellation.Stars.Remove(starId); PooledObject pool = star.Controller.gameObject.GetComponent <PooledObject>(); pool.ReturnToPool(); }
protected void CreateDisplayConstellation(GameData.Constellation original) { //Remove previous constellations for (int i = 0; i < ConstellationDisplayParent.childCount; i++) { Destroy(ConstellationDisplayParent.GetChild(0).gameObject); } //Duplicate Constellation GameObject duplicateConstellation = Instantiate(original.ConstellationParent); for (int i = 0; i < duplicateConstellation.transform.childCount; i++) { var child = duplicateConstellation.transform.GetChild(i); var poolComp = child.GetComponentInChildren <PooledObject>(); Destroy(poolComp); child.tag = "DisplayStar"; var starComp = child.GetComponentInChildren <StarController>(); Destroy(starComp); var lineComp = child.GetComponentInChildren <LineRenderer>(); if (lineComp != null) { lineComp.SetWidth(0.1f, 0.1f); } } //Up opacity on background SpriteRenderer background = duplicateConstellation.transform.FindChild("Background").GetComponent <SpriteRenderer>(); background.color = ConstellationDisplayBackgroundColor; Vector3 center = GetAverageStarPosition(new List <GameData.Star>(original.Stars.Values).ToArray()); duplicateConstellation.transform.SetParent(ConstellationDisplayParent); duplicateConstellation.transform.localScale = Vector3.one; duplicateConstellation.transform.localPosition = Vector3.zero - center; UiController.TriggerConstellationFadeEvent(original.ConstellationName); StartCoroutine(DisplayConstellationSuicide(duplicateConstellation)); }
protected void DestroyConstellation(GameData.Constellation constellation) { //Destroy Stars var stars = new List <GameData.Star>(constellation.Stars.Values); for (int i = 0; i < stars.Count; i++) { var star = stars[i]; if (star.Controller != null) { Destroy(star.Controller.gameObject); } } //Destroy Links for (int i = 0; i < constellation.Links.Count; i++) { var link = constellation.Links[i]; Destroy(link.LineComponent.gameObject); } }
protected void StarToCometCollision(GameData.Constellation constellation, Guid starId) { if (constellation.Stars.ContainsKey(starId)) { GameData.Star star = constellation.Stars[starId]; //Explosion Vector3 particlePosition = constellation.Stars[starId].Controller.gameObject.transform.position; particlePosition.y += 1f; Instantiate(starHitCometParticle, particlePosition, Quaternion.identity); //Pushback float strength = GameData.baseStrength + (GameData.strengthMultiplier * star.LinkedStars.Count); GameController.TriggerCometCollision(strength, GameData.cometCollisionSpeed); BreakStarLink(constellation, starId); if (constellation.Stars.Count <= 0) { Destroy(constellation.ConstellationParent); } AudioController.Instance.PlaySfx(SoundBank.SoundEffects.ConstellationHit); } }
public bool CompleteConstellation() { Debug.Log("Complete Constellation"); if (Stars.Count >= GameData.minimumStars) { LastStarId = null; var constellation = new GameData.Constellation(); constellation.Stars = new Dictionary <Guid, GameData.Star>(Stars); constellation.Links = new List <GameData.Link>(Links); GameObject constellationParent = new GameObject("Constellation"); constellation.ConstellationParent = constellationParent; GameObject constellationBackgorund = new GameObject("Background"); constellationBackgorund.transform.SetParent(constellationParent.transform); constellationBackgorund.transform.position = GetAverageStarPosition(new List <GameData.Star>(constellation.Stars.Values).ToArray()); SpriteRenderer bgSpriteRenderer = constellationBackgorund.AddComponent <SpriteRenderer>(); bgSpriteRenderer.sprite = GetRandomConstellationImage(); bgSpriteRenderer.color = ConstellationBackgroundColor; string constellationName = GenerateConstellationName(Stars.Keys.Count); constellation.ConstellationName = constellationName; Debug.Log("Constellation Name:" + constellationName); var keys = new List <Guid>(constellation.Stars.Keys); for (int i = 0; i < keys.Count; i++) { Guid key = keys[i]; GameData.Star star = constellation.Stars[key]; star.Controller.UpdateLayerToSendStar(); star.Controller.starTriggered.AddListener(() => StarToCometCollision(constellation, key)); star.Controller.gameObject.transform.SetParent(constellationParent.transform); } for (int i = 0; i < constellation.Links.Count; i++) { constellation.Links[i].LineComponent.gameObject.transform.SetParent(constellationParent.transform); } //Send data to Visualization and score //Score int score = GameData.scorePerStar; float totalConnections = 1 + (GameData.scoreConnectionMulti * constellation.Links.Count); float totalStars = 1 + (GameData.constSizeMulti * constellation.Stars.Count); GameController.TriggerAddScore((int)((score * totalConnections) * totalStars)); UiController.TriggerScoreData(constellation.Stars.Count, constellation.Links.Count, score, constellationName); Stars.Clear(); Links.Clear(); UiController.TriggerConstellationEvent(constellationParent); //Create Mini CreateDisplayConstellation(constellation); Tweener tween = constellation.ConstellationParent.transform.DOMoveY(GameData.cometStartY * 2, GameData.sendSpeed).SetEase(Ease.InOutBack); tween.OnComplete(() => DestroyConstellation(constellation)); AudioController.Instance.PlaySfx(SoundBank.SoundEffects.ConstellationComplete); AudioController.Instance.PlayAtEnd(AudioController.Instance.effectBus[(int)SoundBank.SoundEffects.ConstellationComplete], SoundBank.Instance.Request(SoundBank.SoundEffects.ConstellationSent), false); //StartCoroutine(ConstellationFlyAway(constellation)); return(true); } else { return(false); } }