void Start()
 {
     //FIgure out how many threads we'll have to dispatch
     numThreads = Mathf.CeilToInt((float)numParticles / NUM_THREADS);
     //Prepare an array of particles to send to the GPU
     FireParticle[] particles = new FireParticle[numParticles];
     for (int i = 0; i < numParticles; i++)
     {
         particles[i].position = particleTransform.position;
         particles[i].velocity = new Vector3(
             Random.Range(startingXZvelocityMin, startingXZvelocityMax),
             Random.Range(startingYVelocityMin, startingYVelocityMax),
             Random.Range(startingXZvelocityMin, startingXZvelocityMax));
         particles[i].startPosition = particles[i].position;
         particles[i].startVelocity = particles[i].velocity;
         particles[i].prevPosition  = particles[i].position;
         particles[i].startTime     = i * emissionTimeInterval;
     }
     //Find out when we have to effectively restart the particle system
     particleRestartTime = emissionTimeInterval * (numParticles + 1);
     //Prepare the compute buffer
     //sizeof(Vector3) doesn't work? Doing a hacky solution instead...
     computeBuffer = new ComputeBuffer(numParticles, PARTICLE_SIZE);
     computeBuffer.SetData(particles);
     //Get the kernel
     kernelID = shader.FindKernel("FireCSMain");
     //Set the buffer data
     shader.SetBuffer(kernelID, "particleBuffer", computeBuffer);
     particleShaderMaterial.SetBuffer("particleBuffer", computeBuffer);
 }
Esempio n. 2
0
        public override void Update(GameTime gameTime, Player attackPlayer, NPC attackNPC)
        {
            for (int i = 0; i < 3; i++)
            {
                FireParticle particle = new FireParticle()
                {
                    Position        = CardGameUI.ToUIPos(Position) + new Vector2(0f, -10f),
                    Velocity        = Vector2.Zero,
                    UIPosition      = UIPosition,
                    Alpha           = 100,
                    IsPanelParticle = true
                };
                particle.Setup(Size, 1f, attackPlayer);
                particle.Velocity *= 0.85f;
                attackPlayer.GetModPlayer <EntrogicPlayer>()._particles.Add(particle);
            }
            Velocity.Y -= 0.1f;

            if (Vector2.Distance(CardGameUI.ToUIPos(Position + Size / 2f), TargetPosition + new Vector2(0, 12f)) < 10f)
            {
                IsRemoved = true;
                CardFightableNPC fightNPC = (CardFightableNPC)attackNPC.modNPC;
                fightNPC.CardGameHealth -= 46;
            }

            base.Update(gameTime, attackPlayer, attackNPC);
        }
    private void FixedUpdate()
    {
        int count = fireParticles.Count;

        for (int i = 0; i < count; ++i)
        {
            FireParticle particle = fireParticles.Dequeue();

            if (!particle.Update(Time.fixedDeltaTime))
            {
                for (int j = 0; j < particle.treeDepth; ++j)
                {
                    FireParticle childParticle = new FireParticle();
                    //childParticle.age = Random.Range(0, particle.age);
                    childParticle.particle.position    = particle.particle.position;
                    childParticle.particle.velocity.x += particle.particle.velocity.x;
                    childParticle.particle.velocity.y += particle.particle.velocity.y;
                    childParticle.particle.velocity.z += particle.particle.velocity.z;
                    childParticle.treeDepth            = Random.Range(0, particle.treeDepth);
                    childParticle.color = particle.color + new Color(Random.Range(-0.10f, 0.10f), Random.Range(-0.10f, 0.10f), Random.Range(-0.10f, 0.10f));
                    fireParticles.Enqueue(childParticle);
                }
                particle.Dispose();
            }
            else
            {
                fireParticles.Enqueue(particle);
            }
        }
    }
 private void OnDestroy()
 {
     while (fireParticles.Count > 0)
     {
         FireParticle p = fireParticles.Dequeue();
         if (p != null)
         {
             p.Dispose();
         }
     }
 }
Esempio n. 5
0
 public void ExtinguishPoint(FireParticle particle)
 {
     for (int i = 0; i < this.FirePoints.Length; i++)
     {
         FireDamagePoint fireDamagePoint = this.FirePoints[i];
         if (fireDamagePoint.particleSystem == particle)
         {
             fireDamagePoint.particleSystem = null;
             return;
         }
     }
 }
Esempio n. 6
0
 public void ExtinguishPoint(FireParticle particle)
 {
     for (int i = 0; i < this.FirePoints.Length; i++)
     {
         FireDamagePoint fireDamagePoint = this.FirePoints[i];
         if (fireDamagePoint.particleSystem == particle)
         {
             fireDamagePoint.particleSystem = null;
             return;
         }
     }
 }
Esempio n. 7
0
    private void SimulateParticles()
    {
        List <FireParticle> elementsToRemove = new List <FireParticle>();

        foreach (FireParticle p in visibleParticles)
        {
            if (p.NeedsRecycling)
            {
                elementsToRemove.Add(p);
            }
        }
        for (int i = 0; i < elementsToRemove.Count; i++)
        {
            FireParticle p = elementsToRemove[i];
            visibleParticles.Remove(p);
            p.gameObject.SetActive(false);
            pooledParticles.Enqueue(p);
        }
    }
        public override void update(GameTime gameTime)
        {
            if (Controller.MouseLeftDown())
            {
                FireParticle particula = new FireParticle(texturaFogo, random);
                particula.x = random.Next(Mouse.GetState().X - 5, Mouse.GetState().X + 5);
                particula.y = random.Next(Mouse.GetState().Y - 5, Mouse.GetState().Y + 5);
                listaParticulas.Add(particula);
                FireManager.AddFireParticle(particula);
            }

            FireParticle particula2 = new FireParticle(texturaFogo, random);

            particula2.x = random.Next(400 - 5, 400 + 5);
            particula2.y = random.Next(400 - 5, 400 + 5);
            listaParticulas.Add(particula2);
            FireManager.AddFireParticle(particula2);

            FireManager.Update(gameTime);
        }
Esempio n. 9
0
    private void EmitParticles()
    {
        FireParticle unusedParticle = null;
        Vector3      randomPos      = new Vector3(Random.Range(-_maxFireRange.x, _maxFireRange.x), 0, Random.Range(-_maxFireRange.y, _maxFireRange.y)) + _fireSourceTransform.position;

        if (pooledParticles.Count + visibleParticles.Count < _maxParticles)
        {
            GameObject newFireParticleObject = Instantiate(_fireParticlePrefab, randomPos, Quaternion.identity) as GameObject;
            newFireParticleObject.transform.SetParent(_fireSourceTransform);
            unusedParticle = newFireParticleObject.GetComponent <FireParticle>();
        }
        else if (pooledParticles.Count > 0)
        {
            unusedParticle = pooledParticles.Dequeue();
            unusedParticle.gameObject.SetActive(true);
            unusedParticle.gameObject.transform.position = randomPos;
        }
        if (unusedParticle != null)
        {
            visibleParticles.Add(unusedParticle);
            unusedParticle.Init(_particleLifetime, _particleSpeed, _particleAcceleration, _particleSizeCurve);
        }
    }
Esempio n. 10
0
        public override void Kill(Player attackPlayer)
        {
            Vector2 screenCenter = new Vector2(Main.screenWidth, Main.screenHeight) / 2f + Main.screenPosition;

            Main.PlaySound(SoundID.Item10, (int)screenCenter.X, (int)screenCenter.Y + -30);
            Size.X     = 20;
            Size.Y     = 20;
            Position.X = CardGameUI.ToUIPos(Center).X - Size.X / 2f;
            Position.Y = CardGameUI.ToUIPos(Center).Y - Size.Y / 2f;
            for (int i = 0; i < 23; i++)
            {
                FireParticle particle = new FireParticle()
                {
                    Position        = Position,
                    UIPosition      = UIPosition,
                    Alpha           = 100,
                    IsPanelParticle = true
                };
                particle.Setup(Size, 1f, attackPlayer);
                if (Main.rand.Next(2) == 0)
                {
                    particle.Scale = 0.5f;
                }
                particle.Velocity *= 2f;
                attackPlayer.GetModPlayer <EntrogicPlayer>()._particles.Add(particle);
            }
            for (int j = 0; j < 20; j++)
            {
                FireParticle2 particle = new FireParticle2()
                {
                    Position        = Position,
                    UIPosition      = UIPosition,
                    Alpha           = 100,
                    IsPanelParticle = true
                };
                particle.Setup(Size, 1f, attackPlayer);
                particle.Velocity *= 2f;
                attackPlayer.GetModPlayer <EntrogicPlayer>()._particles.Add(particle);
            }
            for (int k = 0; k < Main.rand.Next(5, 7); k++)
            {
                float scaleFactor = 0.33f;
                if (k % 3 == 1)
                {
                    scaleFactor = 0.66f;
                }
                if (k % 3 == 1)
                {
                    scaleFactor = 1f;
                }
                StarParticle particle = new StarParticle()
                {
                    Position        = Position,
                    UIPosition      = UIPosition,
                    Alpha           = Main.rand.Next(140, 201),
                    IsPanelParticle = true
                };
                particle.Setup(Size, Main.rand.NextFloat() * 0.5f + 1f, attackPlayer);
                particle.Velocity *= scaleFactor;
                attackPlayer.GetModPlayer <EntrogicPlayer>()._particles.Add(particle);
            }
            //for (float rad = 0.0f; rad < 2 * 3.141f; rad += (float)Main.rand.Next(8, 14) / 10)
            //{
            //    Vector2 vec = new Vector2(120f, 0f);
            //    Vector2 finalVec = (vec.ToRotation() + rad).ToRotationVector2() * 16f;
            //    Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, Main.rand.Next(-10, 11), Main.rand.Next(-10, 11), ProjectileType<PineapplePieces>(), 21, 0f, projectile.owner, 0f, 0f);
            //}
            base.Kill(attackPlayer);
        }
Esempio n. 11
0
 private Particle Defaultemitterroutine(BCBlockGameState gstate, EmitterParticle source, int framenum, int ttl)
 {
     FireParticle p = new FireParticle(new PointF(source.Location.X, source.Location.Y));
     p.TTL = 60;
     p.Velocity = BCBlockGameState.GetRandomVelocity(0, 2);
     return p;
 }
Esempio n. 12
0
        public override void Update(GameTime gameTime, Player attackPlayer, NPC attackNPC)
        {
            for (int extraUpdates = 0; extraUpdates < 2; extraUpdates++)
            {
                if (!State2)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        FireParticle particle = new FireParticle()
                        {
                            Position        = CardGameUI.ToUIPos(Position) + new Vector2(0f, -10f),
                            Velocity        = Vector2.Zero,
                            UIPosition      = UIPosition,
                            Alpha           = 100,
                            IsPanelParticle = true
                        };
                        particle.Setup(Size, 1.2f, attackPlayer);
                        particle.Velocity *= 0.5f * 1.1f;
                        attackPlayer.GetModPlayer <EntrogicPlayer>()._particles.Add(particle);
                    }
                    Velocity += new Vector2(0f, -0.8f);
                }
                else
                {
                    if (localAI == 0f)
                    {
                        Vector2 screenCenter = new Vector2(Main.screenWidth, Main.screenHeight) / 2f + Main.screenPosition;
                        Main.PlaySound(SoundID.Item74, (int)screenCenter.X, (int)screenCenter.Y + -30);
                        localAI += 1f;
                    }
                    ai += 1f;
                    ai += 3f;
                    float num466 = 25f;
                    if (ai > 180f)
                    {
                        num466 -= (ai - 180f) / 2f;
                    }
                    num466 *= 0.7f;
                    int num467 = 0;
                    while ((float)num467 < num466)
                    {
                        float num468 = (float)Main.rand.Next(-10, 11);
                        float num469 = (float)Main.rand.Next(-10, 11);
                        float num470 = (float)Main.rand.Next(3, 9);
                        float num471 = (float)Math.Sqrt((double)(num468 * num468 + num469 * num469));
                        num471  = num470 / num471;
                        num468 *= num471;
                        num469 *= num471;

                        FireParticle particle = new FireParticle()
                        {
                            Position        = CardGameUI.ToUIPos(Position) + new Vector2(0f, -10f),
                            Velocity        = Vector2.Zero,
                            UIPosition      = UIPosition,
                            Alpha           = 100,
                            IsPanelParticle = true
                        };
                        particle.Setup(Size, 1.5f, attackPlayer);
                        particle.Position  = CardGameUI.ToUIPos(Position) + Size / 2f;
                        particle.Position += new Vector2(Main.rand.Next(-10, 11), Main.rand.Next(-10, 11));
                        particle.Velocity  = new Vector2(num468, num469) * 0.75f;
                        attackPlayer.GetModPlayer <EntrogicPlayer>()._particles.Add(particle);

                        int num3 = num467;
                        num467 = num3 + 1;
                    }
                    Velocity = Vector2.Zero;
                }

                base.Update(gameTime, attackPlayer, attackNPC);

                if (!State2 && Vector2.Distance(CardGameUI.ToUIPos(Position + Size / 2f), TargetPosition + new Vector2(0, 12f)) < 10f)
                {
                    State2 = true;
                    CardFightableNPC fightNPC = (CardFightableNPC)attackNPC.modNPC;
                    fightNPC.CardGameHealth -= GetDamage(Damage);
                }
            }
        }
Esempio n. 13
0
    private void Fire()
    {
        FireParticle particle = new FireParticle();

        fireParticles.Enqueue(particle);
    }