Beispiel #1
0
		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.7f * (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();
		}
		protected override async Task OnFire(bool player)
		{
			var cache = Application.ResourceCache;

			var bulletNode = CreateRigidBullet(player);
			var bulletModelNode = bulletNode.CreateChild();

			var model = bulletModelNode.CreateComponent<StaticModel>();
			model.Model = cache.GetModel(Assets.Models.Box);
			bulletModelNode.SetScale(2f);
			bulletModelNode.Rotate(new Quaternion(45, 0, 0), TransformSpace.Local);
			bulletNode.SetScale(RandomHelper.NextRandom(0.15f, 0.2f));

			// Trace-effect using particles
			var trace = bulletNode.CreateChild();
			trace.SetScale(2f);
			var particleEmitter = trace.CreateComponent<ParticleEmitter2D>();
			particleEmitter.Effect = cache.GetParticleEffect2D(Assets.Particles.Explosion);

			// Route (Bezier)
			float direction = player ? 1 : -1;
			var moveMissileAction = new BezierBy(3f, new BezierConfig
				{
					ControlPoint1 = new Vector3(0, 3f * direction, 0),
					ControlPoint2 = new Vector3(RandomHelper.NextRandom(-3f, 3f), 5 * direction, 0),
					EndPosition = new Vector3(0, 8 * direction, 0),//to launch "to" point
				});

			var bulletRotationTask = bulletModelNode.RunActionsAsync(new RotateBy(3f, 0, 1000, 0));
			var bulletMoveTask = bulletNode.RunActionsAsync(new EaseOut(moveMissileAction, 1), new DelayTime(2f)); //a delay to leave the trace effect
			await Task.WhenAll(bulletRotationTask, bulletMoveTask);

			//remove the missile from the scene.
			bulletNode.Remove();
		}
Beispiel #3
0
		public override FiniteTimeAction Reverse ()
		{
			BezierConfig r;

			r.EndPosition = -BezierConfig.EndPosition;
			r.ControlPoint1 = BezierConfig.ControlPoint2 + -BezierConfig.EndPosition;
			r.ControlPoint2 = BezierConfig.ControlPoint1 + -BezierConfig.EndPosition;

			var action = new BezierBy (Duration, r);
			return action;
		}
Beispiel #4
0
        public BezierToState(BezierBy action, Node target)
            : base(action, target)
        {
            var config = BezierConfig;

            config.ControlPoint1 -= StartPosition;
            config.ControlPoint2 -= StartPosition;
            config.EndPosition   -= StartPosition;

            BezierConfig = config;
        }
Beispiel #5
0
		public BezierToState (BezierBy action, Node target)
			: base (action, target)
		{ 
			var config = BezierConfig;

			config.ControlPoint1 -= StartPosition;
			config.ControlPoint2 -= StartPosition;
			config.EndPosition -= StartPosition;

			BezierConfig = config;
		}
Beispiel #6
0
        public override FiniteTimeAction Reverse()
        {
            BezierConfig r;

            r.EndPosition   = -BezierConfig.EndPosition;
            r.ControlPoint1 = BezierConfig.ControlPoint2 + -BezierConfig.EndPosition;
            r.ControlPoint2 = BezierConfig.ControlPoint1 + -BezierConfig.EndPosition;

            var action = new BezierBy(Duration, r);

            return(action);
        }
Beispiel #7
0
		public BezierByState (BezierBy action, Node target)
			: base (action, target)
		{ 
			BezierConfig = action.BezierConfig;
			PreviousPosition = StartPosition = target.Position;
		}
Beispiel #8
0
 public BezierByState(BezierBy action, Node target)
     : base(action, target)
 {
     BezierConfig     = action.BezierConfig;
     PreviousPosition = StartPosition = target.Position;
 }