public void Update(float elapsed) { position += Velocity * elapsed; foreach (Entity e in Owner.Map.Entities) { if (e == Owner) continue; if (HitBox.Intersects(e.CollisionBox)) { // We have a hit! e.DoDamage(Damage); Active = false; // Create particles Particle p = new Particle(); p.Initialize(position, Velocity * -1, Vector2.Zero, Color.Red, 1f, 0f, 0, 0.5f); return; } } // Deactivate if outside bounds if (!Owner.Map.Bounds.Contains((int)position.X, (int)position.Y)) { Active = false; } }
public virtual void InitializeParticle(Particle p) { //assign initial location to emitter location Vector2 where = emitterLocation; // first, call PickRandomDirection to figure out which way the particle // will be moving. velocity and acceleration's values will come from this. Vector2 direction = PickRandomDirection(); // pick some random values for our particle float velocity = RandomBetween(minInitialSpeed, maxInitialSpeed); float acceleration = RandomBetween(minAcceleration, maxAcceleration); float lifetime = RandomBetween(minLifetime, maxLifetime); float scale = RandomBetween(minScale, maxScale); float rotationSpeed = RandomBetween(minRotationSpeed, maxRotationSpeed); // then initialize it with those random values. initialize will save those, // and make sure it is marked as active. //p.Initialize(velocity * direction, acceleration * direction, lifetime, scale, rotationSpeed); }