public void ThrowActiveProjectile() { Debug.Log("Projectiles count: " + gloomProjectiles.Count); if (gloomProjectiles.Count > 0) { GloomProjectile activeProjectile = gloomProjectiles[activeIdx]; // Throw projectile activeProjectile.ThrowProjectile(); // Remove from list & destroy projectile gloomProjectiles.RemoveAt(activeIdx); Debug.Log("Projectile thrown! Projectiles remaining: " + gloomProjectiles.Count); // Choose a new active projectile if (gloomProjectiles.Count > 0) { AutoSetActiveProjectile(); } else { activeIdx = -1; } } else { // TODO - Let the user know or make a sound that they don't have any projectiles Debug.Log("You have no projectiles to throw!"); } }
// Update is called once per frame void Update() { #if ENABLE_LEGACY_INPUT_MANAGER // Old input backends are enabled. // If throwing gloom projectile if (Input.GetKeyDown(KeyCode.Space)) { gloomProjectileController.ThrowActiveProjectile(); playerAudio.PlayOneShot(throwSound, 1.0f); } // TODO: if got hit // When player is walking if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position = new Vector2(transform.position.x - 1, transform.position.y); } if (Input.GetKeyDown(KeyCode.RightArrow)) { transform.position = new Vector2(transform.position.x + 1, transform.position.y); } if (Input.GetKeyDown(KeyCode.UpArrow)) { transform.position = new Vector2(transform.position.x, transform.position.y + 1); } if (Input.GetKeyDown(KeyCode.DownArrow)) { transform.position = new Vector2(transform.position.x, transform.position.y - 1); } #endif if (isCharging) { bool meterHasMoreJuice = voidMeter.DecreaseMeter(); float maxPitch = GloomProjectile.MaxGloomPitch(); float minPitch = GloomProjectile.MinGloomPitch(); float currentCharge = voidMeter.GetValue(); float meterMaxValue = voidMeter.GetCapacity(); float meterJuiceObtained = chargeBegValue - currentCharge; float meterJuiceObtainedPercentage = meterJuiceObtained / meterMaxValue; chargingAudio.pitch = Mathf.Clamp(maxPitch - (maxPitch * meterJuiceObtainedPercentage), minPitch, maxPitch); } }
// TODO - use the parameter (% of juice obtained from meter) to set the pitch of the new gloom projectile // Add gloom ands sets position and highlight // Parameter: meterPercent - % of meter used to create gloom public void AddGloom(float meterPercent) { if (activeIdx >= 0) { gloomProjectiles[activeIdx].DeactivateHighlight(); } if (gloomProjectiles.Count < MAX_GLOOM_PROJECTILES) { GameObject gloomObject = Instantiate(gloomPrefab, transform); GloomProjectile gloomProjectile = gloomObject.GetComponent <GloomProjectile>(); gloomProjectile.SetGloomPitch(meterPercent); gloomProjectiles.Add(gloomProjectile); activeIdx = gloomProjectiles.Count - 1; gloomProjectile.ActivateHighlight(); UpdateGloomPositionAndParent(gloomObject); } }