Exemplo n.º 1
0
        public async Task ShowStartMenu(bool gameOver)
        {
            var cache = Application.ResourceCache;

            bigAircraft = Node.CreateChild();
            var model = bigAircraft.CreateComponent <StaticModel>();

            if (gameOver)
            {
                model.Model = cache.GetModel(Assets.Models.Enemy1);
                model.SetMaterial(cache.GetMaterial(Assets.Materials.Enemy1).Clone(""));
                bigAircraft.SetScale(0.3f);
                bigAircraft.Rotate(new Quaternion(180, 90, 20), TransformSpace.Local);
            }
            else
            {
                model.Model = cache.GetModel(Assets.Models.Player);
                model.SetMaterial(cache.GetMaterial(Assets.Materials.Player).Clone(""));
                bigAircraft.SetScale(1f);
                bigAircraft.Rotate(new Quaternion(0, 40, -50), TransformSpace.Local);
            }

            bigAircraft.Position = new Vector3(10, 2, 10);
            bigAircraft.RunActions(new RepeatForever(new Sequence(new RotateBy(1f, 0f, 0f, 5f), new RotateBy(1f, 0f, 0f, -5f))));

            //TODO: rotor should be defined in the model + animation
            rotor = bigAircraft.CreateChild();
            var rotorModel = rotor.CreateComponent <Box>();

            rotorModel.Color = Color.White;
            rotor.Scale      = new Vector3(0.1f, 1.5f, 0.1f);
            rotor.Position   = new Vector3(0, 0, -1.3f);
            var rotorAction = new RepeatForever(new RotateBy(1f, 0, 0, 360f * 6)); //RPM

            rotor.RunActions(rotorAction);

            menuLight          = bigAircraft.CreateChild();
            menuLight.Position = new Vector3(-3, 6, 2);
            menuLight.AddComponent(new Light {
                LightType = LightType.Point, Brightness = 0.3f
            });

            await bigAircraft.RunActionsAsync(new EaseIn(new MoveBy(1f, new Vector3(-10, -2, -10)), 2));

            textBlock = new Text();
            textBlock.HorizontalAlignment = HorizontalAlignment.Center;
            textBlock.VerticalAlignment   = VerticalAlignment.Bottom;
            textBlock.Value = gameOver ? "GAME OVER" : "TAP TO START";
            textBlock.SetFont(cache.GetFont(Assets.Fonts.Font), Application.Graphics.Width / 15);
            Application.UI.Root.AddChild(textBlock);

            menuTaskSource = new TaskCompletionSource <bool>();
            finished       = false;
            await menuTaskSource.Task;
        }
Exemplo n.º 2
0
        protected override async void OnUpdate(float timeStep)
        {
            if (finished)
            {
                return;
            }

            var input = Application.Input;

            if (input.GetMouseButtonDown(MouseButton.Left) || input.NumTouches > 0)
            {
                finished = true;
                Application.UI.Root.RemoveChild(textBlock, 0);
                await bigAircraft.RunActionsAsync(new EaseIn(new MoveBy(1f, new Vector3(-10, -2, -10)), 3));

                rotor.RemoveAllActions();
                menuTaskSource.TrySetResult(true);
            }
        }
Exemplo n.º 3
0
        async void RotateBackground()
        {
            while (true)
            {
                // calculate positions using Law of sines
                var x = BackgroundScale * (float)Math.Sin(MathHelper.DegreesToRadians(90 - BackgroundRotationX));
                var y = BackgroundScale * (float)Math.Sin(MathHelper.DegreesToRadians(BackgroundRotationX)) + FlightHeight;

                var moveTo = x + 1f; //a small adjusment to hide that gap between two tiles
                var h      = (float)Math.Tan(MathHelper.DegreesToRadians(BackgroundRotationX)) * moveTo;
                await Task.WhenAll(frontTile.RunActionsAsync(new MoveBy(1 / BackgroundSpeed, new Vector3(0, -moveTo, -h))),
                                   rearTile.RunActionsAsync(new MoveBy(1 / BackgroundSpeed, new Vector3(0, -moveTo, -h))));

                //switch tiles
                var tmp = frontTile;
                frontTile = rearTile;
                rearTile  = tmp;

                rearTile.Position = new Vector3(0, x, y);
            }
        }