public void AddPower(PowerUp power) { power.Activate(data); if (!power.isPermanent) { powerups.Add(power); } }
public void UsePowerUp() { if (powerCountInInventory > 0) { powerCountInInventory--; powerUp.Activate(this); } }
private void OnTriggerEnter2D(Collider2D collision) { GameObject other = collision.gameObject; if (collision.CompareTag("Checkpoint")) { respawnPos = other.transform.position; } Star star = other.GetComponent <Star>(); if (star != null) { bool newStar = gm.CollectStar(star); Destroy(other); if (newStar) { audioSrc.PlayOneShot(starCollectSound); } else { audioSrc.PlayOneShot(oldStarCollectSound); } } Portal portal = other.GetComponent <Portal>(); if (portal != null) { gm.ShowHUDPortalStars(portal); portal.TryActivate(); } PowerUp powerUp = other.GetComponent <PowerUp>(); if (powerUp != null) { powerUp.Activate(this); } /*Portal portalCollided = other.GetComponent<Portal>(); * if (portalCollided != null) * { * int starType = (int)gm.levelStarPrefab.GetComponent<Star>().starType; * if (gm.starsCollected[starType] >= portalCollided.starsRequired) * { * NextLevel(); * } * } * * StarSpot starSpot = other.GetComponent<StarSpot>(); * if (starSpot != null && !starSpot.touched) * { * starSpot.Fill(); * }*/ }
public void TryUsePowerUp() { if (_currentPowerUp != null) { _currentPowerUp.Activate(_currentCharacter); _currentPowerUp = null; _timeSinceLastPowerUp = 0; powerUpImage.gameObject.SetActive(false); powerUpCountdown.gameObject.SetActive(true); } }
public void CollectPowerUp(PowerUp powerUpToAdd) { for (int i = 0; i < collectedPowerUp.Length; i++) { if (collectedPowerUp[i] == null) { collectedPowerUp[i] = delegate { powerUpToAdd.Activate(); }; powerUpToAdd.SelfDestruct(); return; } } }
private void Update() { //Update power up if (powerUp != null) { if (status.Input.Fire()) { powerUp.Activate(); } powerUp.UpdateNow(Time.deltaTime); } }
public PowerUp GetPowerUp(GameObject player) { PlayerStatus ps = player.GetComponent <PlayerStatus>(); PowerUp p = Object.Instantiate(powerup) as PowerUp; p.Initialize(player); if (p.immediateActivate) { p.Activate(); } return(p); }
public void ActivatePower(PowerUp power) { if (power.overwriteActive) { foreach (KeyValuePair <string, PowerUp> pu in activePowers) { pu.Value.isFinished = true; } activePowers.Clear(); } // Debug.Log("Applier Activation!"); power.Activate(); if (!power.isFinished) { activePowers.Add(power.powerName, power); } }
void Update() { if (Input.GetKeyDown(KeyCode.E)) { _selectedNumber = (_selectedNumber + 1) % _powerUps.Count; SetCurrent(); } else if (Input.GetKeyDown(KeyCode.R)) { _selectedNumber = (_selectedNumber - 1) % _powerUps.Count; SetCurrent(); } else if (Input.GetKeyDown(KeyCode.Q)) { _selected.Activate(RoundManager.Instance.CurrentUnit); GameManager.GameState.Players[_currentPlayer].RemovePowerUp(_selected); ReloadPowerUps(); } }
public void TriggerPowerup(PowerUp powerUp) { PowerUp similarPowerup = null; switch (powerUp.PowerUpType) { case PowerUpType.Bigger: case PowerUpType.Smaller: similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Bigger || p.PowerUpType == PowerUpType.Smaller).FirstOrDefault(); break; case PowerUpType.Longer: case PowerUpType.Shorter: similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Longer || p.PowerUpType == PowerUpType.Shorter).FirstOrDefault(); break; case PowerUpType.Faster: case PowerUpType.Slower: similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Faster || p.PowerUpType == PowerUpType.Slower).FirstOrDefault(); break; case PowerUpType.Stronger: case PowerUpType.Weaker: similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Stronger || p.PowerUpType == PowerUpType.Weaker).FirstOrDefault(); break; case PowerUpType.Magnetize: similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Magnetize).FirstOrDefault(); break; } if (similarPowerup == null) { PowerUps.Add(powerUp); } else { PowerUps.Remove(similarPowerup); PowerUps.Add(powerUp); } powerUp.Activate(); }
//Reacts differently to different objects public void ProcessHit() { if (gameObject.GetComponent <PlayerControl>()) { lives.DecreaseLives(1); } else if (gameObject.GetComponent <DestructibleBarrier>()) { barrier.Damage(); } else if (gameObject.GetComponent <PowerUp>()) { powerUp.Activate(); Die(); } else { Die(); } }
// For user input to make it snappy. private void Update() { // Don't bother doing anything if they're dead. if (!Alive) { return; } if (Action && powerUp != default) { powerUp.Activate(this); powerUp = default; } desiredDirection = GetInput(); if (desiredDirection == default) { desiredDirection = direction; } if (direction == default) { direction = desiredDirection; } }
public PowerUp GetPowerUp(GameObject player) { PlayerStatus ps = player.GetComponent <PlayerStatus>(); PowerUp[] powerups = firstPowerups; if (GameController.GetPlayerPosition(ps) < 0.5f) { powerups = lastPowerups; } //Check what is players position in game and generates powerup accordingly PowerUp original = powerups[Random.Range(0, powerups.Length)]; PowerUp p = Object.Instantiate(original) as PowerUp; p.Initialize(player); if (p.immediateActivate) { p.Activate(); } return(p); }
/// <summary> /// This method loops over the powerups and checks if they overlaps with the ball. /// If this is the case the powerup is triggered /// </summary> /// <param name="ball">current ball thats being checked</param> /// <param name="players">list of players that play the game</param> /// <param name="powerups">list of powerups that are currently present in the game</param> /// <param name="balls">list of balls currently present in the game</param> public void HandlePowerups(Ball ball, List <Player> players, List <PowerUp> powerups, List <Ball> balls) { //Loop over powerups, activate them if needed for (int i = 0; i < powerups.Count; i++) { PowerUp powerup = powerups[i]; if (OverLap(ball, powerup)) { if (powerup is BombPowerUp && ball.LastHit != null) { List <object> objects = new List <object>(); List <Player> affected = new List <Player>(players); affected.Remove(ball.LastHit); objects.Add(affected); objects.Add(setup.MinHealth); powerup.Activate(objects); } else if (powerup is HealthPowerUp && ball.LastHit != null) { List <object> objects = new List <object>(); objects.Add(ball.LastHit); objects.Add(setup.MaxHealth); powerup.Activate(objects); } else if (powerup is SpeedPowerUp) { powerup.Activate(ball); } else if (powerup is ReversePowerUp && ball.LastHit != null) { List <Player> affected = new List <Player>(players); affected.Remove(ball.LastHit); powerup.Activate(affected); } else if (powerup is MultiBallPowerUp) { List <object> objects = new List <object>(); objects.Add(world); objects.Add(balls); objects.Add(ball); powerup.Activate(objects); } powerups.Remove(powerup); world.Children.Remove(powerup.Shape); } } //update LastHit Rect ballCollisionArea = new Rect { X = ball.X, Y = ball.Y, Width = ball.Diameter, Height = ball.Diameter }; foreach (Player player in players) { Rect r = new Rect { X = player.Beam.X, Y = player.Beam.Y, Width = player.Beam.Width, Height = player.Beam.Height }; if (r.IntersectsWith(ballCollisionArea)) { ball.LastHit = player; break; } } }
private void RefreshPowerUps(PlayerState newState) { //1,2,3 //1,2 //->3 var hadButNoMore = new List <PowerUpType>(CollectedPowerUps.Keys.Except(newState.CollectedPowerUpTypes)); //clone otherwise it will result in out-of-sync //1,2 //1,2,3 //->3 var hasButDidnt = new List <PowerUpType>(newState.CollectedPowerUpTypes.Except(CollectedPowerUps.Keys)); //clone otherwise it will result in out-of-sync foreach (PowerUpType type in hadButNoMore) { GameObject uiImage = GameObject.Find("UIcanvas").transform.Find(type.ToString() + "Image").gameObject; //(by convention we name the image as the powerup tag +"Image", eg GhostImage) uiImage.SetActive(false); CollectedPowerUps.Remove(type); /* * if (StateGroupManager.IsRewinding) * {//time is going backwards and we just lost a powerup. This means that we haven't collected it yet!. So place it * * GameObject go = null; * switch (type) * { * case PowerUpType.DoubleJump: * go= UnityEngine.Object.Instantiate(DoubleJumpPrefab, transform.position , Quaternion.identity); * * * break; * case PowerUpType.Ghost: * go = UnityEngine.Object.Instantiate(GhostPrefab, transform.position , Quaternion.identity); * break; * case PowerUpType.RewindTime: * go = UnityEngine.Object.Instantiate(RewindTimePrefab, transform.position , Quaternion.identity); * break; * } * * go.transform.position = go.transform.position + new Vector3(go.GetComponent<Collider2D>().bounds.extents.x, 0, 0) + new Vector3(this.GetComponent<Collider2D>().bounds.extents.x, 0, 0); * } */ } foreach (PowerUpType type in hasButDidnt) { GameObject uiImage = GameObject.Find("UIcanvas").transform.Find(type.ToString() + "Image").gameObject; //(by convention we name the image as the powerup tag +"Image", eg GhostImage) uiImage.SetActive(true); PowerUp powerup = (PowerUp)Activator.CreateInstance(null, type.ToString() + "PowerUp").Unwrap(); //(by convention we name the class as the powerup tag +"PowerUp", eg GhostPowerUp) CollectedPowerUps.Add(type, powerup); if (StateGroupManager.IsRewinding == false) { //we don't want to activate powerups while rewinding uiImage.GetComponent <AudioSource>().Play(); if (powerup.IsActivatedImmediately) //eg Ghost { powerup.Activate(); } } } }
private void OnTriggerEnter2D(Collider2D collision) { GameObject other = collision.gameObject; if (collision.CompareTag("Checkpoint")) { respawnPos = other.transform.position; } Star star = other.GetComponent <Star>(); if (star != null) { bool newStar = gm.CollectStar(star); Destroy(other); if (newStar) { audioSrc.PlayOneShot(starCollectSound); } else { audioSrc.PlayOneShot(oldStarCollectSound); } } Door door = other.GetComponent <Door>(); if (door != null) { gm.ShowHUDDoorStars(door); door.TryOpen(); } PowerUp powerUp = other.GetComponent <PowerUp>(); if (powerUp != null) { powerUp.Activate(this); } if (other.layer == LayerMask.NameToLayer("Water") && movement is PlayerLand) { //enter swim state movement = new PlayerSwim(this); } /*Portal portalCollided = other.GetComponent<Portal>(); * if (portalCollided != null) * { * int starType = (int)gm.levelStarPrefab.GetComponent<Star>().starType; * if (gm.starsCollected[starType] >= portalCollided.starsRequired) * { * NextLevel(); * } * } * * StarSpot starSpot = other.GetComponent<StarSpot>(); * if (starSpot != null && !starSpot.touched) * { * starSpot.Fill(); * }*/ }