// Used to handle everything happens when spawns a child cell public IEnumerator ProduceChild() { if (bCanSpawn) { bCanSpawn = false; // Calling the Animate class for spawn animation Animate mAnimate; mAnimate = new Animate(this.transform); mAnimate.ExpandContract(0.1f, 1, 1.1f); if (Level_Manager.LevelID < 4) { EMController.Instance().ReduceNutrient(); } // Randomize the interval time between spawns of child cells in terms of current difficulty float intervalTime = UnityEngine.Random.Range( 1.25f / EMDifficulty.Instance().CurrentDiff, 1.75f / EMDifficulty.Instance().CurrentDiff ); if (Level_Manager.LevelID > 2) { intervalTime /= 1.2f; } yield return(new WaitForSeconds(intervalTime)); if (m_EMFSM.AvailableChildNum < 100) { bCanSpawn = true; } } }
// Co-Routines IEnumerator SpawnRoutine() { bIsProduce = true; this.CalculateCooldown(); while (bIsProduce) { yield return(new WaitForSeconds(fNextCooldown)); if (SquadChildFSM.StateCount(SCState.Produce) != 0) { if (!this.CalculateCooldown()) { bIsProduce = false; } else { SquadChildFSM.Spawn(transform.position); mAnimate.ExpandContract(0.5f, 1, 1.3f); } } else { bIsProduce = false; } } }
public void ActionSpawn(int _nodeIndex) { Node _selectedNode = (Node)_nodeIndex; if (activeNode != Node.None && !m_bIsHoldingDownSpawnBtn) { return; } if (PlayerChildFSM.GetActiveChildCount() >= Constants.s_nPlayerMaxChildCount) { infoText.text = "Reached\nMaximum\nChild Cell\nCount"; PresentInfoPanel(); Node_Manager.GetNode(_selectedNode).CalculateChildCount(); // Force calcualtion check. return; } if (s_nResources >= Settings.s_nPlayerChildSpawnCost) { // Call a child cell from object pool and set its m_assignedNode to assigned node. PlayerChildFSM currentChild = PlayerChildFSM.Spawn(PlayerMain.Instance.transform.position + (Vector3)Random.insideUnitCircle * 0.25f); currentChild.m_assignedNode = Node_Manager.GetNode(_selectedNode); currentChild.m_bIsDefending = Node_Manager.GetNode(_selectedNode).m_bIsDefending; currentChild.m_assignedNode.AddChildToNode(currentChild.poolIndex); s_nResources -= Settings.s_nPlayerChildSpawnCost; UpdateUI_nutrients(); UpdateUI_nodeChildCountText(); // Animations PlayerMain.Instance.animate.ExpandContract(0.5f, 1, 1.2f, true, 0.2f); switch (_selectedNode) { case Node.LeftNode: leftNodeChildText.transform.localPosition = new Vector3(leftNodeChildText.transform.localPosition.x, childCountTextOriginY + childCountTextPopOffsetY); m_LeftNodeChildTextAnimate.ExpandContract(1.1f, 1, 4.0f, true, 0.4f); break; case Node.RightNode: rightNodeChildText.transform.localPosition = new Vector3(rightNodeChildText.transform.localPosition.x, childCountTextOriginY + childCountTextPopOffsetY); m_RightNodeChildTextAnimate.ExpandContract(1.1f, 1, 4.0f, true, 0.4f); break; } // Update tutorial state if (Tutorial.Instance() != null && Tutorial.Instance().tutorialState == TutorialState.PlayerNodeTapWaiting) { Tutorial.Instance().tutorialState = TutorialState.PlayerNodeTapCompleted; } AudioManager.PlayPMSoundEffect(PlayerMainSFX.SpawnCell); } else { infoText.text = "Not enough\nnutrients\n\nNeeded:\n" + Settings.s_nPlayerChildSpawnCost + " units"; PresentInfoPanel(); } }
// Update(): is called once per frame void Update() { if (bIsInPool) { return; } // if: Checks if the resource is clicked if (bIsCollectable) { // Animation of player absorbing the resource Vector2 vectorToTarget = endPosition - transform.position; transform.position = Vector2.MoveTowards(transform.position, endPosition, (vectorToTarget.magnitude * fTimeTaken + fMinimumSpeed) * Time.deltaTime); transform.rotation = Quaternion.AngleAxis(vectorToTarget.magnitude * 60f, Vector3.forward); // ExpandContract. if (mAnimate.IsExpandContract == false) { mAnimate.ExpandContract(0.5f, 1, 1.5f, true, 0f); } if (transform.position == endPosition) { SendBackToPool(); } } else { // distanceMagnitude: The magnitude between the resource and the player's main cell's position float distanceMagnitude = (playerMainTransform.position - transform.position).magnitude; transform.position = Vector2.MoveTowards(transform.position, playerMainTransform.position, (distanceMagnitude * fTimeTaken + fMinimumSpeed) * 5.0f * Time.deltaTime); transform.localScale = Vector3.one * (distanceMagnitude / fClickMagnitude); if (distanceMagnitude < 0.1f) { SendBackToPool(); } } }
// Pause the spawning process so that there are not too many mini cells taking too much computing power at the same time IEnumerator PauseSpawn() { bCanSpawn = false; // Pause for random amount of time depending on the size of the agent yield return(new WaitForSeconds(Random.Range(Mathf.Sqrt(Mathf.Pow(nSize, 1f)), Mathf.Sqrt(Mathf.Pow(nSize, 3f))))); // Double check if the main nutrient is in the map and not too close to the enemy main cell if (MapManager.Instance.IsInBounds((Vector2)(position * 1.1f)) && Vector2.Distance(EMHelper.Instance().Position, transform.position) > fInitialRadius * nSize + EMHelper.Instance().Radius) { // Instantiate a mini nutrient object Instantiate(miniNutrient, position, Quaternion.identity); // Calling the Animate class for spawn animation Animate mAnimate; mAnimate = new Animate(this.transform); mAnimate.ExpandContract(0.1f, 1, 1.1f); // Reduce the size of the current main nutrient by 1 nSize--; } bCanSpawn = true; }
public override void Execute() { if (EnemyMainFSM.Instance() != null) { m_LeaderMine = ObtainLeaderFrmMines(); } if (!m_bGatherTogether) { m_nECMineNearby = GetNearbyECMineAmount(); if (m_nECMineNearby == ECTracker.Instance.LandmineCells.Count) { if (m_LeaderMine != null) { m_CurrentPositionType = DeterminePositionType(); m_Target = m_ecFSM.m_AttackTarget; if (m_Target == null) { m_Target = PositionQuery.Instance.GetLandmineTarget(m_CurrentPositionType, m_Child); } m_TargetLandminePos = PositionQuery.Instance.GetLandminePos(DetermineRangeValue(), m_CurrentPositionType, m_LeaderMine); PathQuery.Instance.AStarSearch(m_LeaderMine.transform.position, m_TargetLandminePos, false); m_PathToTarget = PathQuery.Instance.GetPathToTarget(DetermineDirectness(m_Target)); m_nCurrentTargetIndex = 0; m_CurrentTargetPoint = m_PathToTarget[m_nCurrentTargetIndex]; } m_bGatherTogether = true; AudioManager.PlayECSoundEffect(EnemyChildSFX.DeployLandmine, m_ecFSM.Audio); } } if (!m_bExploding && !m_bExplodeCorountineStart && IsMineReachingPlayer(m_Target)) { m_bExploding = true; m_bExplodeCorountineStart = true; m_ecFSM.rigidbody2D.drag = 0f; m_ecFSM.rigidbody2D.velocity = new Vector2(m_ecFSM.rigidbody2D.velocity.x * 0.75f, m_ecFSM.rigidbody2D.velocity.y); m_ecFSM.StartChildCorountine(ExplodeCorountine()); } if (IsCellReachingWall()) { m_ecFSM.rigidbody2D.velocity = new Vector2(0f, m_ecFSM.rigidbody2D.velocity.y); } if (m_bGatherTogether && (HasCellReachTarget(m_PathToTarget[m_PathToTarget.Count - 1].Position) || ECTracker.Instance.LandmineCells.Count <= 1 || m_Child.transform.position.y < m_PathToTarget[m_PathToTarget.Count - 1].Position.y)) { m_bReachTarget = true; m_EndPosition = new Vector2(m_Child.transform.position.x, -99f); m_ecFSM.StopChildCorountine(ExplodeCorountine()); } if (m_bGatherTogether && m_ecFSM.HitBottomOfScreen()) { MessageDispatcher.Instance.DispatchMessage(m_Child, m_Child, MessageType.Dead, 0.0f); } if (m_bGatherTogether && !m_bExpandContractStart) { m_Animator.ExpandContract(15f, 60, 1.9f); m_bExpandContractStart = true; } }
public void DisplayEnemyStun(float _stunDuration) { stunDisplayDuration = _stunDuration; EnemyStunnedTextSpriteRen.enabled = true; m_EnemyStunnedTextAnimate.ExpandContract(500.0f, 1000, 1.25f, true, 0f); }
void Update() { if (shouldSnapUp) { cameraTransform.position += Vector3.up * snapSpeed * Time.deltaTime * slowDownFactor; if (slowDownFactor > minSlowDownFactor) { slowDownFactor *= 0.925f; } else { slowDownFactor = minSlowDownFactor; } switch (_menuPosition) { case MainMenuPosition.Bottom: if (cameraTransform.position.y > 0f) { cameraTransform.position = new Vector3(cameraTransform.position.x, 0f, cameraTransform.position.z); _menuPosition = MainMenuPosition.Center; shouldSnapUp = false; isSnapping = false; } break; case MainMenuPosition.Center: if (cameraTransform.position.y > maxY) { cameraTransform.position = new Vector3(cameraTransform.position.x, maxY, cameraTransform.position.z); _menuPosition = MainMenuPosition.Top; shouldSnapUp = false; isSnapping = false; } break; } } if (shouldSnapDown) { cameraTransform.position -= Vector3.up * snapSpeed * Time.deltaTime; switch (_menuPosition) { case MainMenuPosition.Top: if (cameraTransform.position.y < 0f) { cameraTransform.position = new Vector3(cameraTransform.position.x, 0f, cameraTransform.position.z); _menuPosition = MainMenuPosition.Center; shouldSnapDown = false; isSnapping = false; } break; case MainMenuPosition.Center: if (cameraTransform.position.y < minY) { cameraTransform.position = new Vector3(cameraTransform.position.x, minY, cameraTransform.position.z); _menuPosition = MainMenuPosition.Bottom; shouldSnapDown = false; isSnapping = false; } break; } } if (shouldSnapBack) { switch (_menuPosition) { case MainMenuPosition.Top: _menuPosition = MainMenuPosition.Center; shouldSnapUp = true; isSnapping = true; break; case MainMenuPosition.Center: if (cameraTransform.position.y > 0) { _menuPosition = MainMenuPosition.Top; shouldSnapDown = true; isSnapping = true; } else { _menuPosition = MainMenuPosition.Bottom; shouldSnapUp = true; isSnapping = true; } break; case MainMenuPosition.Bottom: _menuPosition = MainMenuPosition.Center; shouldSnapDown = true; isSnapping = true; break; } shouldSnapBack = false; } swipeTextCanvasGroup.alpha = 1f - Mathf.Abs(cameraTransform.position.y) * alphaMultiplier; titleTransform.position = new Vector3(0f, cameraTransform.position.y * titlePosMultiplier); if (titleAnimate.IsExpandContract == false) { titleAnimate.ExpandContract(2.0f, 1, 1.1f); } }
public void UpdateUI_nutrients() { nutrientText.text = s_nResources.ToString(); m_ResourceTextAnimate.ExpandContract(0.25f, 1, 1.5f, true, 0.5f); }
// Pause the spawning process so that there are not too many mini cells taking too much computing power at the same time IEnumerator PauseSpawn() { bCanSpawn = false; // Pause for random amount of time depending on the size of the agent yield return new WaitForSeconds (Random.Range (Mathf.Sqrt (Mathf.Pow (nSize, 1f)), Mathf.Sqrt (Mathf.Pow (nSize, 3f)))); // Double check if the main nutrient is in the map and not too close to the enemy main cell if (MapManager.Instance.IsInBounds ((Vector2)(position * 1.1f)) && Vector2.Distance (EMHelper.Instance().Position, transform.position) > fInitialRadius * nSize + EMHelper.Instance ().Radius) { // Instantiate a mini nutrient object Instantiate (miniNutrient, position, Quaternion.identity); // Calling the Animate class for spawn animation Animate mAnimate; mAnimate = new Animate (this.transform); mAnimate.ExpandContract (0.1f, 1, 1.1f); // Reduce the size of the current main nutrient by 1 nSize--; } bCanSpawn = true; }
// PulseSprawl(): Pulse the sprawl once public void PulseSprawl() { mAnimate.ExpandContract(0.5f, 1, 1.1f, true, 0.5f); }