SamplyGame.StartMenu.ShowStartMenu C# (CSharp) Method

ShowStartMenu() public method

public ShowStartMenu ( bool gameOver ) : System.Threading.Tasks.Task
gameOver bool
return System.Threading.Tasks.Task
		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;
		}

Usage Example

コード例 #1
0
        async void CreateScene()
        {
            scene = new Scene();
            scene.CreateComponent <Octree>();

            var physics = scene.CreateComponent <PhysicsWorld>();

            physics.SetGravity(new Vector3(0, 0, 0));

            // Camera
            var cameraNode = scene.CreateChild();

            cameraNode.Position = (new Vector3(0.0f, 0.0f, -10.0f));
            cameraNode.CreateComponent <Camera>();
            Viewport = new Viewport(Context, scene, cameraNode.GetComponent <Camera>(), null);

            if (Platform != Platforms.Android && Platform != Platforms.iOS)
            {
                RenderPath effectRenderPath = Viewport.RenderPath.Clone();
                var        fxaaRp           = ResourceCache.GetXmlFile(Assets.PostProcess.FXAA3);
                effectRenderPath.Append(fxaaRp);
                Viewport.RenderPath = effectRenderPath;
            }
            Renderer.SetViewport(0, Viewport);

            var zoneNode = scene.CreateChild();
            var zone     = zoneNode.CreateComponent <Zone>();

            zone.SetBoundingBox(new BoundingBox(-300.0f, 300.0f));
            zone.AmbientColor = new Color(1f, 1f, 1f);

            // UI
            coinsText = new Text();
            coinsText.HorizontalAlignment = HorizontalAlignment.Right;
            coinsText.SetFont(ResourceCache.GetFont(Assets.Fonts.Font), Graphics.Width / 20);
            UI.Root.AddChild(coinsText);


            hsCoinsText = new Text();
            hsCoinsText.HorizontalAlignment = HorizontalAlignment.Left;
            hsCoinsText.SetFont(ResourceCache.GetFont(Assets.Fonts.Font), Graphics.Width / 20);
            UI.Root.AddChild(hsCoinsText);
            Input.SetMouseVisible(true, false);

            // Background
            var background = new Background();

            scene.AddComponent(background);
            background.Start();

            // Lights:
            var lightNode = scene.CreateChild();

            lightNode.Position = new Vector3(0, -5, -40);
            lightNode.AddComponent(new Light {
                Range = 120, Brightness = 0.8f
            });

            // Game logic cycle
            bool firstCycle = true;

            while (true)
            {
                //
                StartMenu = scene.CreateComponent <StartMenu>();
                NewStartMenu?.Invoke(StartMenu);
                if (!firstCycle)
                {
                    FinishedGame?.Invoke(Coins);
                }
                await StartMenu.ShowStartMenu(!firstCycle);                 //wait for "start"

                StartMenu.Remove();
                RemovedStartMenu?.Invoke(StartMenu);

                await StartGame();

                firstCycle = false;
            }
        }