SamplyGame.Missile.LaunchSingleMissile C# (CSharp) Method

LaunchSingleMissile() private method

private LaunchSingleMissile ( bool left, bool player ) : System.Threading.Tasks.Task
left bool
player bool
return System.Threading.Tasks.Task
		async Task LaunchSingleMissile(bool left, bool player)
		{
			var cache = Application.ResourceCache;
			var carrier = Node;
			var carrierPos = carrier.Position;

			var bulletNode = CreateRigidBullet(player);
			bulletNode.Position = new Vector3(carrierPos.X + 0.4f * (left ? -1 : 1), carrierPos.Y + 0.3f, carrierPos.Z);
			var bulletModelNode = bulletNode.CreateChild();

			bulletModelNode.Scale = new Vector3(1f, 2f, 1f) / 2.5f;
			bulletNode.SetScale(0.3f);

			// Trace-effect using particles
			bulletNode.CreateComponent<ParticleEmitter2D>().Effect = cache.GetParticleEffect2D(Assets.Particles.MissileTrace);
			bulletNode.CreateComponent<ParticleEmitter2D>().Effect = cache.GetParticleEffect2D(Assets.Particles.Explosion);

			// Route (Bezier)
			float directionY = player ? 1 : -1;
			float directionX = left ? -1 : 1;
			var moveMissileAction = new BezierBy(1.0f, new BezierConfig
				{
					ControlPoint1 = new Vector3(-directionX, 2f * directionY, 0),
					ControlPoint2 = new Vector3(RandomHelper.NextRandom(-2, 2) * directionX, 4 * directionY, 0),
					EndPosition = new Vector3(RandomHelper.NextRandom(-1, 1) * directionX, 12 * directionY, 0),
				});

			await bulletNode.RunActionsAsync(
				new EaseIn(moveMissileAction, 1), // move
				new CallFunc(() => bulletNode.SetScale(0f)), //collapse
				new DelayTime(2f)); //a delay to leave the trace effect

			//remove the missile from the scene.
			bulletNode.Remove();
		}