Exemple #1
0
 public void addParticle(Vector2 position, Vector2 velocity, Particle_Type type)
 {
     Particle p;
     if (type.Equals(Particle_Type.Sand))
         p = new Particle_Sand(position, velocity);
     else if (type.Equals(Particle_Type.Wall))
         p = new Particle_Wall(position, velocity);
     else
         p = new Particle_Sand(position, velocity);
     //Check if p is in the viewing box
     Rectangle surround = new Rectangle((int)p.position.X - boundryBuffer, (int)p.position.Y - boundryBuffer, 2 * boundryBuffer, 2 * boundryBuffer);
     if (boundry.Intersects(surround))
         particles.Add(p);
 }
Exemple #2
0
        public bool addParticle(Vector2 position, Vector2 velocity, Particle_Type type, bool screenCoord, bool overlay)
        {
            if(screenCoord)
                position = (position + new Vector2(boundry.X, boundry.Y)) / particleSize;
            position.X = (int)position.X;
            position.Y = (int)position.Y;
            Particle p;
            if(type.Equals(Particle_Type.Sand))
                p = new Particle_Sand(position, velocity);
            else if (type.Equals(Particle_Type.Wall))
                p = new Particle_Wall(position, velocity);
            else if (type.Equals(Particle_Type.Water))
                p = new Particle_Water(position, velocity);
            else if (type.Equals(Particle_Type.Plant))
                p = new Particle_Plant(position, velocity);
            else if (type.Equals(Particle_Type.Fire))
                p = new Particle_Fire(position, velocity);
            else
                p = new Particle_Sand(position, velocity);
            //Check if p is in the viewing box
            Rectangle surround = new Rectangle((int)p.position.X - boundryBuffer, (int)p.position.Y - boundryBuffer, 2 * boundryBuffer, 2 * boundryBuffer);
            if (boundry.Intersects(surround))
            {
                //particles.Add(p);
                //particleField[(int)p.position.X, (int)p.position.Y] = p;//todo fix
                //return true;
                if (!overlay)
                {
                    if (particleStorage.particleAt((int)p.position.X, (int)p.position.Y) != null && particleStorage.particleAt((int)p.position.X, (int)p.position.Y).type == p.type)
                        return true;
                    else
                    {
                        particleStorage.deleteParticle(particleStorage.particleAt((int)p.position.X, (int)p.position.Y));
                        particleStorage.newParticle(p);
                        return true;
                    }
                }
                if (particleStorage.newParticle(p))
                    return true;
                //particles.Add(p);
                //particleField[(int)p.position.X, (int)p.position.Y] = p;//todo fix

            }
            return false;
        }