public IEnumerator RotateSpawner(PlayerFireball playerFireball) { yield return(new WaitForSeconds(m_FireballForAllDuration)); m_inProgress = false; m_doneRotation = true; playerFireball.SetCanCast(true); Destroy(m_fireballer); yield return(null); }
public IEnumerator Cast() { PlayerFireball fireballer = m_fireballer.GetComponent <PlayerFireball>(); while (!m_doneRotation) { yield return(new WaitForSeconds(0.2f)); fireballer.FireballTurret(m_player.gameObject); } }
void Update() { if (CameraFollow.lockCamera == 0) //If camera locked { playerMoving = false; //Get input (or lack of it) float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); //Set new player position if the player is moving if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f) { playerMoving = true; lastMove.Set(Input.GetAxisRaw("Horizontal"), 0f); } if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f) { playerMoving = true; lastMove.Set(0f, Input.GetAxisRaw("Vertical")); } //Apply input to animator anim.SetFloat("MoveX", horizontal); anim.SetFloat("MoveY", vertical); anim.SetBool("PlayerMoving", playerMoving); anim.SetFloat("LastMoveX", lastMove.x); anim.SetFloat("LastMoveY", lastMove.y); //Play sound if moving and update position if (playerMoving) { if (!walkingSound.isPlaying) { audio.PlayOneShot(walking); } transform.Translate(horizontal * Time.deltaTime * speed, vertical * Time.deltaTime * speed, 0f); } //Save facing direction to prevDir (used for firing projectiles) Vector2 currentMovement = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); prevDir = (currentMovement.Equals(Vector2.zero)) ? prevDir : currentMovement; if (Input.GetButtonDown("Fire1") && energy > 0) { //Show firing animation anim.SetTrigger("AttackTrigger"); audio.PlayOneShot(fireballSound); PlayerFireball newFireball = Instantiate(fireball, transform.position, Quaternion.identity); newFireball.Dir(prevDir.normalized); //Code to reduce energy goes here energy--; } if (Input.GetButtonDown("Fire2") && energy >= 5) { //Show firing animation anim.SetTrigger("AttackTrigger"); audio.PlayOneShot(fireballSound); //Straight lines for (int i = -1; i <= 1; i += 2) { Instantiate(fireball, transform.position, Quaternion.identity).Dir(new Vector2(i, 0f).normalized); Instantiate(fireball, transform.position, Quaternion.identity).Dir(new Vector2(0f, i).normalized); Instantiate(fireball, transform.position, Quaternion.identity).Dir(new Vector2(i, i).normalized); Instantiate(fireball, transform.position, Quaternion.identity).Dir(new Vector2(i, -i).normalized); } //Code to reduce energy goes here energy -= 5; } if (Input.GetKeyDown(KeyCode.F)) //Health potion using? { if (healthPotions > 0 && health < maxHealth) { audio.PlayOneShot(potionSound); healthPotions--; health++; //Health regen } } } }
public override void Update() { base.Update(); manaRegenTimer += ( float )Game1.currentGameTime.ElapsedGameTime.TotalSeconds; while (manaRegenTimer >= 1) { manaRegenTimer -= 1; if (++mana > manaMax) { mana = manaMax; } } if (immunTimer > 0) { immunTimer = Math.Max(0, immunTimer - (float)Game1.currentGameTime.ElapsedGameTime.TotalSeconds); } if (Game1.input.GetKeyboardState().IsKeyDown(Keys.Space)) { chargeTime += (float)Game1.currentGameTime.ElapsedGameTime.TotalSeconds; if (chargeTime >= 1) { chargeTime = 1; } } else { if (chargeTime > 0) { int tier = ( int )(chargeTime / 0.25f); if (tier >= 1 && mana > tier) { mana -= tier; var speed = (World.cam.target - World.cam.pos) / 4; // * ( -4 + tier ); var proj = new PlayerFireball(World) { Position = new Vector3(Position.X, 0, Position.Z), Speed = new Vector2(speed.X, speed.Z), Level = tier - 1, }; World.projectiles.Add(proj); Game1.playSound("fireball"); } else { Game1.playSound("steam"); } chargeTime = 0; } } foreach (var proj in World.projectiles) { if (proj.Dead) { continue; } if ((proj.BoundingBox + new Vector2(proj.Position.X, proj.Position.Z)).Intersects(BoundingBox + new Vector2(Position.X, Position.Z)) && proj.HurtsPlayer) { proj.Trigger(this); } } if (World.warp != null && (BoundingBox + new Vector2(Position.X, Position.Z)).Intersects(new RectangleF(World.warp.Position.X, World.warp.Position.Z, 1, 1))) { Game1.playSound("wand"); World.QueueNextLevel(); } }