protected override void Execute(int execID, EntityID entity, ref ProjectileSpawnerComponent spawner, ref TransformComponent trans) { const int SHOTS_PER_BURST = 5; const float COOLDOWN_AFTER_BURST = 1.5f; const float COOLDOWN_BETWEEN_SHOTS = .05f; spawner.Cooldown -= deltaTime.Value; if (spawner.Cooldown > 0f) //Still cooling down so early out { return; } if (spawner.Target != null && context.HasEntity(spawner.Target.Value) && !context.HasTags(spawner.Target.Value, disabledMask)) { FireProjectile(ref spawner, ref trans); } spawner.Cooldown = COOLDOWN_BETWEEN_SHOTS; spawner.ShotsRemaining--; //If there are no shots-remaining then start cooling down if (spawner.ShotsRemaining <= 0) { spawner.ShotsRemaining = SHOTS_PER_BURST; spawner.Cooldown = COOLDOWN_AFTER_BURST; EntityID target; if (colliderManager.Intersect(AABox.FromCenterAndExtents(trans.Matrix.Position, new Vector3(75f, 125f, 75f)), out target)) { spawner.Target = target; } } }
protected override void Execute(int execID, EntityID entity, ref TransformComponent trans, ref VelocityComponent velo) { Vector3 pos = trans.Matrix.Position; Vector3 prevPos = pos - velo.Velocity * deltaTime.Value; Line line = new Line(prevPos, pos); EntityID target; if (colliderManager.Intersect(line, out target)) { //Remove the projectile context.RemoveEntity(entity); //Mark the target as hit context.SetTag <HitTag>(target); //Spawn a impact EntityID impactEntity = context.CreateEntity(); context.SetComponent(impactEntity, new TransformComponent(Float3x4.FromPosition(pos))); context.SetComponent(impactEntity, new GraphicComponent(graphicID: 3)); context.SetComponent(impactEntity, new LifetimeComponent(totalLifetime: .5f)); context.SetComponent(impactEntity, new AgeComponent()); } }