Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 3
0
 async void MoveRandomly()
 {
     while (IsAlive)
     {
         var moveAction = new MoveBy(0.75f, new Vector3(RandomHelper.NextRandom(-0.4f, 0.4f), RandomHelper.NextRandom(-0.3f, 0.3f), 0));
         await Node.RunActionsAsync(moveAction, moveAction.Reverse());
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Set boundaries for random movements
 /// </summary>
 protected async void MoveRandomly(float minX, float maxX, float minY, float maxY, float duration)
 {
     while (IsAlive)
     {
         var moveAction = new MoveBy(duration, new Vector3(RandomHelper.NextRandom(minX, maxX), RandomHelper.NextRandom(minY, maxY), 0));
         await Node.RunActionsAsync(moveAction, moveAction.Reverse());
     }
 }
Ejemplo n.º 5
0
        async void Launch(Node bulletNode)
        {
            await bulletNode.RunActionsAsync(
                new MoveTo(3f, new Vector3(RandomHelper.NextRandom(-6f, 6f), -6, 0)),
                new CallFunc(() => bulletNode.SetScale(0f)));

            //remove the bullet from the scene.
            bulletNode.Remove();
        }
Ejemplo n.º 6
0
        private async void Launch(Node bulletNode)
        {
            await bulletNode.RunActionsAsync(
                new MoveTo(3f, new Vector3(RandomHelper.NextRandom(-6f, 6f), -6, 0)),
                new CallFunc(() => bulletNode.SetScale(0f)));

            // rimuovere il proiettile dalla scena
            bulletNode.Remove();
        }
Ejemplo n.º 7
0
        protected override void Init()
        {
            var cache = Application.ResourceCache;
            var node  = Node;
            var model = node.CreateComponent <StaticModel>();

            model.Model = cache.GetModel(Assets.Models.Enemy2);
            model.SetMaterial(cache.GetMaterial(Assets.Materials.Enemy2).Clone(""));
            node.SetScale(RandomHelper.NextRandom(0.85f, 1f));
            node.Position = new Vector3(0f, 5f, 0f);

            // load weapons:
            node.AddComponent(new Joysticks());

            base.Init();
        }
Ejemplo n.º 8
0
        protected async void StartShooting()
        {
            while (IsAlive && Node.Components.Count > 0)
            {
                foreach (var weapon in Node.Components.OfType <Weapon>())
                {
                    await weapon.FireAsync(false);

                    if (!IsAlive)
                    {
                        return;
                    }
                }
                await Node.RunActionsAsync(new DelayTime(RandomHelper.NextRandom(0.1f, 0.5f)));
            }
        }
Ejemplo n.º 9
0
        async void SpawnCoins()
        {
            var player = Player;

            while (Player.IsAlive && player == Player)
            {
                var coinNode = scene.CreateChild();
                coinNode.Position = new Vector3(RandomHelper.NextRandom(-2.5f, 2.5f), 5f, 0);
                var coin = new Apple();
                coinNode.AddComponent(coin);
                await coin.FireAsync(false);

                await scene.RunActionsAsync(new DelayTime(3f));

                coinNode.Remove();
            }
        }
Ejemplo n.º 10
0
        Node CreateTile(int index)
        {
            var  cache     = Application.ResourceCache;
            Node tile      = Node.CreateChild();
            var  planeNode = tile.CreateChild();

            planeNode.Scale = new Vector3(BackgroundScale, 0.0001f, BackgroundScale);
            var planeObject = planeNode.CreateComponent <StaticModel>();

            planeObject.Model = cache.GetModel(Assets.Models.Plane);
            planeObject.SetMaterial(cache.GetMaterial(Assets.Materials.Grass));

            // area for trees:
            var sizeZ = BackgroundScale / 2.1f;
            var sizeX = BackgroundScale / 3.8f;

            Node treeNode = tile.CreateChild();

            treeNode.Rotate(new Quaternion(0, RandomHelper.NextRandom(0, 5) * 90, 0), TransformSpace.Local);
            treeNode.SetScale(0.35f);            //RandomHelper.NextRandom(0.33f, 0.38f));
            var treeGroup = treeNode.CreateComponent <StaticModel>();

            treeGroup.Model = cache.GetModel(Assets.Models.Tree);
            treeGroup.SetMaterial(cache.GetMaterial(Assets.Materials.TreeMaterial));

            for (float i = -sizeX; i < sizeX; i += 2.6f)
            {
                for (float j = -sizeZ; j < sizeZ; j += 3f)
                {
                    var clonedTreeNode = treeNode.Clone(CreateMode.Local);
                    clonedTreeNode.Position = new Vector3(i + RandomHelper.NextRandom(-0.5f, 0.5f), 0, j);
                }
            }

            treeNode.Remove();

            tile.Rotate(new Quaternion(270 + BackgroundRotationX, 0, 0), TransformSpace.Local);
            tile.RotateAround(new Vector3(0, 0, 0), new Quaternion(0, BackgroundRotationY, 0), TransformSpace.Local);
            var tilePosX = BackgroundScale * (float)Math.Sin(MathHelper.DegreesToRadians(90 - BackgroundRotationX));
            var tilePosY = BackgroundScale * (float)Math.Sin(MathHelper.DegreesToRadians(BackgroundRotationX));

            tile.Position = new Vector3(0, (tilePosX + 0.01f) * index, tilePosY * index + FlightHeight);
            return(tile);
        }
Ejemplo n.º 11
0
        protected override async void Init()
        {
            InitialRotation = new Quaternion(180, 270, -30);
            var cache = Application.ResourceCache;
            var node  = Node;
            var model = node.CreateComponent <StaticModel>();

            model.Model = cache.GetModel(Assets.Models.Enemy1);
            model.SetMaterial(cache.GetMaterial(Assets.Materials.Enemy1).Clone(""));
            node.SetScale(RandomHelper.NextRandom(0.1f, 0.12f));
            node.Position = new Vector3(0f, 5f, 0f);
            // carico armi
            node.AddComponent(new XamarinCube());
            node.Position = new Vector3(3 * (RandomHelper.NextBoolRandom() ? 1 : -1), RandomHelper.NextRandom(0, 2), 0);
            await Node.RunActionsAsync(new MoveTo(1f, new Vector3(RandomHelper.NextRandom(-2, 2), RandomHelper.NextRandom(2, 4), 0)));

            MoveRandomly(minX: -2f, maxX: 2f, minY: -1f, maxY: 1f, duration: 0.5f);
            StartShooting();
        }