Пример #1
0
 /// <summary>
 /// Updates the particle emitter.
 /// </summary>
 /// <returns>True if it's still alive, false if not.</returns>
 public override bool Update()
 {
     if (m_Emitting)
     {
         m_FrequencyCounter = m_FrequencyCounter + (m_Frequency / 1000.0);
         while (m_FrequencyCounter >= 1)
         {
             BaseParticle p = SetParticleBaseAttributes(CreateParticle());
             if (p != null)
             {
                 m_Target.Add(p);
             }
             m_FrequencyCounter -= 1f;
         }
     }
     return(base.Update());
 }
        public static bool Set(this CompiledParticle compiled, OpenXmlCompositeElement parent, OpenXmlElement value, Type type)
        {
            if (type is null)
            {
                return(false);
            }

            if (compiled is null)
            {
                return(false);
            }

            var collection = new ParticleCollection(type, compiled, parent);

            collection.Clear();
            return(collection.Add(value));
        }
Пример #3
0
 /// <summary>
 /// Creates a particle system with an already created manipulators and particles.
 /// </summary>
 /// <param name="manipulators">The manipulators to associate with this particle system.</param>
 /// <param name="particles">The particles to add to this particle system.</param>
 public ParticleSystem(ParticleManipulatorCollection manipulators, ParticleCollection particles)
 {
     m_Manipulators = manipulators;
     m_Particles = new ParticleCollection();
     m_Particles.Add(particles);
 }
Пример #4
0
 /// <summary>
 /// Copy Constructor.
 /// </summary>
 /// <param name="system">The particle system to copy.</param>
 public ParticleSystem(ParticleSystem system)
 {
     if (system == null)
     {
         throw new ArgumentNullException("system");
     }
     m_Manipulators = new ParticleManipulatorCollection(system.Manipulators);
     m_Particles = new ParticleCollection();
     m_Particles.Add(system);
 }
Пример #5
0
        private void Tick(object sender, TickEventArgs e)
        {
            DateTime now = DateTime.Now;

            // Read the "game has begun" flag.
            bool gameHasBegun = this.theGameHasBegun;

            // Fill in the background.
            Video.Screen.Fill(Color.Black);
            Video.Screen.Blit(this.background);

            // Update all the particles in the universe.
            this.particleSystem.Update();

            if (gameHasBegun)
            {
                // The game has begun.

                // Spawn player 1.
                if (this.player1.Ship == null
                    || !this.player1.Ship.Alive && this.player1.Ship.RespawnTime < now)
                    SpawnShip(1);

                // Spawn player 2.
                if (this.player2.Ship == null
                    || !this.player2.Ship.Alive && this.player2.Ship.RespawnTime < now)
                    SpawnShip(2);

                if (this.player1.Ship != null && this.player2.Ship != null)
                {
                    // Perform user control (input) related updates.

                    // Player 1.
                    Bullet bullet = this.player1.ProcessUserInput();
                    if (bullet != null)
                        this.particleSystem.Particles.Add(bullet);

                    // Player 2.
                    bullet = this.player2.ProcessUserInput();
                    if (bullet != null)
                        this.particleSystem.Particles.Add(bullet);

                    // Check for collisions.
                    EnforceCollisions();
                }
            }

            // Enforce the Ship's speed limit last.
            ParticleCollection particleCollection = new ParticleCollection();
            particleCollection.Add(this.particleSystem);
            this.speedLimitManipulator.Manipulate(particleCollection);

            // Render all the particles in the universe.
            this.particleSystem.Render(Video.Screen);

            if (!gameHasBegun)
            {
                // The game hasn't actually started yet.

                // Display the title screen.
                this.mainTitle.Refresh();
            }
            else
            {
                // Display the plain InfoBar graphic.
                Video.Screen.Blit(this.infoBar, Configuration.InfoBarPosition);

                // Display the scoreCards on the InfoBar.
                this.player1.ScoreCard.Refresh(Video.Screen);
                this.player2.ScoreCard.Refresh(Video.Screen);
            }

            // Display the back-buffer onto the screen surface (double-buffering).
            Video.Screen.Update();
        }
Пример #6
0
        private void EnforceCollisions()
        {
            // Enforce Ship-Planet Impact.
            if (this.player1.Ship.Alive && this.player1.Ship.Collision(this.planet))
                Impact(this.player1.Ship, this.planet);
            if (this.player2.Ship.Alive && this.player2.Ship.Collision(this.planet))
                Impact(this.player2.Ship, this.planet);

            // Enforce Ship-Ship Impact.
            if (this.player1.Ship.Alive && this.player2.Ship.Alive && this.player1.Ship.Collision(this.player2.Ship))
                Impact(this.player1.Ship, this.player2.Ship);

            /* Create a shallow copy of the bullet particles to work with;
             * otherwise things go all wonky when we add particles during
             * iteration (i.e. explosions).
             */
            ParticleCollection bulletParticles = new ParticleCollection();
            foreach (BaseParticle p in this.particleSystem.Particles)
                if ((Type)p.GetType() == typeof(Bullet))
                    bulletParticles.Add(p);

            foreach (Bullet b in bulletParticles)
            {
                // Enforce Ship-Bullet impact.
                if (this.player1.Ship.Collision(b))
                    Impact(this.player1.Ship, b);
                if (this.player2.Ship.Collision(b))
                    Impact(this.player2.Ship, b);

                // Enforce Planet-Bullet impact.
                if (this.planet.Collision(b))
                    Impact(this.planet, b);
            }
        }
Пример #7
0
        public override bool Update()
        {
            this.forwardThruster.Update();
            this.reverseThruster.Update();

            // Enforce the Ship's speed limit.
            ParticleCollection particleCollection = new ParticleCollection();
            particleCollection.Add(this);
            this.speedLimiter.Manipulate(particleCollection);

            return base.Update();
        }