Beispiel #1
0
        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);
            model.SetMaterial(Material.FromImage(Assets.Textures.XamarinLogo));
            bulletModelNode.SetScale(2f);
            bulletModelNode.Rotate(new Quaternion(45, 0, 0), TransformSpace.Local);
            bulletNode.SetScale(RandomHelper.NextRandom(0.15f, 0.2f));
            // effetto traccia che usa le particelle
            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);

            // rimuovere il missile dalla scena
            bulletNode.Remove();
        }
Beispiel #2
0
        private 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);
            // effetto traccia che usa le particelle
            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)), // crollare
                                             new DelayTime(2f));                          // un ritardo per lasciare l'effetto traccia

            // rimuovere il missile dalla scena
            bulletNode.Remove();
        }