示例#1
0
        public SungCruiser(Vector2 position, float orbitHeight, CruiserType type)
        {
            Position    = position;
            OrbitHeight = orbitHeight;

            Type = type;
        }
示例#2
0
        public override void Update(GameTime gameTime)
        {
            if (Victory)
            {
                goalScale = 0.0f;

                if (!exiting)
                {
                    zoomOut.Play();
                    exiting = true;
                }
            }
            else if (!player.Alive)
            {
                goalScale = Math.Min(0.4f * SpriteBatch.GraphicsDevice.Viewport.Height / 900.0f, 1.0f);
            }
            else
            {
                goalScale = Math.Min(0.6f * SpriteBatch.GraphicsDevice.Viewport.Height / 900.0f, 1.0f);
            }

            if (Victory && scale < 0.01)
            {
                NextLevel();
            }

            scale += (goalScale - scale) * 0.025f;

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                enemies.Clear();
                broccolis.Clear();
            }

            if (currentDeplyTime <= 0 && !Victory)
            {
                Vector2     position = GetOffscreenCoordinate(SpriteBatch.GraphicsDevice.Viewport);
                CruiserType type     = CruiserType.Cruiser;
                if (Utils.random.NextDouble() < level.DreadnaughtChance)
                {
                    type = CruiserType.Dreadnaught;
                }

                SungCruiser cruiser = new SungCruiser(position, 400.0f + 100 * (float)Utils.random.NextDouble(), type)
                {
                    Angle     = Utils.AngleOf(position),
                    Clockwise = Utils.random.NextDouble() < 0.5
                };

                cruiserEnter.Play();
                cruisers.Add(cruiser);
                currentDeplyTime = level.CruiserDeployTime;
            }
            else if (cruisers.Count < level.MaxCruisers)
            {
                currentDeplyTime -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            foreach (SungCruiser cruiser in cruisers)
            {
                if (cruiser.Behaviour == CruiserBehaviour.Entering)
                {
                    cruiser.Position += Vector2.Normalize(-cruiser.Position) * cruiser.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (cruiser.Position.Length() <= cruiser.OrbitHeight)
                    {
                        cruiser.Behaviour = CruiserBehaviour.Orbiting;
                    }
                }
                else if (cruiser.Behaviour == CruiserBehaviour.Orbiting)
                {
                    cruiser.Angle   += cruiser.OrbitSpeed / cruiser.OrbitHeight * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    cruiser.Position = Utils.VectorFrom(cruiser.Angle, cruiser.OrbitHeight);
                }
                else if (cruiser.Behaviour == CruiserBehaviour.Leaving)
                {
                    cruiser.Position -= Vector2.Normalize(-cruiser.Position) * cruiser.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;

                    if (!OnScreen(cruiser.Position, SpriteBatch.GraphicsDevice.Viewport, -100))
                    {
                        cruiser.Remove = true;
                    }
                }

                if (cruiser.FiringTimer <= 0)
                {
                    if (player.Alive && cruiser.Behaviour != CruiserBehaviour.Leaving)
                    {
                        Vector2 playerOffset = player.Position - cruiser.Position;

                        Vector2 targetPosition = player.Position;
                        if (cruiser.Type == CruiserType.Dreadnaught)
                        {
                            targetPosition = player.Position + player.Velocity * (playerOffset.Length() / 300.0f);
                        }

                        bullets.Add(new GravitarBullet(cruiser.Position, Vector2.Normalize(targetPosition - cruiser.Position) * 300, false));
                        cruiser.FiringTimer = cruiser.FiringDelay + (float)random.NextDouble();
                        shoot.Play();
                    }
                }
                else
                {
                    cruiser.FiringTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }

            UpdatePlayer((float)gameTime.ElapsedGameTime.TotalSeconds);
            UpdateBullets((float)gameTime.ElapsedGameTime.TotalSeconds);
            UpdateParticles((float)gameTime.ElapsedGameTime.TotalSeconds);

            foreach (GravitarBroccoli broccoli in broccolis)
            {
                broccoli.MoveToParent();
            }

            foreach (GravitarEnemy enemy in enemies)
            {
                enemy.MoveToParent();
                enemy.firingTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (enemy.firingTimer <= 0 && player.Alive)
                {
                    switch (enemy.Type)
                    {
                    case EnemyType.Standard:
                        bullets.Add(new GravitarBullet(enemy.Position, Vector2.Normalize(player.Position - enemy.Position) * 300, false));
                        enemy.firingTimer = enemy.firingDelay + (float)random.NextDouble();
                        shoot.Play();

                        break;

                    case EnemyType.SungBrute:
                        float angle = Utils.AngleOf(player.Position - enemy.Position);

                        bullets.Add(new GravitarBullet(enemy.Position, Utils.VectorFrom(angle - 0.2f, 300), false));
                        bullets.Add(new GravitarBullet(enemy.Position, Utils.VectorFrom(angle, 300), false));
                        bullets.Add(new GravitarBullet(enemy.Position, Utils.VectorFrom(angle + 0.2f, 300), false));

                        enemy.firingTimer = enemy.firingDelay + (float)random.NextDouble();
                        bigShoot.Play();

                        break;

                    case EnemyType.Queen:
                        Vector2 playerOffset   = player.Position - enemy.Position;
                        Vector2 targetPosition = player.Position + player.Velocity * (playerOffset.Length() / 300.0f);
                        bullets.Add(new GravitarBullet(enemy.Position, Vector2.Normalize(targetPosition - enemy.Position) * 300, false));

                        enemy.firingTimer = enemy.firingDelay + (float)random.NextDouble();
                        shoot.Play();

                        break;
                    }
                }
            }

            if (player.Tractoring)
            {
                foreach (GravitarBroccoli broccoli in broccolis)
                {
                    if (Sprites.TractorBeam.ContainsPoint(player.Position, player.Angle, broccoli.Position))
                    {
                        score          += 100;
                        broccoli.Remove = true;

                        pickup.Play();
                        AddParticles(broccoli.Position, 10, Color.Green);
                    }
                }
            }

            if (particles.Any(particle => particle.Remove))
            {
                sizzle.Play(0.2f, 0.0f, 0.0f);
            }

            bullets.RemoveAll(bullet => bullet.Remove);
            broccolis.RemoveAll(broccoli => broccoli.Remove);
            enemies.RemoveAll(enemy => enemy.Remove);
            cruisers.RemoveAll(cruiser => cruiser.Remove);
            particles.RemoveAll(particle => particle.Remove);

            foreach (Planet planet in planets)
            {
                planet.Angle += 0.001f;
            }
        }