/// <summary> /// Change scene if conditions are met. /// </summary> /// <returns></returns> public bool GoNextLevel() { if (!GameObject.FindWithTag("Enemy")) { if (gotoShop) { SceneManager.GetInstance().ChangeScene(shopScene, true); } else { if (nextLevel.Equals("")) { PersistanceManager.GetInstance().currentLevel++; SceneManager.GetInstance().ChangeScene(GetNextLevel(), true); } else { // Manual level change SceneManager.GetInstance().ChangeScene(nextLevel, true); } } return(true); } else { return(false); } }
/// <summary> /// Update UI and check for game state /// </summary> void Update() { // Update healthbar if (healthbar) { healthbar.value = player.hitpoints; healthbar.maxValue = player.hitpointsMax; healthbarRect.sizeDelta = new Vector2(player.hitpointsMax * 30, healthbarRect.sizeDelta.y); } // Update coins text coinText.SetText("" + player.coins); // Update score text scoreText.SetText(System.String.Format("{0:000000}", PersistanceManager.GetInstance().playerScore)); // Check for player death if (player.hitpoints <= 0 && !changingScene) { // Save stats and go to death screen PersistanceManager.GetInstance().ResetPlayerScore(); PersistanceManager.GetInstance().ResetPlayerStats(); SceneManager.GetInstance().ChangeScene("Death Screen", true); changingScene = true; } }
/// <summary> /// Load AudioClips to SoundManager and apply persistance to the player /// </summary> public virtual void Start() { // Load AudioClips SoundManager.GetInstance().Load(hurtClip); SoundManager.GetInstance().Load(slideClip); SoundManager.GetInstance().Load(attackClip); SoundManager.GetInstance().Load(coinClip); // Retrive persistent player data and load it PersistanceManager persistanceManager = PersistanceManager.GetInstance(); UpdateStats(); isAlive = true; if (!persistanceManager.playerAlive) { persistanceManager.playerAlive = true; persistanceManager.playerHealth = hitpointsMax; hitpoints = hitpointsMax; coins = 0; } else { hitpoints = persistanceManager.playerHealth; coins = persistanceManager.playerCoins; } // Add player to AI pathfiding system LevelManager.GetInstance().AddDynamicGenerator(this); }
/// <summary> /// Update UI position of the controls to reflect the control scheme /// </summary> public void UpdateControlScheme() { switch (PersistanceManager.GetInstance().controlScheme) { case 0: { cmdPad.transform.rotation = Quaternion.identity; movePad.transform.rotation = Quaternion.identity; } break; case 2: { Quaternion rot = Quaternion.AngleAxis(45, Vector3.forward); cmdPad.transform.rotation = rot; movePad.transform.rotation = rot; } break; case 1: { Quaternion rot = Quaternion.AngleAxis(-45, Vector3.forward); cmdPad.transform.rotation = rot; movePad.transform.rotation = rot; } break; } }
void Start() { #if UNITY_STANDALONE_WIN Screen.SetResolution(896, 504, false); #endif scoreNumber.SetText(System.String.Format("{0:000000}", PersistanceManager.GetInstance().GetMaxScore())); PersistanceManager.GetInstance().ResetPlayerScore(); PersistanceManager.GetInstance().ResetPlayerStats(); }
/// <summary> /// Update shop UI to reflect the current selected item, aviability and price /// </summary> public void UpdateShop() { PersistanceManager pm = PersistanceManager.GetInstance(); // Deactivate all items images for (int i = 0; i < imagesItems.Length; i++) { imagesItems[i].SetActive(false); } // Show selected item image and description imagesItems[selectedItemIndex].SetActive(true); switch (selectedItemIndex) { case 0: // Refill health textArticleName.SetText("Health Potion"); textArticleDescription.SetText("110% organic remedy. Don't ask for the 10%"); textArticlePrice.SetText("x2"); imageSoldout.SetActive(false); break; case 1: // Health upgrade textArticleName.SetText("Health Upgrade"); textArticleDescription.SetText("Found it floating somewhere and decided to sell it."); textArticlePrice.SetText("x" + GetNextLevelPrice(pm.playerStatHealth)); imageSoldout.SetActive(pm.playerStatHealth >= 5); break; case 2: // Strength upgrade textArticleName.SetText("Attack Upgrade"); textArticleDescription.SetText("The best defense is not having who to fight you."); textArticlePrice.SetText("x" + GetNextLevelPrice(pm.playerStatStrength)); imageSoldout.SetActive(pm.playerStatStrength >= 5); break; case 3: // Speed upgrade textArticleName.SetText("Speed Upgrade"); textArticleDescription.SetText("Bebrage imported from far lands. It surely makes you go faster."); textArticlePrice.SetText("x" + GetNextLevelPrice(pm.playerStatSpeed)); imageSoldout.SetActive(pm.playerStatSpeed >= 5); break; case 4: // Tenacity upgrade textArticleName.SetText("Tenacity Upgrade"); textArticleDescription.SetText("Pants ready for rough jobs. Not fit for square bodies."); textArticlePrice.SetText("x" + GetNextLevelPrice(pm.playerStatTenacity)); imageSoldout.SetActive(pm.playerStatTenacity >= 5); break; case 5: // Luck upgrade textArticleName.SetText("Luck Upgrade"); textArticleDescription.SetText("It's fake, but has to be useful for something, right?"); textArticlePrice.SetText("x" + GetNextLevelPrice(pm.playerStatLuck)); imageSoldout.SetActive(pm.playerStatLuck >= 5); break; } }
/// <summary> /// Creates an object list for each spawner and fills them based on the calculated difficulty points and the difficulty value of each enemy in the catalogue. /// Stops filling the lists when the available difficulty points are less than the minimum value of all enemies. /// </summary> /// <returns></returns> private List <GameObject>[] ChooseSequence() { // Get the available difficulty points float targetNumber = diffBase + PersistanceManager.GetInstance().currentLevel *diffDelta + waveProgress * (diffIncreaseBase + diffIncreaseDelta * PersistanceManager.GetInstance().currentLevel); // Get the minimum value of all enemies float minBudget = float.MaxValue; for (int i = 0; i < enemyCatalogue.catalogue.Length; i++) { if (enemyCatalogue.catalogue[i].minTier <= PersistanceManager.GetInstance().currentLevel) { if (enemyCatalogue.catalogue[i].score < minBudget) { minBudget = enemyCatalogue.catalogue[i].score; } } } // Create the lists for each spawner List <GameObject>[] sequence = new List <GameObject> [spawners.Length]; for (int i = 0; i < spawners.Length; i++) { sequence[i] = new List <GameObject>(); } // Infinite loop exit int margin = 1000; // Fill object lists int spawnerIndex = 0; float budget = targetNumber; while (budget >= minBudget) { // Check for random enemy int enemy = Random.Range(0, enemyCatalogue.catalogue.Length); if (enemyCatalogue.catalogue[enemy].minTier <= PersistanceManager.GetInstance().currentLevel&& enemyCatalogue.catalogue[enemy].score <= budget) { budget -= enemyCatalogue.catalogue[enemy].score; sequence[spawnerIndex].Add(enemyCatalogue.catalogue[enemy].enemyPrefab); spawnerIndex = (spawnerIndex + 1) % spawners.Length; margin = 1000; } else { margin--; } if (margin <= 0) { break; } } return(sequence); }
/// <summary> /// Load statistics from persistance /// </summary> public void UpdateStats() { PersistanceManager persistanceManager = PersistanceManager.GetInstance(); hitpointsMax = baseHitpoints + persistanceManager.playerStatHealth; speed = baseSpeed + persistanceManager.playerStatSpeed * 4f / 5; dodgeTime = baseDodgeTime - persistanceManager.playerStatSpeed * .3f / 5; slideTime = baseSlideTime - persistanceManager.playerStatSpeed * 2f / 5; attackDamage = baseAttackDamage + persistanceManager.playerStatStrength * 2.5f / 5; pushForce = basePushForce + persistanceManager.playerStatStrength * 2; launchDrag = baseLaunchDrag - persistanceManager.playerStatTenacity * .6f / 5; }
/// <summary> /// Death logic /// </summary> public void OnDestroy() { // Save player score PersistanceManager.GetInstance().playerCoins = coins; LevelManager lm = LevelManager.GetInstance(); if (lm != null && this != null) { lm.RemoveDynamicGenerator(this); } }
/// <summary> /// Call the death of the enemy and give player rewards. /// </summary> public virtual void Kill() { // Adds points to the player score. PersistanceManager.GetInstance().AddPlayerScore(stats.scoreValue); // Generate items based on the drop list. float randomBonus = 1 + PersistanceManager.GetInstance().playerStatLuck *2f / 5; while (randomBonus > 0) { if (randomBonus >= 1) { DropListScriptableObject.DropChoice dropChoice = dropList.GetRandomChoice(); for (int i = 0; i < dropChoice.drops.Length; i++) { GameObject obj = Instantiate(dropChoice.drops[i], transform.position, Quaternion.identity); Rigidbody rb = obj.GetComponent <Rigidbody>(); if (rb != null) { rb.AddExplosionForce(100, transform.position + Random.onUnitSphere.normalized, 10); } } randomBonus--; } else { if (Random.Range(0f, 1f) <= randomBonus) { DropListScriptableObject.DropChoice dropChoice = dropList.GetRandomChoice(); for (int i = 0; i < dropChoice.drops.Length; i++) { GameObject obj = Instantiate(dropChoice.drops[i], transform.position, Quaternion.identity); Rigidbody rb = obj.GetComponent <Rigidbody>(); if (rb != null) { rb.AddForce(Random.onUnitSphere * Random.Range(0f, 1f)); } } } randomBonus = 0; } } // Show death FX particles. if (deathParticlesPrefab) { GameObject deathParticles = PoolManager.poolManager.GetPoolInstance(deathParticlesPrefab); deathParticles.transform.position = transform.position; deathParticles.GetComponent <IPoolable>().Init(); } Destroy(gameObject); }
/* * Return true if request was successful */ private bool SendAndOutput(String url, String method, String data, String tenantId, Dictionary <string, string> headers) { Dictionary <string, string> newHeaders = new Dictionary <string, string>(); List <String> keys = new List <String>(headers.Keys); foreach (String key in keys) { newHeaders[key] = replaceParameters(headers[key]); } HttpWebResponse response = null; String output; String outputStatus; try { response = Send(url, tenantId, method, data, newHeaders); using (var streamReader = new StreamReader(response.GetResponseStream())) { output = streamReader.ReadToEnd(); } outputStatus = response.StatusCode.ToString(); SetOutput(outputStatus, output); } catch (WebException ex) { output = ex.Message; outputStatus = "Failed"; SetOutput(outputStatus, output); if (ex.Response != null) { using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) { String errorMessage = reader.ReadToEnd(); richConsole.AppendText("\n"); richConsole.AppendText(errorMessage); } } } PersistanceManager.GetInstance().SaveToLog(m_sharedData.ConnectedUser, tenantId, url, method, m_headers, data, outputStatus, output); return(outputStatus != "Failed");; }
/// <summary> /// Select the next scene from a random scene list, taking into account the difficulty level /// </summary> /// <returns></returns> public string GetNextLevel() { int currentLevel = PersistanceManager.GetInstance().currentLevel; List <string> selectableLevels = new List <string>(); for (int i = 0; i < levelCatalogue.entries.Length; i++) { if ((levelCatalogue.entries[i].minTier == -1 || levelCatalogue.entries[i].minTier <= currentLevel) && (levelCatalogue.entries[i].maxTier == -1 || levelCatalogue.entries[i].maxTier >= currentLevel)) { selectableLevels.AddRange(levelCatalogue.entries[i].scenes); } } if (selectableLevels.Count == 0) { return(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name); } return(selectableLevels[Random.Range(0, selectableLevels.Count)]); }
/// <summary> /// The entity takes damage from an unknown source. /// </summary> /// <param name="damage">Ammount of damage to be taken.</param> /// <param name="direction">Incoming damage direction. Axis represented in clockwise order: 0-Forward, 1-Left, 2-Back, 3-Right.</param> /// <param name="pushForce">Force applied to the entity in the specified direction.</param> /// <param name="stunForce">Stun duration applied to the entity.</param> /// <returns>True if enemy was damaged, otherwise false.</returns> public bool Damage(float damage = 0, int direction = 0, float pushForce = 0, float stunForce = 0) { if (isActive && isAlive && !isDespawning) { // Check invencibility if (moveMode != MoveMode.Launched) { // Play sound SoundManager.GetInstance().Play(hurtClip); // Apply damage AddHealth(-damage); // Create floating number effect FloatingNumberController fnc = PoolManager.poolManager.GetPoolInstance(floatingNumberPrefab).GetComponent <FloatingNumberController>(); fnc.number = -(int)damage; fnc.textColor = Color.red; fnc.transform.position = transform.position + Vector3.up * .5f + Vector3.right * UnityEngine.Random.Range(-.1f, .1f) + Vector3.forward * UnityEngine.Random.Range(-.1f, .1f); fnc.Init(); // Apply push if (pushForce > 0) { moveMode = MoveMode.Launched; launchVelocity = Quaternion.AngleAxis(-90 * direction, Vector3.up) * Vector3.forward * pushForce; } // Check for death if (hitpoints <= 0) { PersistanceManager.GetInstance().playerAlive = false; isAlive = false; animator.SetTrigger("Death"); return(true); } } } return(false); }
/// <summary> /// Add coins to the player statistics /// </summary> /// <param name="value">The ammount of coins to add</param> public void AddCoins(int value) { coins += value; PersistanceManager.GetInstance().playerCoins = coins; }
/// <summary> /// Add hit points to the player health /// </summary> /// <param name="value">Ammount of hitpoints to add</param> public void AddHealth(float value) { hitpoints = Mathf.Min(hitpoints + value, hitpointsMax); PersistanceManager.GetInstance().playerHealth = hitpoints; }
public void SetControlScheme(int mode) { PersistanceManager.GetInstance().controlScheme = mode; }
/// <summary> /// Buy the selected item /// </summary> public void BuySelectedItem() { PersistanceManager pm = PersistanceManager.GetInstance(); PlayerController player = GameObject.FindWithTag("Player").GetComponent <PlayerController>(); switch (selectedItemIndex) { case 0: // Refill health if (player.hitpoints < player.hitpointsMax && player.coins >= 2) { player.AddCoins(-2); player.AddHealth(1); SoundManager.GetInstance().Play(purchaseClip); } else { SoundManager.GetInstance().Play(errorClip); } break; case 1: // Health upgrade if (pm.playerStatHealth < 5 && player.coins >= GetNextLevelPrice(pm.playerStatHealth)) { player.AddCoins(-GetNextLevelPrice(pm.playerStatHealth)); pm.playerStatHealth++; player.UpdateStats(); player.AddHealth(1); SoundManager.GetInstance().Play(purchaseClip); } else { SoundManager.GetInstance().Play(errorClip); } break; case 2: // Strength upgrade if (pm.playerStatStrength < 5 && player.coins >= GetNextLevelPrice(pm.playerStatStrength)) { player.AddCoins(-GetNextLevelPrice(pm.playerStatStrength)); pm.playerStatStrength++; player.UpdateStats(); SoundManager.GetInstance().Play(purchaseClip); } else { SoundManager.GetInstance().Play(errorClip); } break; case 3: // Speed upgrade if (pm.playerStatSpeed < 5 && player.coins >= GetNextLevelPrice(pm.playerStatSpeed)) { player.AddCoins(-GetNextLevelPrice(pm.playerStatSpeed)); pm.playerStatSpeed++; player.UpdateStats(); SoundManager.GetInstance().Play(purchaseClip); } else { SoundManager.GetInstance().Play(errorClip); } break; case 4: // Tenacity upgrade if (pm.playerStatTenacity < 5 && player.coins >= GetNextLevelPrice(pm.playerStatTenacity)) { player.AddCoins(-GetNextLevelPrice(pm.playerStatTenacity)); pm.playerStatTenacity++; player.UpdateStats(); SoundManager.GetInstance().Play(purchaseClip); } else { SoundManager.GetInstance().Play(errorClip); } break; case 5: // Luck upgrade if (pm.playerStatLuck < 5 && player.coins >= GetNextLevelPrice(pm.playerStatLuck)) { player.AddCoins(-GetNextLevelPrice(pm.playerStatLuck)); pm.playerStatLuck++; player.UpdateStats(); SoundManager.GetInstance().Play(purchaseClip); } else { SoundManager.GetInstance().Play(errorClip); } break; } UpdateShop(); }
/// <summary> /// Initiate values and start sending enemy waves. /// /// </summary> public void Start() { waveNumber = waveBase + waveDelta * PersistanceManager.GetInstance().currentLevel; SendWaves(); }