public Particle(Vector2 initialPosition, ParticleTemplate template, Entity owner)
        {
            _template = template;
            _owner = owner;

            //Rotation
            Rotation = template.GetValue<float>(ParticleValues.InitialRotation);
            if ((int)Rotation == -1) Rotation = (float)_rand.NextDouble();

            Size = template.GetValue<float>(ParticleValues.InitialSize);
            _secondsRemaining = template.GetValue<float>(ParticleValues.LifeTime);
            Texture = ResourceManager.GetTexture("particles/" + template.GetValue<string>(ParticleValues.Texture));
            Alpha = 1.0f - template.GetValue<float>(ParticleValues.InitialAlpha);
            IsCollidable = template.GetValue<bool>(ParticleValues.CanCollide);
            Position = initialPosition;

            //Sound effect
            string spawnSound = template.GetValue<string>(ParticleValues.SoundEffectOnSpawn);
            if (spawnSound != null) ResourceManager.PlaySoundEffect(spawnSound);

            //camera shake effect
            Camera.shake += template.GetValue<int>(ParticleValues.CameraShake);

            if (template.GetValue<bool>(ParticleValues.AreaOfEffect))
            {
                _areaOfEffect = new HashSet<Entity>();
            }
        }
        public static void SpawnParticle(Vector2 position, ParticleTemplate template, bool centre = false, Entity owner = null)
        {
            //Don't spawn more particles than the set limit
            if (Count() >= MaxParticles || template == null) return;

            //Spawn it and add it last in our list
            SpawnList.AddLast(new Particle(position, template, owner));
        }
 /// <summary>
 /// Constructor for an Entity
 /// </summary>
 /// <param name="textureID">The name of the texture file to use</param>
 public Entity(UnitType type)
 {
     IsCollidable = true;
     this.type = type;
     Texture = type.Texture;
     Width = Texture.Width;
     Height = Texture.Height;
     TurnRate = type.GetValue<float>(UnitValues.TurnRate);
     MaxHealth = Health = type.GetValue<float>(UnitValues.Health);
     Speed = type.GetValue<float>(UnitValues.Speed);
     PrimaryWeapon = ResourceManager.GetParticleTemplate(type.GetValue<string>(UnitValues.PrimaryWeapon));
     SecondaryWeapon = ResourceManager.GetParticleTemplate(type.GetValue<string>(UnitValues.SecondaryWeapon));
     DestroyOnCollsion = type.GetValue<bool>(UnitValues.DestroyOnCollision);
 }
        public static void SpawnProjectile(Entity shooter, ParticleTemplate template)
        {
            //Don't spawn more particles than the set limit
            if (Count() >= MaxParticles || template == null) return;

            Particle projectile = new Particle(shooter.Position, template, shooter);
            projectile.Rotation = shooter.Rotation;
            projectile.Speed = template.GetValue<float>(ParticleValues.Speed);
            projectile.Team = shooter.Team;

            //Spawn projectile from gun barrel and not unit origin
            projectile.X += (float)Math.Cos(shooter.Rotation) * shooter.Width/2;
            projectile.Y += (float)Math.Sin(shooter.Rotation) * shooter.Width/2;

            //Spawn it and add it last in our list
            SpawnList.AddLast(projectile);
        }
        public static ParticleTemplate GetParticleTemplate(string particleID)
        {
            if (particleID == null) return null;

            if (!_loadedParticles.ContainsKey(particleID))
            {
                try
                {
                    _loadedParticles[particleID] = new ParticleTemplate(ContentFolder + "particles/" + particleID);
                }
                catch
                {
                    Logger.Log("Unable to load ParticleTemplate: " + particleID, LogLevel.Warning);
                    _loadedParticles[particleID] = null;
                }

            }

            return _loadedParticles[particleID];
        }