예제 #1
0
파일: Background.cs 프로젝트: kaifudeng/ck1
        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.Scale = new Vector3(0.3f, 0.4f, 0.3f);
            var treeGroup = treeNode.CreateComponent <StaticModel>();

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

            for (float i = -sizeX; i < sizeX; i += 3.2f)
            {
                for (float j = -sizeZ; j < sizeZ; j += 3.2f)
                {
                    var clonedTreeNode = treeNode.Clone(CreateMode.Local);
                    clonedTreeNode.Position = new Vector3(i + RandomHelper.NextRandom(-0.3f, 0.3f), 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);
        }
예제 #2
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;
        }