Exemplo n.º 1
0
        public Entity spawn(GameTime gameTime)
        {
            //if(rand.NextDouble()*0.91f *spawnVelocity *  Math.Max(1,gameTime.TotalTime.Minutes) > 1)
            //if(rand.NextDouble() < 0.003f)
            //if (rand.NextDouble() < 0.0025f + gameTime.TotalTime.Minutes/1000)
            //if (rand.NextDouble() < 0.0025f + (gameTime.TotalTime.TotalSeconds % 60)/1000)
            //if(  Math.Pow(gameTime.TotalTime.Minutes,2) * gameTime.TotalTime.Seconds + 0.99f< rand.NextDouble() * Math.Max(gameTime.TotalTime.Minutes,1)    )
            if (rand.NextDouble() / 2 + (gameTime.TotalTime.TotalMinutes / 60.0f) > 0.495f)
            {
                Entity e         = null;
                float  radius    = Math.Max(Game.WINDOWSIZE.X, Game.WINDOWSIZE.Y) / 2 + 30;
                Vec2f  ePosition = Game.WINDOWSIZE / 2 + (float)Math.Pow(-1, rand.Next(2)) * new Vec2f((float)rand.NextDouble() + 0.001f, (float)rand.NextDouble() + 0.001f).normalized() * radius;
                Vec2f  eVelocity = new Vec2f(0, 0);
                float  w         = (float)rand.NextDouble();
                if (p_breeder > w)
                {
                    e = new Breeder(ePosition, 0.0f, new Vec2f(), "Breeder", player);
                }
                else// wahrscheinlichkeit p_kamikaze
                {
                    e = new Kamikaze(ePosition, 0.0f, eVelocity, "Kamikaze", player);
                }


                e.loadContent();
                return(e);
            }

            return(null);
        }
Exemplo n.º 2
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);
                }
            }
        }