void OnTriggerEnter2D(Collider2D collider) { if (collider.CompareTag("Enemy")) { if (!invincible) { Die(); } } else if (collider.CompareTag("Pickup")) { SFXHandler.PlaySound("item_generic"); Pickup pickup = collider.GetComponent <Pickup>(); switch (pickup.type) { case PickupType.Point: float multiplier = (pickup.fixedScore == 0) ? pickup.GetScore() : pickup.fixedScore; AddScore((uint)Mathf.RoundToInt(pickup.value * multiplier)); break; case PickupType.Power: ChangePower(power + 0.03f * pickup.value); break; } } }
// Actions private void Die() { Vector3 deathPos = transform.position; // Move to spawn, stop controls and become invincible SFXHandler.PlaySound("playerdeath"); StartCoroutine(DeathVisualEffect(1f, .6f, 80f, deathPos)); StartCoroutine(Invincibility(3f)); StartCoroutine(Paralyze(.3f)); transform.position = startPos; // Lose 35% of power and drop 30% // Drops power above death position DropPower(deathPos, power * 0.30f); ChangePower(power * 0.65f); // Kill bullets BulletHandler.BulletsToScore(); if (lives > 0) { lives--; Score.UpdatePlayer(lives); } else { // Pause and disable resuming on game over PauseMenu.TogglePause(PauseMode.GameOver); Debug.Log("Game Over"); } }
void Update() { if (hasAi && StageHandler.InStageBounds(transform.position)) { if (!ai.inBounds) { ai.nextFire = Time.time; ai.inBounds = true; } } else { ai.inBounds = false; } if (hitOnFrame) { SFXHandler.PlaySound("enemyhit_loop", true); hitOnFrame = false; } else { SFXHandler.StopSound("enemyhit_loop"); } }
public void Die() { // Don't accidentally spawn multiple pickups if (!dead) { dead = true; // Play death sound SFXHandler.PlaySound("enemydeath"); // Spawn pickups while (scoreValue > 0 && powerValue > 0) { if (scoreValue > 0) { StageHandler.SpawnPickup(0, transform.position, (Vector2)transform.position + (Random.insideUnitCircle + Vector2.up) * .5f, .2f); scoreValue--; } if (powerValue > 0) { StageHandler.SpawnPickup(1, transform.position, (Vector2)transform.position + (Random.insideUnitCircle + Vector2.up) * .5f, .2f); powerValue--; } } // Destroy object Destroy(gameObject); } }
public override void Shoot() { SFXHandler.PlaySound("enemyshot"); bulletData.pos = transform.position; bulletData.rot = BulletHandler.AngleToPlayer(transform.position); BulletHandler.ShootBullet(bulletData); }
private void Bomb() { if (bombs > 0) { bombs--; Score.UpdateBombs(bombs); // Start bomb visual, audio and "physical" effects SFXHandler.PlaySound("bomb"); StartCoroutine(ScaleRotateEffect(3f, .8f, 80f, bombEffect)); StartCoroutine(BombEffect(.6f)); } }
public override void Shoot() { SFXHandler.PlaySound("burstshot"); bulletData.pos = transform.position; bulletData.rot = BulletHandler.AngleToPlayer(transform.position); StartCoroutine(BulletHandler.ShootBurst( bulletData, burstSpread, burstCount, burstTime )); }
// Update power value public void ChangePower(float newPower, bool silent = false) { newPower = Mathf.Clamp(newPower, 0f, 5f); if (Mathf.FloorToInt(newPower) > Mathf.FloorToInt(power) && !silent) { SFXHandler.PlaySound("powerup"); } power = newPower; Score.UpdatePower(newPower); damage = Mathf.Lerp(1f, 5f, newPower / 5); UpdateOrb(Mathf.Clamp(Mathf.FloorToInt(newPower), 0, 4)); }
void Update() { // Handle controls focus = Input.GetButton("Focus"); focusHitbox.enabled = focus; Orb.radius = focus ? .4f : .6f; shooting = Input.GetButton("Shoot"); // Reset fire timer and play shooting sound if (Input.GetButtonDown("Shoot")) { SFXHandler.PlaySound("generic_shot", true); nextFire = Time.time; } if (Input.GetButtonUp("Shoot")) { SFXHandler.StopSound("generic_shot"); } if (Input.GetButtonDown("Bomb")) { Bomb(); } // Movement movement = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); movement.Normalize(); movement *= focus ? focusMovementSpeed : movementSpeed; // Animation if (paralyzed) { anim.SetFloat("Horizontal", 0); anim.SetBool("Moving", false); } else { anim.SetFloat("Horizontal", movement.x); anim.SetBool("Moving", movement.x != 0); } }
public void OnSelect(BaseEventData eventData) { SFXHandler.PlaySound("generic_shot"); }
public void OnCancel(BaseEventData eventData) { EventSystem.current.SetSelectedGameObject(cancelObject); SFXHandler.PlaySound("hit"); }
public void OnSubmit(BaseEventData eventData) { buttonHandler.HandleButton(name); SFXHandler.PlaySound("shot_special1"); }