/// <summary>
        /// InitializeParticle randomizes some properties for a particle, then
        /// calls initialize on it. It can be overriden by subclasses if they
        /// want to modify the way particles are created. For example,
        /// SmokePlumeParticleSystem overrides this function make all particles
        /// accelerate to the right, simulating wind.
        /// </summary>
        /// <param name="p">the particle to initialize</param>
        /// <param name="where">the position on the screen that the particle should be
        /// </param>
        protected virtual void InitializeParticle(Particle p, Vector2 where)
        {
            // first, call PickRandomDirection to figure out which way the particle
            // will be moving. velocity and acceleration's values will come from this.
            Vector2 direction;

            if (EmitterVelocity == Vector2.Zero)
            {
                direction = PickRandomDirection();
            }
            else
            {
                direction = EmitterVelocity += EmitterAcceleration;
            }

            // pick some random values for our particle
            float velocity =
                StarTrooperGame.RandomBetween(minInitialSpeed, maxInitialSpeed);
            float acceleration =
                StarTrooperGame.RandomBetween(minAcceleration, maxAcceleration);
            float lifetime =
                StarTrooperGame.RandomBetween(minLifetime, maxLifetime);
            float scale =
                StarTrooperGame.RandomBetween(minScale, maxScale);
            float rotationSpeed =
                StarTrooperGame.RandomBetween(minRotationSpeed, maxRotationSpeed);

            // then initialize it with those random values. initialize will save those,
            // and make sure it is marked as active.
            p.Initialize(
                where, velocity * direction, acceleration * direction,
                lifetime, scale, rotationSpeed);
        }
예제 #2
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (StarTrooperGame game = new StarTrooperGame())
     {
         game.Run();
     }
 }
        /// <summary>
        /// InitializeParticle is overridden to add the appearance of wind.
        /// </summary>
        /// <param name="p">the particle to set up</param>
        /// <param name="where">where the particle should be placed</param>
        protected override void InitializeParticle(Particle p, Vector2 where)
        {
            base.InitializeParticle(p, where);

            // the base is mostly good, but we want to simulate a little bit of wind
            // heading to the right.
            p.Acceleration.X += StarTrooperGame.RandomBetween(10, 50);
        }
        void TrooperFire()
        {
            // dynamically create a new sprite
            Fire fire = (Fire)StarTrooperGame.Fire.Clone();

            fire.Position = new Vector2(Position.X, Position.Y - 35);
            fire.Velocity = new Vector2(0, -4);
            StarTrooperGame.Add(fire); // set the fire sprite active
            FireballLaunch(new Vector2(Position.X, Position.Y - 35), new Vector2(0, -40), new Vector2(0, -0.5f));
            StarTrooperGame.Shoot.Play();
            StarTrooperGame.shots++;
        }
        /// <summary>
        /// PickRandomDirection is overriden so that we can make the particles always
        /// move have an initial velocity pointing up.
        /// </summary>
        /// <returns>a random direction which points basically up.</returns>
        protected override Vector2 PickRandomDirection()
        {
            // Point the particles somewhere between 80 and 100 degrees.
            // tweak this to make the smoke have more or less spread.
            float radians = StarTrooperGame.RandomBetween(
                MathHelper.ToRadians(80), MathHelper.ToRadians(100));

            Vector2 direction = Vector2.Zero;

            // from the unit circle, cosine is the x coordinate and sine is the
            // y coordinate. We're negating y because on the screen increasing y moves
            // down the monitor.
            direction.X = (float)Math.Cos(radians);
            direction.Y = -(float)Math.Sin(radians);
            return(direction);
        }
예제 #6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            LoadResources();

            //Try and load any saved key mappings
            FileManager.LoadKeyMappings();

            //If no settings present or setting were unable to be loaded, use the defaults
            if (!Input.InputMappings.SettingsSaved)
            {
                Input.Load_Defaults();
            }


            Shoot = Content.Load <SoundEffect>(@"Sounds\shoot");
            Die   = Content.Load <SoundEffect>(@"Sounds\die");

            Music                    = Content.Load <SoundEffect>(@"Music\music");
            BackgroundMusic          = Music.CreateInstance();
            BackgroundMusic.IsLooped = true;
            BackgroundMusic.Play();

            font = Content.Load <SpriteFont>(@"Fonts\SpriteFont1");

            ScoreText          = new Text2D(font);
            ScoreText.Text     = "Score: " + score.ToString();
            ScoreText.Position = new Vector2(10, 10);
            ScoreText.Color    = Color.Red;
            StarTrooperGame.Add(ScoreText);

            ShotsText          = new Text2D(font);
            ShotsText.Text     = "Shots: " + shots.ToString();
            ShotsText.Position = new Vector2(150, 10);
            ShotsText.Color    = Color.Red;
            StarTrooperGame.Add(ShotsText);

            // TODO: use this.Content to load your game content here
        }