예제 #1
0
파일: Game1.cs 프로젝트: Wiles/sgd_assign_3
        /// <summary>
        /// Updates the asteroids.
        /// </summary>
        /// <param name="delta">The delta.</param>
        /// <param name="inputState">State of the input.</param>
        private void UpdateAsteroids(long delta, Input inputState)
        {
            for (int i = _asteroids.Count - 1; i >= 0; i--)
            {
                _asteroids[i].Update(GraphicsDevice, inputState, delta);

                if (_asteroids[i].Active == false)
                {
                    Asteroid parent = _asteroids[i];

                    if (parent.Generation <= 2)
                    {
                        var asteroid = new Asteroid();
                        asteroid.Initialize(GraphicsDevice.Viewport, _asteroidTexture, parent.Position,
                                            parent.Radians - _rand.Next(10, 30) * Math.PI / 180, parent.Speed * 1.1f,
                                            parent.Generation + 1);
                        _asteroids.Add(asteroid);

                        asteroid = new Asteroid();
                        asteroid.Initialize(GraphicsDevice.Viewport, _asteroidTexture, parent.Position,
                                            parent.Radians + _rand.Next(10, 30) * Math.PI / 180, parent.Speed * 1.1f,
                                            parent.Generation + 1);
                        _asteroids.Add(asteroid);
                    }
                    var explosion = new Explosion
                    {
                        Active   = true,
                        Position =
                            parent.Position - new Vector2((float)(parent.Width / 2.0), (float)(parent.Height / 2.0)),
                        Scale    = (float)parent.Scale,
                        Texture  = parent.Texture,
                        Velocity = new Vector2()
                    };
                    _explosionSound.Play();
                    _explosions.Add(explosion);
                    _asteroids.RemoveAt(i);
                    if (_asteroids.Count == 0)
                    {
                        _wave += 1;
                        StartWave(_wave);
                    }
                }
            }
        }
예제 #2
0
파일: Game1.cs 프로젝트: Wiles/sgd_assign_3
        /// <summary>
        /// Starts the wave of asteroids.
        /// The higher the wave number the harder the wave will be
        /// </summary>
        /// <param name="wave">The wave.</param>
        private void StartWave(int wave)
        {
            int asteroids = (wave + 4 < 12) ? wave + 4 : 12;

            for (int i = 0; i < asteroids; ++i)
            {
                double direction = _rand.NextDouble() * Math.PI * 2;
                double x         = GraphicsDevice.Viewport.Width / 2.0 + GraphicsDevice.Viewport.Width * Math.Cos(direction);

                double y = GraphicsDevice.Viewport.Height / 2.0 + GraphicsDevice.Viewport.Height * Math.Sin(direction);
                x = MathHelper.Clamp((float)x, 0, GraphicsDevice.Viewport.Width);
                y = MathHelper.Clamp((float)y, 0, GraphicsDevice.Viewport.Height);
                double init     = _rand.NextDouble() * Math.PI * 2;
                var    asteroid = new Asteroid();
                float  speed    = 50.0f;
                if (wave > 12)
                {
                    speed += wave - 12 * 10;
                }
                asteroid.Initialize(GraphicsDevice.Viewport, _asteroidTexture, new Vector2((int)x, (int)y), init,
                                    (float)Math.Floor(speed + ((_rand.NextDouble() - .5)) * 25), 1);
                _asteroids.Add(asteroid);
            }
        }