private void LaunchProjectiles(Actor3D actor) { //Only shoot if the player is within activation range if (playerTransform == null || Vector3.Distance(parentTransform.Translation, playerTransform.Translation) > GameConstants.Projectile_ActivationDistance) { return; } //Launch a projectile in each direction for (int i = 0; i < launchDirections.Count; i++) { CollidableProjectile projectile = projectileArchetype.Clone() as CollidableProjectile; projectile.Transform3D.Translation = parentTransform.Translation; projectile.EffectParameters.DiffuseColor = Color.Red; //Rotate the direction launchDirections[i] = Vector3.Transform(launchDirections[i], Quaternion.CreateFromAxisAngle(Vector3.Up, 45)); //Add the projectile to the ObjectManager and start its movement animation EventDispatcher.Publish(new EventData(EventCategoryType.Object, EventActionType.OnAddActor, new[] { projectile })); EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAdd, new[] { new TranslationTween(projectile, (int)MathF.Round(maxDistance * unitSpeedInMs), launchDirections[i] * maxDistance, true, actor3D => { EventDispatcher.Publish(new EventData(EventCategoryType.Object, EventActionType.OnRemoveActor, new[] { actor3D })); }, LoopType.PlayOnce, EasingType.easeIn) })); } //Play a shooting sound EventDispatcher.Publish(new EventData(EventCategoryType.Sound, EventActionType.OnPlay3D, new object[] { "shoot", parentTransform })); }
public ShootingController(string id, ControllerType controllerType, CollidableProjectile projectile, float maxDistance, int unitSpeedInMs) : base(id, controllerType) { this.projectileArchetype = projectile; this.maxDistance = maxDistance; this.unitSpeedInMs = unitSpeedInMs; EventDispatcher.Subscribe(EventCategoryType.Player, HandleGameStateEvent); }