Esempio n. 1
0
        protected override void SetupScene()
        {
            Board = new MarbleBoard
            {
                OnMatch      = OnMatch,
                OnNewMarbles = OnNewMarbles,
            };

            //RenderContext.WorldPositionMatrix = Matrix4.CreateScale(1, -1, 1);
            //RenderContext.PrimaryRenderPipeline = RenderContext.GetPipeline<ForwardRenderPipeline>();
            DefaultKeyBindings = false;

            SceneContext.AddActor(BoardActor = new Actor(BoardComponent = new SceneComponent()
            {
                //RelativeRotation = new Vector3(0, 0, 0.02f).ToQuaternion(),
                RelativeTranslation = new Vector3(0, 0, 0.05f),
            }));

            BoardComponent.AddComponent(NextMarbleComponent = new SceneComponent()
            {
                RelativeTranslation = new Vector3(10, -3, 0),
                RelativeScale       = new Vector3(0.5f),
            });

            BoardComponent.AddComponent(NextMarbleBoardComponent = new SceneComponent()
            {
                RelativeTranslation = new Vector3(0, 0, -0.2f),
                // RelativeScale = new Vector3(0.5f),
                // TranslationMatrix = Matrix4.CreateScale(2),
                // IsAbsoluteRotation = true,
                // IsAbsoluteScale = true,
                // IsAbsoluteTranslation = true,
            });

            var camSize = new Vector2(9 * RenderContext.ScreenAspectRatio, 9);

            RenderContext.Camera = new OrthographicCamera(new Vector3(4.5f + ((camSize.X - camSize.Y) / 2f) - 0.5f, -4.5f + 0.5f, 25))
            {
                Size      = camSize,
                NearPlane = 1f,
                FarPlane  = 100.0f,
                Facing    = (float)Math.PI / 2,
                Pitch     = -((float)(Math.PI / 2) - 0.00001f),
            };

            SceneContext.AddActor(new Actor(new CubeComponent()
            {
                Name     = "Ground",
                Material = new Material
                {
                    Color     = new Vector4(0.4f, 0.6f, 0.6f, 1),
                    Shininess = 1.0f,
                },
                RelativeScale       = new Vector3(50, 50, 1),
                RelativeTranslation = new Vector3(0f, 0f, -0.5f),
            }));

            BoardComponent.AddComponent(new CubeComponent()
            {
                Name     = "Board",
                Material = new Material
                {
                    Color     = new Vector4(0.4f, 0.6f, 0.6f, 1) * 1.1f,
                    Shininess = 1.0f,
                },
                RelativeScale       = new Vector3(Board.Width, Board.Height, 1),
                RelativeTranslation = new Vector3((Board.Width / 2f) - 0.5f, (Board.Height / 2f) - 0.5f, -0.5f),
                TranslationMatrix   = BoardTranslationMatrix,
            });

            BoardComponent.AddComponent(new GridPlaneComponent(9, false)
            {
                Name = "Grid",
                RelativeTranslation = new Vector3(-0.5f, -0.5f + 9, 0.01f),
                TranslationMatrix   = BoardTranslationMatrix,
            });
            SceneContext.AddActor(new Actor(new CrossLineComponent(10, true)
            {
                Name = "CenterCross",
                RelativeTranslation = new Vector3(0f, 0f, 0.02f),
                RelativeScale       = new Vector3(1.0f),
            }));

            var alchemyCircleOptions = new Generators.AlchemyCircle.AlchemyCircleOptions
            {
                Seed      = 1919654508,
                Size      = 256,
                Thickness = 4,
            };
            var decalMaterial = new Material()
            {
                DiffuseTexture   = Texture.CreateFromFile(AssetManager.GetAssetsPath("Textures/AlchemyCircle/.png", alchemyCircleOptions)),
                Color            = new Vector4(57f / 255f, 1, 20f / 255f, 1),
                Ambient          = 0.3f,
                Shininess        = 32.0f,
                SpecularStrength = 0.5f,
                CastShadow       = false,
                PipelineType     = PipelineType.Forward,
                UseTransparency  = true,
            };

            BoardComponent.AddComponent(new QuadComponent()
            {
                Material            = decalMaterial,
                Name                = "GroundCursor",
                RelativeTranslation = new Vector3(0, 1, 0.051f),
                RelativeScale       = new Vector3(2f, 2f, 0.1f),
                DrawPriority        = 101,
            });

            BoardComponent.AddComponent(new QuadComponent()
            {
                Name              = "MarbleSelector",
                Material          = decalMaterial,
                TranslationMatrix = BoardTranslationMatrix,
                //Material = material,
                RelativeTranslation = new Vector3(0, 1, 0.05f),
                RelativeScale       = new Vector3(2f, 2f, 0.1f),
                Visible             = false,
                DrawPriority        = 100,
            });

            SceneContext.AddActor(new Actor(new PointLightComponent()
            {
                RelativeTranslation = new Vector3(0, 2, 3.5f),
                Name = "MovingLight",
                //Enabled = false,
            }));

            SceneContext.AddActor(new Actor(new PointLightComponent()
            {
                RelativeTranslation = new Vector3(2f, 0.5f, 4.25f),
                Name = "StaticLight",
            }));

            var flowContainer = new UIFlowContainer()
            {
                Name = "UI",
                DefaultChildSizes = new Vector2(0, 50),
                ExtraChildMargin  = new UIAnchors(10, 10, 10, 0),
                Location          = new Vector2(1000, 0),
                Size = new Vector2(200, 0),
            };

            SceneContext.AddActor(new Actor(flowContainer));

            // flowContainer.AddComponent(new UIMarbles()
            // {
            //     Name = "UI",
            // });

            flowContainer.AddComponent(new UILabelComponent()
            {
                Name  = "LastScore",
                Color = Color.White,
            });
            flowContainer.AddComponent(new UILabelComponent()
            {
                Name  = "TotalScore",
                Color = Color.White,
            });

            SceneContext.AddActor(new Actor(new StatsComponent()
            {
                Name = "Stats",
            }));

            UIButton bt;

            flowContainer.AddComponent(bt = new UIButton()
            {
                Name           = "Exit",
                Text           = "Exit",
                Color          = Color.White,
                BackColor      = new Color(new Rgba32(0, 0, 0, 0.5f)),
                BackColorHover = new Color(new Rgba32(0, 0, 0, 0.8f)),
                BorderColor    = new Color(new Rgba32(0, 0, 0, 0.8f)),
                // Location = new Vector2(620, 200),
                // Size = new Vector2(100, 100),
            });
            bt.Click += (e) =>
            {
                Stop();
            };

            SelectorTween = new Tween1
            {
                Duration  = TimeSpan.FromSeconds(10),
                ScaleFunc = ScaleFuncs.Linear(MathF.PI * 2),
                Repeat    = true,
            };
            SelectorTween.Start();

            RemoveTween = new Tween1
            {
                Duration  = TimeSpan.FromSeconds(0.75),
                ScaleFunc = ScaleFuncs.LinearReverse(MarbleScale),
            };
            RemoveTween.TweenComplete += OnAnimFinshed_MarbleRemoved;

            CreateTween = new Tween1
            {
                Duration  = TimeSpan.FromSeconds(0.75),
                ScaleFunc = ScaleFuncs.Linear(MarbleScale),
            };
            CreateTween.TweenComplete += OnAnimationFinished_MarbleCreated;

            MoveTween = new Tween1()
            {
                ScaleFunc = ScaleFuncs.Power10EaseInOut,
            };
            MoveTween.TweenComplete += OnAnimFinished_MarbleMoved;
        }
Esempio n. 2
0
        protected override void SetupScene()
        {
            // GameMaterial material = new GameMaterial
            // {
            //     DiffuseTexture = GameTexture.GetFromFile("Textures/woodenbox.png"),
            //     SpecularTexture = GameTexture.GetFromFile("Textures/woodenbox_specular.png"),
            //     Ambient = 0.2f,
            //     Shininess = 32f,
            //     PipelineType = PipelineType.Forward,
            //     CastShadow = true,
            // };

            // GameContext.AddActor(new Actor(new DebugCubeComponent()
            // {
            //     Name = "Box1",
            //     Transform = new Transform
            //     {
            //         Scale = new Vector3(1),
            //         Rotation = new Vector3(0, 0, 0.5f).ToQuaternion(),
            //         Translation = new Vector3(0f, 0, 0.5f),
            //     },
            //     Material = material,
            // }));

            // GameMaterial material2 = new GameMaterial
            // {
            //     DiffuseTexture = GameTexture.GetFromFile("Textures/woodenbox.png"),
            //     SpecularTexture = GameTexture.GetFromFile("Textures/woodenbox_specular.png"),
            //     Shininess = 32f,
            //     Ambient = 0.2f,
            //     PipelineType = PipelineType.Deferred,
            //     CastShadow = true,
            // };

            // GameContext.AddActor(new Actor(new DebugCubeComponent()
            // {
            //     Name = "Box2",
            //     Transform = new Transform
            //     {
            //         Scale = new Vector3(1),
            //         Rotation = new Vector3(0, 0, 0.5f).ToQuaternion(),
            //         Translation = new Vector3(1.0f, 0, 0.5f),
            //     },
            //     Material = material2,
            // }));

            // GameContext.AddActor(new Actor(new PointLightComponent()
            // {
            //     RelativeTranslation = new Vector3(-0.2f, -2.1f, 1.85f),
            //     Name = "StaticLight",
            // }));

            // GameContext.AddActor(new Actor(new CubeComponent()
            // {
            //     Name = "Ground",
            //     RelativeScale = new Vector3(50, 50, 1),
            //     RelativeTranslation = new Vector3(0f, 0f, -0.5f),
            //     Material = material,
            // }));

            // return;
            //---

            //RenderContext.PrimaryRenderPipeline = RenderContext.GetPipeline<ForwardRenderPipeline>();

            var materialWood1 = new Material()
            {
                DiffuseTexture   = Texture.GetFromFile("Textures/woodenbox.png"),
                SpecularTexture  = Texture.GetFromFile("Textures/woodenbox_specular.png"),
                Ambient          = 0.3f,
                Shininess        = 32.0f,
                SpecularStrength = 0.5f,
                CastShadow       = true,
            };

            var materialWood2 = new Material()
            {
                DiffuseTexture   = Texture.GetFromFile("Textures/wood.png"),
                SpecularTexture  = Texture.GetFromFile("Textures/woodenbox_specular.png"),
                Ambient          = 0.3f,
                Shininess        = 32.0f,
                SpecularStrength = 0.5f,
                CastShadow       = true,
            };

            SceneContext.AddActor(new Actor(new SphereComponent()
            {
                Name = "CompSphere",
                RelativeTranslation = new Vector3(-3, 0, 0),
                RelativeScale       = new Vector3(1.5f),
                Material            = materialWood2,
            }));

            SceneContext.AddActor(new Actor(new CubeComponent()
            {
                Name                = "Ground",
                RelativeScale       = new Vector3(50, 50, 1),
                RelativeTranslation = new Vector3(0f, 0f, -0.5f),
                Material            = materialWood1,
            }));

            SceneContext.AddActor(new Actor(new GridPlaneComponent(10, true)
            {
                Name = "GridPlaneXY",
                RelativeTranslation = new Vector3(0f, 0f, 0.01f),
            }));
            SceneContext.AddActor(new Actor(new GridPlaneComponent(10, true)
            {
                Name = "GridPlaneYZ",
                RelativeTranslation = new Vector3(-10f, 0f, 0.01f),
                RelativeRotation    = new Vector3(0, 0.25f, 0).ToQuaternion(),
            }));
            SceneContext.AddActor(new Actor(new GridPlaneComponent(10, true)
            {
                Name = "GridPlaneXZ",
                RelativeTranslation = new Vector3(0f, 10f, 0.01f),
                RelativeRotation    = new Vector3(0.25f, 0, 0).ToQuaternion(),
            }));
            SceneContext.AddActor(new Actor(new CrossLineComponent(10, true)
            {
                Name = "CenterCross",
                RelativeTranslation = new Vector3(0f, 0f, 0.02f),
                RelativeScale       = new Vector3(2.0f),
            }));
            // GameContext.AddActor(new Actor(new UIImage("Textures/wood.png")
            // {
            //     Name = "UI-Image-Alone",
            //     RectanglePixels = new RectangleF(0, 0, 30f, 30f),
            // }));

            // -- UI

            var flowContainer = new UIFlowContainer()
            {
                DefaultChildSizes = new Vector2(0, 50),
                ExtraChildMargin  = new UIAnchors(10, 10, 10, 0),
            };

            SceneContext.AddActor(new Actor(flowContainer));

            //flowContainer.AddComponent(new UIImage("Textures/woodenbox_specular.png")
            //{
            //    Name = "ScreenTexture1.1",
            //    //Size = new Vector2(100, 100),
            //    //Margin = new UIAnchors(20, 20, 20, 20),
            //});

            //flowContainer.AddComponent(new UIImage("Textures/woodenbox_specular.png")
            //{
            //    Name = "ScreenTexture1.1",
            //    //Size = new Vector2(100, 100),
            //    //Margin = new UIAnchors(20, 20, 20, 20),
            //});

            //flowContainer.AddComponent(new UIButton()
            //{
            //    Name = "bt1",
            //    //Size = new Vector2(100, 100),
            //    //Margin = new UIAnchors(20, 20, 20, 20),
            //});

            flowContainer.AddComponent(new UISlider()
            {
                Name     = "bt1",
                MinValue = 20,
                MaxValue = 40,
                Value    = 25,
                //Size = new Vector2(100, 100),
                //Margin = new UIAnchors(20, 20, 20, 20),
            });

            // --

            SceneContext.AddActor(new Actor(new StatsComponent()
            {
                Name        = "Stats",
                CustomOrder = 10,
            }));

            SceneContext.AddActor(new Actor(new LineComponent(new Vector3(0, 0, 0), new Vector3(2, 2, 2))
            {
                Name = "DebugLine",
            }));

            SceneContext.AddActor(new Actor(new DirectionalLightComponent()
            {
                RelativeTranslation = new Vector3(0, 2, 2.5f),
                Name = "MovingLight",
            }));
            SceneContext.AddActor(new Actor(new DirectionalLightComponent()
            {
                RelativeTranslation = new Vector3(2f, 0.5f, 3.25f),
                Name = "StaticLight",
            }));

            SceneContext.AddActor(new Actor(new CubeComponent()
            {
                Name = "GroundCursor",
                RelativeTranslation = new Vector3(0, 1, 0.05f),
                RelativeScale       = new Vector3(1.0f, 1.0f, 0.1f),
                Material            = materialWood1,
            }));

            SceneContext.AddActor(new Actor(new DebugCubeComponent()
            {
                Name                = "Box1",
                RelativeRotation    = new Vector3(0, 0, 0.5f).ToQuaternion(),
                RelativeScale       = new Vector3(1),
                RelativeTranslation = new Vector3(0, 0, 0.5f),
                Material            = materialWood1,
            }));

            SceneContext.AddActor(new Actor(new CubeComponent()
            {
                Name                = "Box2",
                RelativeScale       = new Vector3(1),
                RelativeTranslation = new Vector3(1.5f, 1.5f, 0.5f),
                Material            = materialWood1,
            }));

            SceneContext.AddActor(new Actor(new SphereComponent()
            {
                Name = "Sphere1",
                RelativeTranslation = new Vector3(3f, 3f, 0.5f),
                Material            = materialWood1,
            }));
            SceneContext.AddActor(new Actor(new CubeComponent()
            {
                Name                = "Box4",
                RelativeScale       = new Vector3(1),
                RelativeTranslation = new Vector3(4f, 3f, 0.5f),
                Material            = materialWood1,
            }));

            SceneContext.AddActor(new Actor(
                                      new SceneComponent(
                                          new CubeComponent
            {
                RelativeTranslation = new Vector3(-1, 0, 0),
                Material            = materialWood1,
            },
                                          new SphereComponent
            {
                RelativeTranslation = new Vector3(1f, 0, 0),
                Material            = materialWood1,
            })
            {
                Name = "CompGroup1",
                RelativeTranslation = new Vector3(0, 18, 1f),
                RelativeRotation    = new Quaternion(0, 0, MathF.PI / 4),
                RelativeScale       = new Vector3(2f),
            })
            {
                Name = "GroupActor1",
            });

            SceneContext.AddActor(new Actor(new DebugCubeComponent()
            {
                Name                = "BoxFar1",
                RelativeScale       = new Vector3(1),
                RelativeTranslation = new Vector3(18, 0, 0.5f),
                Material            = materialWood1,
            }));
            SceneContext.AddActor(new Actor(new DebugCubeComponent()
            {
                Name                = "BoxFar2",
                RelativeScale       = new Vector3(1),
                RelativeTranslation = new Vector3(16, 1, 0.5f),
                Material            = materialWood1,
                // Enabled = false,
            }));

            // For performance reasons, skybox should rendered as last
            SceneContext.AddActor(new Actor(new SkyBoxComponent()
            {
                Name = "Sky",
            }));

            var materialWoodRemoveTest = new Material()
            {
                DiffuseTexture   = Texture.GetFromFile("Textures/woodenbox.png"),
                SpecularTexture  = Texture.GetFromFile("Textures/woodenbox_specular.png"),
                Ambient          = 0.3f,
                Shininess        = 32.0f,
                SpecularStrength = 0.5f,
                CastShadow       = true,
            };

            SceneContext.AddActor(new Actor(new DebugCubeComponent()
            {
                Name                = "RemoveTets",
                RelativeScale       = new Vector3(1),
                RelativeTranslation = new Vector3(18, 0, 0.5f),
                Material            = materialWoodRemoveTest,
            }));
            SceneContext.AddActor(new Actor(new DebugCubeComponent()
            {
                Name                = "RemoveTets",
                RelativeScale       = new Vector3(1),
                RelativeTranslation = new Vector3(18, 0, 0.5f),
                Material            = materialWoodRemoveTest,
            }));

            LightTween = new Tween2
            {
                LerpFunc = Tween2.Circle(),
                Duration = TimeSpan.FromSeconds(8),
                Repeat   = true,
                Enabled  = true,
            };
            BoxTween = new Tween1
            {
                ScaleFunc = ScaleFuncs.Linear(AxMath.Norm2Rad),
                Duration  = TimeSpan.FromSeconds(6),
                Repeat    = true,
                Enabled   = true,
            };
        }