public void GetPowerUp(PowerUpEnum powerUp)
    {
        powerUpSound.Play();

        switch (powerUp)
        {
        case PowerUpEnum.DOUBLE_PUSH:
            _pushCount++;
            if (_pushCount > _maxPushCount)
            {
                _pushCount = _maxPushCount;
            }
            _currentTimeToFinishPowerUpDoublePush = 2f;
            _powerPush = 2;
            UpdatePushPanel();
            break;

        case PowerUpEnum.FAST:
            _currentTimeToFinishPowerUpFast = 2f;
            _animator.speed = _multiplierFast;
            _currentSpeed   = _speedFast;
            break;

        case PowerUpEnum.SLOW:
            _currentTimeToFinishPowerUpSlow = 2f;
            _animator.speed = _multiplierSlow;
            _currentSpeed   = _speedSlow;
            break;
        }
    }
 /// <summary>
 /// Erzeugt ein <c>ActivePowerUp</c>
 /// </summary>
 /// <param name="timeLeft">Die Wirkungsdauer des PowerUps</param>
 /// <param name="type">Art des PowerUps</param>
 /// <param name="apply">Die Funktion, mit der das PowerUps angewendet wird</param>
 /// <param name="remove">Die Funktion, mit der das PowerUps rückgängig gemacht wird</param>
 public ActivePowerUp(float timeLeft, PowerUpEnum type, PowerUpAction apply, PowerUpAction remove)
 {
     this.TimeLeft = timeLeft;
     this.Type     = type;
     this.Apply    = apply;
     this.Remove   = remove;
 }
        public void GeneratePowerUpTest()
        {
            // GameItem-Liste initialisieren
            GameItem.GameItemList = new System.Collections.Generic.LinkedList <IGameItem>();

            // Speedboost PowerUp in die Liste eintragen
            int           frequency = 1000;
            CreatePowerUp create    = delegate(Vector2 pos, Vector2 vel)
            {
                new Speedboost(pos, vel);
            };

            PowerUpGenerator.AddAvailablePowerUp(PowerUpEnum.Speedboost, frequency, create);

            // Passende Parameter initialisieren
            PowerUpEnum type     = PowerUpEnum.Speedboost;
            Vector2     position = Vector2.Zero;

            PowerUpGenerator.GeneratePowerUp(type, position);

            // Überprüfen, ob tatsächlich das gewünschte PowerUp erstellt wurde
            Assert.AreEqual(GameItem.GameItemList.Count, 1);
            Assert.AreEqual(GameItem.GameItemList.First.Value is Speedboost, true);

            // GameItem-Liste zurücksetzen
            GameItem.GameItemList = null;
        }
Example #4
0
        private void SelectPowerUp(PowerUpEnum powerup)
        {
            switch (powerup)
            {
            case PowerUpEnum.Health:
                powerList.Add(Health);
                break;

            case PowerUpEnum.ScatterShot:
                powerList.Add(ScatterShot);
                break;

            case PowerUpEnum.HeavyShot:
                powerList.Add(HeavyShot);
                break;

            case PowerUpEnum.ExtraMovement:
                powerList.Add(ExtraMovement);
                break;

            case PowerUpEnum.Shield:
                powerList.Add(ShieldPower);
                break;
            }
        }
Example #5
0
 void Update()
 {
     if (!assignedType)
     {
         type         = gameObject.transform.parent.gameObject.GetComponent <PowerUpGenerator>().powerUpType;
         assignedType = true;
     }
 }
Example #6
0
 void Update()
 {
     if (!assignedType)
     {
         type = gameObject.transform.parent.gameObject.GetComponent<PowerUpGenerator>().powerUpType;
         assignedType = true;
     }
 }
Example #7
0
        /// <summary>
        /// Diese Methode generiert auf Wunsch ein bestimmtes oder zufälliges <c>PowerUps</c>.
        /// </summary>
        /// <param name="type">Typ des PowerUps</param>
        /// <param name="position">Position, an der das PowerUp erstellt werden soll</param>
        public static void GeneratePowerUp(PowerUpEnum type, Vector2 position)
        {
            Vector2 velocity = GameItemConstants.PowerUpVelocity;

            if (type == PowerUpEnum.Random) // Zufälliges erscheinen eines PowerUps
            {
                double powerUpProbability = GameItemConstants.PowerUpProbability;

                // Erstelle mit vorgegebener Wahrscheinlichkeit ein zufälliges PowerUp
                // Überprüfe ob ein neues PowerUp generiert werden soll, breche ab falls nicht
                double rand = random.NextDouble();
                if (powerUpProbability < rand)
                {
                    return;
                }

                // Erstelle ein zufälliges PowerUp
                int generated = random.Next(frequencySum);
                int offset    = 0;

                foreach (AvailablePowerUp powerUp in availablePowerUps)
                {
                    // Wenn das PowerUp gewürfelt wurde, dann wird es erzeugt und die Schleife abgebrochen
                    if (generated < offset + powerUp.Frequency)
                    {
                        if (powerUp.Create != null)
                        {
                            powerUp.Create(position, velocity);
                        }
                        break;
                    }

                    offset += powerUp.Frequency;
                }
            }
            else
            {
                // Suche das angegebene PowerUp in der Liste
                AvailablePowerUp selected = availablePowerUps.Find(delegate(AvailablePowerUp powerUp)
                {
                    return(type == powerUp.Type);
                });

                // Wenn das PowerUp nicht gefunden wurde, wird eine Exception geworfen
                if (selected == null)
                {
                    throw new Exception("PowerUp nicht in der Liste verfügbarer PowerUps!");
                }

                // Wurde das PowerUp gefunden, dann wird es erzeugt
                if (selected.Create != null)
                {
                    selected.Create(position, velocity);
                }
            }
        }
Example #8
0
 public override void EnterState(PowerUpEnum previousState)
 {
     if (previousState == NORMAL)
     {
         Context.Level.Collider.UpdateLocation(Context);
         Context.PrevPosition -= new Point(0, 16);
         Context.Position     -= new Point(0, 16);
     }
     base.EnterState(previousState);
 }
Example #9
0
 void OnTriggerEnter2D(Collider2D coll)
 {
     if ((coll.gameObject.tag == "Player"))
     {
         if (!assignedType)
         {
             type = gameObject.transform.parent.gameObject.GetComponent<PowerUpGenerator>().powerUpType;
             assignedType = true;
         }
         coll.gameObject.SendMessage("AddPowerUp", type);
         assignedType = false;
         gameObject.SetActive(false);
     }
 }
Example #10
0
 void OnTriggerEnter2D(Collider2D coll)
 {
     if ((coll.gameObject.tag == "Player"))
     {
         if (!assignedType)
         {
             type         = gameObject.transform.parent.gameObject.GetComponent <PowerUpGenerator>().powerUpType;
             assignedType = true;
         }
         coll.gameObject.SendMessage("AddPowerUp", type);
         assignedType = false;
         gameObject.SetActive(false);
     }
 }
Example #11
0
        /// <summary>
        /// Fügt ein PowerUp der Liste hinzu
        /// </summary>
        /// <remarks>
        /// Wenn ein PowerUp nicht zufällig erzeut werden soll, dann muss <c>frequency</c> = 0 gesetzt werden.
        /// Außerdem sollte jede Art von PowerUp nur einmal in der Liste vorkommen.
        /// </remarks>
        /// <param name="type">Typ des PowerUps</param>
        /// <param name="frequency">Häufigkeit des PowerUps, ein absoluter Wert, der in Relation zu anderen PowerUps gesetz sein muss. Standardwert zur Orientierung: 1000</param>
        /// <param name="create">Delegate, dass ein neues PowerUp dieser Art erzeugt</param>
        public static void AddAvailablePowerUp(PowerUpEnum type, int frequency, CreatePowerUp create)
        {
            // Füge das PowerUp der Liste hinzu
            availablePowerUps.Add(new AvailablePowerUp(type, frequency, create));

            // Berechnne die Summe aller PowerUps neu
            int sum = 0;

            foreach (AvailablePowerUp powerUp in availablePowerUps)
            {
                sum += powerUp.Frequency;
            }

            frequencySum = sum;
        }
Example #12
0
        public void addPowerUps()
        {
            Location randomLocation = locationValues[random.Next(locationValues.Length)];

            while (lastLocation == randomLocation)
            {
                randomLocation = locationValues[random.Next(locationValues.Length)];
            }

            SelectLocation(randomLocation);

            PowerUpEnum randomPower = powerUpValues[random.Next(powerUpValues.Length)];

            SelectPowerUp(randomPower);

            lastLocation = randomLocation;
        }
Example #13
0
    //this way player receives info from collision with power up
    public void AddPowerUp(PowerUpEnum en)
    {
        switch (en)
        {
        case PowerUpEnum.Shield:
            isShielded = true;
            SoundManager.instance.PlaySingle(powerupShieldSound);
            break;

        case PowerUpEnum.Heal:
            ApplyHeal(maxHP / 2);
            SoundManager.instance.PlaySingle(powerupHealSound);
            break;

        case PowerUpEnum.Ammo:
            weaponHandling.activeWeapon.reload();
            SoundManager.instance.PlaySingle(powerupAmmoSound);
            break;

        case PowerUpEnum.Speed:
            ApplySpeed(1.5f);
            SoundManager.instance.PlaySingle(powerupSpeedSound);
            break;

        case PowerUpEnum.Mystery:
            System.Random rnd = new System.Random();
            var           v   = Enum.GetValues(typeof(PowerUpEnum));
            AddPowerUp((PowerUpEnum)v.GetValue(rnd.Next(v.Length)));
            break;

        case PowerUpEnum.dealDamage:
            ApplyDamage(maxHP / 3, this);     //hit yourself
            SoundManager.instance.PlaySingle(powerupDealDamageSound);
            break;

        case PowerUpEnum.slowSpeed:
            ApplySlow(-1.0f);
            SoundManager.instance.PlaySingle(powerupSlowSpeedSound);
            break;

        default:
            Debug.Log("ERROR: Unknown powerUp received.");
            break;
        }
    }
Example #14
0
    public void SpawnPowerUp()
    {
        var v = Enum.GetValues(typeof(PowerUpEnum));
        int i = UnityEngine.Random.Range(0, countOfPrefabedPowerUps);
        powerUpType = (PowerUpEnum)v.GetValue(i);

        for (int j = 0; j < pooledAmount; j++)
        {
            if (!powerUps[i][j].activeInHierarchy)
            {
                powerUps[i][j].transform.position = posGenerator.GenerateRandomPosition();
                powerUps[i][j].SetActive(true);
                break;
            }
        }

        SoundManager.instance.PlaySingle(itemSpawnSound);
    }
Example #15
0
    public void SpawnPowerUp()
    {
        var v = Enum.GetValues(typeof(PowerUpEnum));
        int i = UnityEngine.Random.Range(0, countOfPrefabedPowerUps);

        powerUpType = (PowerUpEnum)v.GetValue(i);

        for (int j = 0; j < pooledAmount; j++)
        {
            if (!powerUps[i][j].activeInHierarchy)
            {
                powerUps[i][j].transform.position = posGenerator.GenerateRandomPosition();
                powerUps[i][j].SetActive(true);
                break;
            }
        }

        SoundManager.instance.PlaySingle(itemSpawnSound);
    }
Example #16
0
    private void OnPowerUp(PowerUpEnum type)
    {
        switch (type)
        {
        case PowerUpEnum.BallSlowDown:
            rigidbody2D.velocity /= 2;
            break;

        case PowerUpEnum.BallSpeedUp:
            rigidbody2D.velocity *= 2;
            break;

        case PowerUpEnum.PaddleLargeDown:
            lastPlayer.OnLargeDown();
            break;

        case PowerUpEnum.PaddleLargeUp:
            lastPlayer.OnLargeUp();
            break;
        }
        StartCoroutine(OnPowerUpExpire(type, lastPlayer));
    }
        /// <summary>
        /// Fügt der Liste der aktiven PowerUps ein neues PowerUp hinzu. Dabei wird das <c>Apply</c>-Delegate des übegebenen <c>ActivePowerUp</c>s ausgelöst.
        /// </summary>
        /// <remarks>
        /// Wenn bereits ein gleiches <c>ActivePowerUp</c> in der Liste ist, wird dieses gelöscht ohne das <c>Remove-</c>Delegate auszulösen.
        /// Für weitere Informationen sollten unbedingt die Hinweise zur PowerUps-Liste <c>ActivePowerUps</c> beachtet werden.
        /// </remarks>
        /// <param name="powerUp">Das neue PowerUp</param>
        public void AddPowerUp(ActivePowerUp powerUp)
        {
            // Wenn ein gleiches PowerUp in der Liste ist, wird dieses gelöscht
            PowerUpEnum newType = powerUp.Type;

            ActivePowerUps.RemoveAll(delegate(ActivePowerUp p)
            {
                return(p.Type == newType);
            });

            // Wenn das PowerUp ein Waffen-PowerUp ist, dann müssen alle anderen Waffen-PowerUps
            // aus der Liste entfernt werden, damit immer nur ein Waffen-PowerUp aktiv ist.
            if ((powerUp.Type == PowerUpEnum.MultiShot) ||
                (powerUp.Type == PowerUpEnum.PiercingShot) ||
                (powerUp.Type == PowerUpEnum.Rapidfire))
            {
                ActivePowerUps.RemoveAll(delegate(ActivePowerUp p)
                {
                    if ((p.Type == PowerUpEnum.MultiShot) ||
                        (p.Type == PowerUpEnum.PiercingShot) ||
                        (p.Type == PowerUpEnum.Rapidfire))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
            }

            // Das neue PowerUp wird hinzugefügt und dessen Apply-Delegate ausgeführt
            ActivePowerUps.Add(powerUp);
            if (powerUp.Apply != null)
            {
                powerUp.Apply(this);
            }
        }
Example #18
0
    private IEnumerator OnPowerUpExpire(PowerUpEnum type, Player player)
    {
        yield return(new WaitForSeconds(Global.powerUpLifetime[type]));

        switch (type)
        {
        case PowerUpEnum.BallSlowDown:
            rigidbody2D.velocity *= 2;
            break;

        case PowerUpEnum.BallSpeedUp:
            rigidbody2D.velocity /= 2;
            break;

        case PowerUpEnum.PaddleLargeDown:
            player.OnLargeExpire();
            break;

        case PowerUpEnum.PaddleLargeUp:
            player.OnLargeExpire();
            break;
        }
    }
Example #19
0
        private void SelectPowerUp(PowerUpEnum powerup)
        {
            switch (powerup)
            {
                case PowerUpEnum.Health:
                    powerList.Add(Health);
                    break;

                case PowerUpEnum.ScatterShot:
                    powerList.Add(ScatterShot);
                    break;

                case PowerUpEnum.HeavyShot:
                    powerList.Add(HeavyShot);
                    break;

                case PowerUpEnum.ExtraMovement:
                    powerList.Add(ExtraMovement);
                    break;

                case PowerUpEnum.Shield:
                    powerList.Add(ShieldPower);
                    break;
            }
        }
Example #20
0
 private void Start()
 {
     powerUpType = (PowerUpEnum)Random.Range(0, 4);
 }
Example #21
0
        public Level2Beginning(MarioGame game, string levelFolder, Vector2 respawnPosition, PowerUpEnum powerUp) : base(game, levelFolder, respawnPosition, powerUp)
        {
            Mario.Velocity = new Vector2(1, 0);
            Mario.ActionStates.CurrentState = ActionEnum.WALKING;
            Sprite s = Mario.Sprite.Clone();

            Mario.Commands += new Command[]
            {
                new Wait()
                .Until(e => e.CollidingWith.Any(b => b.entity is BlockEntity block && block.BlockStates.CurrentState == States.PipeSide)),
                new MethodCall <IEntity>((e) => s.Layer = 0.4f),
                new Move(0.6f, 0).Repeat(16),
                new MethodCall <IEntity>((e) => GoToNextLevel())
            };
            Mario.Commands += new Command[]
            {
                new SetSprite(s).Repeat(1000)
            };
        }
Example #22
0
 public void AddLevel(string level, Vector2 respawnPosition, PowerUpEnum powerUp, bool appearing)
 {
     AddLevel(LevelFactory.LoadLevel(this, level, respawnPosition, powerUp), appearing);
 }
Example #23
0
 public void AddLevel(string levelFolder, PowerUpEnum powerUp, bool appearing)
 {
     AddLevel(levelFolder, Vector2.Zero, powerUp, appearing);
 }
Example #24
0
 public void AddLevel(string levelFolder, PowerUpEnum powerUp) => AddLevel(levelFolder, powerUp, true);
Example #25
0
 public static Level LoadLevel(MarioGame game, string levelFolder, Vector2 respawnPosition, PowerUpEnum powerUp)
 {
     if (creators.ContainsKey(levelFolder))
     {
         return(creators[levelFolder](game, levelFolder, respawnPosition, powerUp));
     }
     return(new Level(game, levelFolder, respawnPosition, powerUp));
 }
Example #26
0
 /// <summary>
 /// Konstruktor
 /// </summary>
 /// <param name="type">Typ des PowerUps</param>
 /// <param name="frequency">Häufigkeit des PowerUps</param>
 /// <param name="create">Delegate, mit dem ein neues PowerUp der angegeben Art erzeugt werden kann</param>
 public AvailablePowerUp(PowerUpEnum type, int frequency, CreatePowerUp create)
 {
     this.Type      = type;
     this.Frequency = frequency;
     this.Create    = create;
 }
Example #27
0
 //this way player receives info from collision with power up
 public void AddPowerUp(PowerUpEnum en)
 {
     switch (en)
     {
         case PowerUpEnum.Shield:
             isShielded = true;
             SoundManager.instance.PlaySingle(powerupShieldSound);
             break;
         case PowerUpEnum.Heal:
             ApplyHeal(maxHP / 2);
             SoundManager.instance.PlaySingle(powerupHealSound);
             break;
         case PowerUpEnum.Ammo:
             weaponHandling.activeWeapon.reload();
             SoundManager.instance.PlaySingle(powerupAmmoSound);
             break;
         case PowerUpEnum.Speed:
             ApplySpeed(1.5f);
             SoundManager.instance.PlaySingle(powerupSpeedSound);
             break;
         case PowerUpEnum.Mystery:
             System.Random rnd = new System.Random();
             var v = Enum.GetValues(typeof(PowerUpEnum));
             AddPowerUp((PowerUpEnum)v.GetValue(rnd.Next(v.Length)));
             break;
         case PowerUpEnum.dealDamage:
             ApplyDamage(maxHP / 3, this); //hit yourself
             SoundManager.instance.PlaySingle(powerupDealDamageSound);
             break;
         case PowerUpEnum.slowSpeed:
             ApplySlow(-1.0f);
             SoundManager.instance.PlaySingle(powerupSlowSpeedSound);
             break;
         default:
             Debug.Log("ERROR: Unknown powerUp received.");
             break;
     }
 }