Exemple #1
0
        public void update(GameTime gameTime)
        {
            List <Entity> tmp = new List <Entity>();

            for (int i = entities.Count - 1; i >= 0; --i)
            {
                entities.ElementAt(i).update(gameTime);
                Projectiles p = entities[i].shoot();
                if (p != null)
                {
                    tmp.Add(p);
                }
                for (int j = i + 1; j < entities.Count; ++j)
                {
                    Team teamI = entities[i].Team;
                    Team teamJ = entities[j].Team;

                    if (teamI == Team.Neutral || teamI != teamJ)
                    {
                        bool collides = entities[i].collide(entities[j]);
                        if (collides)
                        {
                            if (i == 0 && entities[j].getEntityType() == EntityType.EnemyBreeder)
                            {
                            }
                            entities[i].Hp -= entities[j].Damage;
                            entities[j].Hp -= entities[i].Damage;

                            if (entities[i].getEntityType() == EntityType.Player && entities[j].getEntityType() == EntityType.Letter)
                            {
                                ((Player)entities[i]).addLetter(entities[j].Name);
                                entities[j].canExplode = false;
                            }
                        }
                    }
                }
                // Spezialbehandlung für einige klassen
                EntityType type = entities.ElementAt(i).getEntityType();
                switch (type)
                {
                case EntityType.EnemyBreeder:
                    Breeder bre = (Breeder)entities.ElementAt(i);
                    if (bre.ReadyToSpawn)
                    {
                        float   alpha = (float)rand.NextDouble() * 360;
                        Breeder bre2  = new Breeder(bre.Position + (new Vec2f((float)(20 * Math.Cos(alpha)), (float)(20 * Math.Sin(alpha)))), 0, new Vec2f(0, 0), "Breeder", player);
                        tmp.Add(bre2);
                        bre.ReadyToSpawn = false;
                    }

                    break;

                case EntityType.Drone:
                    Drone drone = (Drone)entities.ElementAt(i);
                    if (drone.noTarget)
                    {
                        Smaragd smaragd = null;
                        foreach (Entity ent in entities)
                        {
                            if (ent.getEntityType() == EntityType.Letter)
                            {
                                Smaragd sam = (Smaragd)ent;
                                if ((smaragd == null) || (sam.Drone == null && (player.Position - sam.Position).length() < (player.Position - smaragd.Position).length()))
                                {
                                    smaragd        = sam;
                                    ent.canExplode = false;
                                }
                            }
                        }
                        drone.setTarget(smaragd);
                    }

                    break;

                case EntityType.Bomb:
                    Bomb bomb = (Bomb)entities.ElementAt(i);
                    entities.AddRange(bomb.getBombFragment());

                    if (bomb.getBombFragment().Count > 1)
                    {
                        bomb.ToDelete = true;
                    }

                    break;

                default:
                    break;
                }

                if (entities.ElementAt(i).ToDelete)
                {
                    if (entities[i].canExplode && (entities[i].getEntityType() != EntityType.Projectile || ((Projectiles)entities[i]).LifeTime >= 0))
                    {
                        particleSpawner.Add(new PSpawner(entities[i].Position, 500));
                        sound.Play();
                    }
                    entities[i].onDeath();
                    entities.RemoveAt(i);
                }
            }
            entities.AddRange(tmp);

            entities.AddRange(player.spawnNewEnemy());

            runSpawnTimeSmaragd += (float)gameTime.ElapsedTime.TotalMilliseconds;

            if (rand.NextDouble() < 0.01f)//runSpawnTimeSmaragd > spawnTimeSmaragd)
            {
                runSpawnTimeSmaragd = 0;
                spawnSmaragd();
            }

            Entity spawnedEntity = spawner.spawn(gameTime);

            if (spawnedEntity != null)
            {
                entities.Add(spawnedEntity);
            }

            for (int i = particleSpawner.Count - 1; i > 0; --i)
            {
                particleSpawner.ElementAt(i).update(gameTime);
                if (particleSpawner.ElementAt(i).isSpawnerFinish())
                {
                    particleSpawner.RemoveAt(i);
                }
            }
            JoystickButton[] upgradeButton = { JoystickButton.A, JoystickButton.B, JoystickButton.X, JoystickButton.Y, JoystickButton.LB, JoystickButton.RB };
            Keyboard.Key[]   upgradeKeys   = { Keyboard.Key.Num1, Keyboard.Key.Num2, Keyboard.Key.Num3, Keyboard.Key.Num4, Keyboard.Key.Num5, Keyboard.Key.Num6 };
            UpgradeType[]    upgradeTypes  = { UpgradeType.AddCannon, UpgradeType.IncreaseDamage, UpgradeType.DecreaseCooldown, UpgradeType.AddDrone, UpgradeType.Heal, UpgradeType.Bomb };

            for (int i = 0; i < upgradeKeys.Length; ++i)
            {
                if (Game.keyboardInput.isClicked(upgradeKeys[i]) || Game.joystickInput.isClicked(upgradeButton[i]))
                {
                    player.upgrade(upgradeTypes[i], entities);
                }
            }
        }
Exemple #2
0
        public bool upgrade(UpgradeType upgradeType, List <Entity> entityList)
        {
            if (points < upgradeCosts)
            {
                return(false);
            }
            else
            {
                points      -= upgradeCosts;
                upgradeCosts = (int)(upgradeCosts * 1.5f);

                ++upgrades[(int)upgradeType];

                switch (upgradeType)
                {
                case UpgradeType.AddCannon:
                    Weapon newWeapon = new Cannon(position, 0, 10, cannonBaseCoolDown, cannonBaseDamage);
                    newWeapon.loadContent();
                    newWeapon.ProjectileDamageFactor = projectileDamageFactor;
                    newWeapon.CoolDownFactor         = coolDownFactor;
                    weapons.Add(newWeapon);
                    break;

                case UpgradeType.IncreaseDamage:
                    projectileDamageFactor *= 1.5f;
                    foreach (Weapon w in weapons)
                    {
                        w.ProjectileDamageFactor = projectileDamageFactor;
                    }
                    break;

                case UpgradeType.DecreaseCooldown:
                    coolDownFactor *= 0.8f;
                    foreach (Weapon w in weapons)
                    {
                        w.CoolDownFactor = coolDownFactor;
                    }
                    break;

                case UpgradeType.AddDrone:
                    baseDroneHP *= 2;
                    Entity newDrone = new Drone(new Vec2f(0, 0), 0, baseDroneHP, new Vec2f(0, 0), this);
                    newDrone.loadContent();
                    entityList.Add(newDrone);
                    break;

                case UpgradeType.Heal:
                    maxHp        *= 1.5f;
                    Hp            = maxHp;
                    lifebar.MaxHP = maxHp;
                    break;

                case UpgradeType.Bomb:
                    bombDamageFactor *= 1.5f;
                    bombAddTime       = TimeSpan.FromSeconds(bombAddTime.TotalSeconds * 0.8f);
                    break;

                default:
                    break;
                }

                return(true);
            }
        }