private void FixedUpdate() { if (MinigameManager.GameOver) { return; } // difficulty check { var vectorList = new List <Vector2> { RotationSpeedMinMax, FlySpeedMinMax }; var unparsed = DifficultyAdjuster.SpreadDifficulty(MinigameManager.DiffCurrent, vectorList); RotationSpeed = unparsed[0]; FlySpeed = unparsed[1]; SpeedText.text = $"DIFFICULTY: {Mathf.Round(MinigameManager.DiffCurrent * 100)}"; } // following { // play sound? var direction = (Vector2)Target.position - rigidBody2D.position; direction.Normalize(); var up = rigidBody2D.transform.up; var rotationAngle = Vector3.Cross(direction, up).z; rigidBody2D.angularVelocity = -rotationAngle * RotationSpeed; rigidBody2D.velocity = up * FlySpeed; } }
private void FixedUpdate() { if ((spawnTimer += Time.fixedDeltaTime) > SpawnInBetween) { spawnTimer = 0; spawnCloud(); } if ((difficultyTimer += Time.fixedDeltaTime) > IncreaseAfter) { difficultyTimer = 0; var vectors = new List <Vector2> { CloudMoveSpeedMinMax }; CurrentDifficulty += IncreaseBy; currentCloudSpeed = DifficultyAdjuster.SpreadDifficulty(CurrentDifficulty, vectors)[0]; TextSpeed.text = $"DIFFICULTY: {System.Math.Round(CurrentDifficulty, 2) * 100}"; } foreach (var item in cloudPool) { if (item == null) { continue; } item.transform.position -= new Vector3(currentCloudSpeed * Time.fixedDeltaTime, 0, 0); } }
private void FixedUpdate() { if (MinigameManager.GameOver) { return; } if (lastCactus == null) { spawnCactus(); } spawnTimer = 0; if (liveObjects.Count <= MaxCactusesOnScreen && lastCactus.transform.position.x < Rex.transform.position.x) { MinigameManager.Events.EventScored(); spawnCactus(); if (CurrentDifficulty < 1.0f) { CurrentDifficulty += IncreaseDifficultyBy; var difficulty = DifficultyAdjuster.SpreadDifficulty(CurrentDifficulty, new List <Vector2>() { MinMaxSpeed }); currentSpeed = difficulty[0]; TextDifficulty.text = $"DIFFICULTY: {System.Math.Round(CurrentDifficulty, 2) * 100}"; } } foreach (var item in liveObjects) { item.transform.position -= new Vector3(currentSpeed * Time.fixedDeltaTime, 0, 0); if (item.transform.position.x < xOffscreen) { deadObjects.Add(item); } } if (cleanUp) { deadObjects.AddRange(liveObjects); cleanUp = false; } foreach (var item in deadObjects) { Destroy(item); liveObjects.Remove(item); } deadObjects.Clear(); }
private void Start() { gameManager = GetComponentInParent <MinigameManager>(); rigidbody2d = GetComponent <Rigidbody2D>(); var difficulty = DifficultyAdjuster.SpreadDifficulty( gameManager.Difficulty, new List <Vector2> { MovementSpeedMinMax }); currentSpeed = difficulty[0]; }
private void updateDifficulty() { Difficulty.text = $"DIFFICULTY: {CurrentDifficulty * 100}"; var vectors = new List <Vector2> { FlightSpeedMinMax, SpawnAmountMinMax }; var spread = DifficultyAdjuster.SpreadDifficulty(CurrentDifficulty, vectors); currentFlightSpeed = spread[0]; currentSpawnCount = (int)spread[1]; }
private void createRandomSequence() { for (var i = 0; i < Directions.Length; i++) { var color = Directions[i].color; color.a = Alpha; Directions[i].color = color; } sequenceTimer = 0; waitTimer = 0; // adjust difficulty { var vectors = new List <Vector2> { // reverse because min is hardest, max is easiet new Vector2(TimeInBetweenPlaysMinMax.y, TimeInBetweenPlaysMinMax.x) }; currentTimeInBetweenPlays = DifficultyAdjuster.SpreadDifficulty(DiffCurrent, vectors)[0]; SpeedText.text = $"DIFFICULTY: {Mathf.Round(DiffCurrent * 100)}"; DiffCurrent += DiffIncreaseBy; if (DiffCurrent > 1f) { DiffCurrent = 1; } } var sequence = new List <int>(); for (var i = 0; i < Directions.Length; i++) { sequence.Add(i); } currentSequenceCount = sequence.Count; playersSequenceCount = sequence.Count; sequence.ShuffleList(); currentSequence = new Queue <int>(); playersSequence = new Queue <int>(); foreach (var item in sequence) { currentSequence.Enqueue(item); playersSequence.Enqueue(item); } sequencePlaying = true; ExplainText.text = "Follow Sequence"; }
private void adjustDifficulty() { var vectors = new List <Vector2> { TargetMovementSpeedMinMax, TargetRotationSpeedMinMax, CrosshairMovementSpeedMin, TargetScaleMinMax }; var difficulty = DifficultyAdjuster.SpreadDifficulty( CurrentDifficulty, vectors); Curve.TargetMovementSpeed = difficulty[0]; Curve.TargetRotationSpeed = difficulty[1]; Curve.MovementSpeed = difficulty[2]; Curve.TargetScale = difficulty[3]; }
private void spawnApple() { gameManager.AllowHand = true; followHand = false; fallingApple = true; var vectors = new List <Vector2> { new Vector2(MaxYOffsetMinMax.y, MaxYOffsetMinMax.x), FallSpeedMinMax }; var difficulty = DifficultyAdjuster.SpreadDifficulty(CurrentDifficulty, vectors); var newPosition = new Vector2( SpawnPoint.position.x, SpawnPoint.position.y + difficulty[0]); transform.position = newPosition; rigidbody2d.simulated = true; rigidbody2d.AddForce(Vector2.down * difficulty[1], ForceMode2D.Impulse); }
private void FixedUpdate() { if ((jumpNextString += Time.fixedDeltaTime) > PickJumpRate) { jumpNextString = 0f; if (++pickPositionIndex == Strings.Length) { pickPositionIndex = 0; } Pick.transform.position = new Vector3(Pick.transform.position.x, strings[pickPositionIndex].transform.position.y, 0); } var vectorList = new List <Vector2> { // reverse because it's time and we need it to speed up so it should go lower and lower new Vector2(PickJumprateMinMax.y, PickJumprateMinMax.x) }; PickJumpRate = DifficultyAdjuster.SpreadDifficulty(MinigameManager.DiffCurrent, vectorList)[0]; SoundAttacker.transform.position -= new Vector3(0.1f * AttackerCurrentSpeed, 0, 0); }
private DifficultySetup difficultySetup() { var vectorList = new List <Vector2> { RotationSpeedMinMax, // reverse scale because bigger is easier new Vector2(SpawnSizeMinMax.y, SpawnSizeMinMax.x), // reverse space because bigger space is easier new Vector2(SpawnSpaceInBetweenMinMax.y, SpawnSpaceInBetweenMinMax.x) }; var unparsed = DifficultyAdjuster.SpreadDifficulty(currentDifficulty, vectorList); var newDifficultySetup = new DifficultySetup { RotationSpeed = unparsed[0], Scale = unparsed[1], SpaceInBetween = unparsed[2] }; return(newDifficultySetup); }
private void spawnCar(int amout = 1) { var occupiedSpawnIndex = new List <int>(); for (var i = 0; i < amout; i++) { var randomCarIndex = Random.Range(0, CarPrefabs.Length); int randomSpawnIndex; do { randomSpawnIndex = Random.Range(0, SpawnPoints.Length); } while (occupiedSpawnIndex.Contains(randomSpawnIndex)); occupiedSpawnIndex.Add(randomSpawnIndex); var vectors = new List <Vector2> { CarSpawnOffsetMinMax, CarSpeedMinMax }; var difficulty = DifficultyAdjuster.SpreadDifficulty(CurrentDifficulty, vectors); var spawnPoint = new Vector2( SpawnPoints[randomSpawnIndex].position.x, SpawnPoints[randomSpawnIndex].position.y + difficulty[0]); var newCar = Instantiate( CarPrefabs[randomCarIndex], spawnPoint, Quaternion.identity, transform); newCar.GetComponent <Rigidbody2D>().AddForce(Vector2.down * difficulty[1], ForceMode2D.Impulse); Destroy(newCar, 4.0f); } }
private IEnumerator InitWaves() { level = 1; while (!gm.GameOver) { if (OnNewLevel != null) { OnNewLevel(level); } bool healAvailable = false; int remainingHealCount = DifficultyAdjuster.LevelHealCount[level]; int maxLevelHealCount = remainingHealCount; float targetSpawnTime = potionSpawnTime; if (DifficultyAdjuster.LevelHealCount[level] > 0) { healTimer = 0; healAvailable = true; } else { healTimer = -1; } yield return(new WaitForSeconds(3f)); if (level == 9) { controller.GetComponent <Animator> ().SetBool("moving", false); controller.transform.localScale = new Vector3(-1, controller.transform.localScale.y, controller.transform.localScale.z); controller.enabled = false; doorAnimator.SetTrigger("open"); backgroundSrc.Pause(); yield return(new WaitForSeconds(1f)); boss1.SetActive(true); cannon.SetActive(true); yield return(new WaitForSeconds(1.25f)); doorCloseSrc.Play(); dialogPanel.SetActive(true); Boss1EntryDialog.SetActive(true); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space))); dialogPanel.SetActive(false); Boss1EntryDialog.SetActive(false); controller.enabled = true; backgroundSrc.Play(); controller.enabled = true; yield return(new WaitForSeconds(0.5f)); boss1.GetComponent <HooklegEnemy> ().enabled = true; var boss = boss1.GetComponent <LivingEntity> (); while (boss.IsAlive) { if (healAvailable) { if (healTimer >= targetSpawnTime && remainingHealCount > 0) { //spawn potion var left = potionSpawnHeightTransform.GetChild(0).position.x; var right = potionSpawnHeightTransform.GetChild(1).position.x; Vector3 rPos = new Vector3(Random.Range(left, right), potionSpawnHeightTransform.position.y, potionSpawnHeightTransform.position.z); var p = Instantiate(potionPrefab, rPos, Quaternion.identity); p.GetComponent <Rigidbody2D> ().gravityScale = 0.2f; print(p.transform.position); --remainingHealCount; healTimer = 0; targetSpawnTime = Mathf.Pow(potionSpawnTime, maxLevelHealCount - remainingHealCount + 1); print("next heal spawns after " + targetSpawnTime); } } yield return(null); } boss.GetComponent <Rigidbody2D> ().isKinematic = true; boss.GetComponent <Rigidbody2D> ().velocity = Vector2.zero; dialogPanel.SetActive(true); Boss1ExitDialog.SetActive(true); controller.enabled = false; yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space))); dialogPanel.SetActive(false); Boss1ExitDialog.SetActive(false); controller.enabled = true; yield return(new WaitForSeconds(0.5f)); boss1.SetActive(false); cannon.SetActive(false); if (FindObjectsOfType <CannonBall> () != null) { foreach (var b in FindObjectsOfType <CannonBall> ()) { Destroy(b.gameObject); } } } else if (level == 21) { controller.GetComponent <Animator> ().SetBool("moving", false); controller.transform.localScale = new Vector3(-1, controller.transform.localScale.y, controller.transform.localScale.z); controller.enabled = false; doorAnimator.SetTrigger("open"); backgroundSrc.Stop(); yield return(new WaitForSeconds(.5f)); boss2.SetActive(true); boss2.GetComponent <Animator> ().SetTrigger("door_in"); yield return(new WaitForSeconds(1.5f)); doorCloseSrc.Play(); yield return(new WaitForSeconds(.5f)); dialogPanel.SetActive(true); Boss2EntryDialog.SetActive(true); backgroundSrc.clip = level2Clip; backgroundSrc.Play(); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space))); dialogPanel.SetActive(false); Boss2EntryDialog.SetActive(false); Boss2Slider.SetActive(true); controller.enabled = true; yield return(new WaitForSeconds(0.5f)); boss2.GetComponent <BombThrower> ().enabled = true; var boss = boss2.GetComponent <LivingEntity> (); while (boss.IsAlive) { if (healAvailable) { if (healTimer >= targetSpawnTime && remainingHealCount > 0) { //spawn potion var left = potionSpawnHeightTransform.GetChild(0).position.x; var right = potionSpawnHeightTransform.GetChild(1).position.x; Vector3 rPos = new Vector3(Random.Range(left, right), potionSpawnHeightTransform.position.y, potionSpawnHeightTransform.position.z); var p = Instantiate(potionPrefab, rPos, Quaternion.identity); p.GetComponent <Rigidbody2D> ().gravityScale = 0.2f; print(p.transform.position); --remainingHealCount; healTimer = 0; targetSpawnTime = Mathf.Pow(potionSpawnTime, maxLevelHealCount - remainingHealCount + 1); print("next heal spawns after " + targetSpawnTime); } } yield return(null); } boss.GetComponent <Rigidbody2D> ().velocity = Vector2.zero; dialogPanel.SetActive(true); Boss2ExitDialog.SetActive(true); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space))); dialogPanel.SetActive(false); Boss2ExitDialog.SetActive(false); yield return(new WaitForSeconds(0.5f)); boss2.SetActive(false); } else if (level == 35) { controller.GetComponent <Animator> ().SetBool("moving", false); controller.transform.localScale = new Vector3(-1, controller.transform.localScale.y, controller.transform.localScale.z); controller.enabled = false; doorAnimator.SetTrigger("open"); backgroundSrc.Stop(); yield return(new WaitForSeconds(.5f)); boss3.SetActive(true); boss3.GetComponent <Animator> ().SetTrigger("door_in"); yield return(new WaitForSeconds(1.5f)); doorCloseSrc.Play(); yield return(new WaitForSeconds(.5f)); dialogPanel.SetActive(true); Boss3EntryDialog.SetActive(true); backgroundSrc.clip = level3Clip; backgroundSrc.Play(); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space))); dialogPanel.SetActive(false); Boss3EntryDialog.SetActive(false); Boss3Slider.SetActive(true); controller.enabled = true; yield return(new WaitForSeconds(0.5f)); boss3.GetComponent <FinalBoss> ().enabled = true; var boss = boss3.GetComponent <LivingEntity> (); while (boss.IsAlive) { if (healAvailable) { if (healTimer >= targetSpawnTime && remainingHealCount > 0) { //spawn potion var left = potionSpawnHeightTransform.GetChild(0).position.x; var right = potionSpawnHeightTransform.GetChild(1).position.x; Vector3 rPos = new Vector3(Random.Range(left, right), potionSpawnHeightTransform.position.y, potionSpawnHeightTransform.position.z); var p = Instantiate(potionPrefab, rPos, Quaternion.identity); p.GetComponent <Rigidbody2D> ().gravityScale = 0.2f; print(p.transform.position); --remainingHealCount; healTimer = 0; targetSpawnTime = Mathf.Pow(potionSpawnTime, maxLevelHealCount - remainingHealCount + 1); print("next heal spawns after " + targetSpawnTime); } } yield return(null); } if (!gm.GameOver) { controller.GetComponent <Animator> ().SetBool("moving", false); controller.enabled = false; boss.GetComponent <Rigidbody2D> ().velocity = Vector2.zero; dialogPanel.SetActive(true); Boss3Exit1Dialog.SetActive(true); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space))); Boss3Exit1Dialog.SetActive(false); yield return(new WaitForSeconds(1f)); Boss3Exit2Dialog.SetActive(true); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space))); Boss3Exit2Dialog.SetActive(false); dialogPanel.SetActive(false); backgroundSrc.Stop(); chestKey.transform.parent = null; chestKey.GetComponent <BoxCollider2D> ().enabled = true; chestKey.GetComponent <Rigidbody2D> ().isKinematic = false; chestKey.GetComponent <Rigidbody2D> ().AddForce(Vector2.up * 4.5f, ForceMode2D.Impulse); chestKey.transform.rotation = Quaternion.Euler(Vector3.forward * 60f); backgroundSrc.clip = keyDropClip; backgroundSrc.loop = false; backgroundSrc.Play(); boss3.SetActive(false); yield return(new WaitForSeconds(2f)); controller.enabled = true; //get key while (Mathf.Abs(controller.transform.position.x - chestKey.transform.position.x) > 0.5f) { yield return(null); } controller.enabled = false; controller.GetComponent <Animator> ().SetBool("moving", false); pressEPanel.SetActive(true); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.E))); chestKey.transform.parent = FindObjectOfType <PlayerController> ().transform; chestKey.SetActive(false); pressEPanel.SetActive(false); controller.enabled = true; while (Mathf.Abs(controller.transform.position.x - chest.transform.position.x) > 0.75f) { yield return(null); } controller.enabled = false; controller.GetComponent <Animator> ().SetBool("moving", false); pressEPanel.SetActive(true); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.E))); pressEPanel.SetActive(false); chest.GetComponent <Animator> ().SetTrigger("open"); backgroundSrc.clip = chestOpenClip; backgroundSrc.Play(); gem.SetActive(true); gem.GetComponent <SpriteRenderer> ().sortingOrder = 5; //make the gem bounce up //gem.GetComponent<Rigidbody2D>().AddForce(Vector2.up * 1.5f, ForceMode2D.Impulse); yield return(new WaitForSeconds(.5f)); backgroundSrc.clip = victoryClip; backgroundSrc.loop = true; dialogPanel.SetActive(true); afterVictory1Dialog.SetActive(true); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space))); afterVictory1Dialog.SetActive(false); yield return(new WaitForSeconds(.5f)); afterVictory2Dialog.SetActive(true); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space))); afterVictory2Dialog.SetActive(false); yield return(new WaitForSeconds(.5f)); dialogPanel.SetActive(false); backgroundSrc.Play(); //show some more victory screen popupPanel.SetActive(true); victoryDialog.SetActive(true); yield return(new WaitForSeconds(3f)); popupPanel.SetActive(false); victoryDialog.SetActive(false); creditsAnimator.SetTrigger("fade"); StartCoroutine(ShowCredits()); yield return(new WaitForSeconds(2f)); StopCoroutine(InitWaves()); break; } } else { int dBombCount = DifficultyAdjuster.GetBombCount(level); //int dFoodCount = DifficultyAdjuster.GetFoodCount (level); activeBombs = dBombCount; int count = 0; while (!gm.GameOver && count < activeBombs) { //pick a random window int index = UnityEngine.Random.Range(0, windows.Length); while (index == lastAccessedWindowIndex) { index = UnityEngine.Random.Range(0, windows.Length); } if (healAvailable) { if (healTimer >= targetSpawnTime && remainingHealCount > 0) { //spawn potion var left = potionSpawnHeightTransform.GetChild(0).position.x; var right = potionSpawnHeightTransform.GetChild(1).position.x; Vector3 rPos = new Vector3(Random.Range(left, right), potionSpawnHeightTransform.position.y, potionSpawnHeightTransform.position.z); var p = Instantiate(potionPrefab, rPos, Quaternion.identity); p.GetComponent <Rigidbody2D> ().gravityScale = 0.2f; print(p.transform.position); --remainingHealCount; healTimer = 0; targetSpawnTime = Mathf.Pow(potionSpawnTime, maxLevelHealCount - remainingHealCount + 1); print("next heal spawns after " + targetSpawnTime); } } float val = Random.value; if (val < 0.02f && activeWhales < 2) { var enemyType = FindObjectOfType <WhaleTanker> (); index %= 2; enemyType.GetPath(index); } else { var enemyType = FindObjectsOfType <ShortRangeThrower> ().Where(e => e.GetComponent <WhaleTanker> () == null).ElementAt(0); enemyType.GetPath(index); } ++count; lastAccessedWindowIndex = index; yield return(new WaitForSeconds(2f)); } while (!gm.GameOver && FindObjectsOfType <Bomb> ().Length > 0) { yield return(null); } count = 0; activeBombs = 0; } ++level; if (level == 36) { break; } if (OnLevelCleared != null) { OnLevelCleared(); } yield return(new WaitForSeconds(3f)); yield return(null); } }
protected virtual void GetFuseTime() { onContactExplosionDelay = DifficultyAdjuster.GetBombFuseTime(FindObjectOfType <Spawner> ().Level); }