Esempio n. 1
0
        public override async Task Execute()
        {
            spriteSheet          = BulletSheet;
            agentSpriteComponent = Entity.Get <SpriteComponent>();
            var animComponent = Entity.Get <AnimationComponent>();
            PlayingAnimation playingAnimation = null;

            // Calculate offset of the bullet from the Agent if he is facing left and right side // TODO improve this
            var bulletOffset = new Vector3(1.3f, 1.65f, 0f);

            // Initialize game entities
            if (!IsLiveReloading)
            {
                shootDelayCounter     = 0f;
                isAgentFacingRight    = true;
                currentAgentAnimation = AgentAnimation.Idle;
            }
            CurrentAgentAnimation = currentAgentAnimation;

            var normalScaleX = Entity.Transform.Scale.X;

            var bulletCS = BulletColliderShape;

            Task animTask = null;

            while (Game.IsRunning)
            {
                await Script.NextFrame();

                var inputState = GetKeyboardInputState();

                if (inputState == InputState.None)
                {
                    inputState = GetPointerInputState();
                }

                if (inputState == InputState.RunLeft || inputState == InputState.RunRight)
                {
                    // Update Agent's position
                    var dt = (float)Game.UpdateTime.Elapsed.TotalSeconds;

                    Entity.Transform.Position.X += ((inputState == InputState.RunRight) ? AgentMoveDistance : -AgentMoveDistance) * dt;

                    if (Entity.Transform.Position.X < -gameWidthHalfX)
                    {
                        Entity.Transform.Position.X = -gameWidthHalfX;
                    }

                    if (Entity.Transform.Position.X > gameWidthHalfX)
                    {
                        Entity.Transform.Position.X = gameWidthHalfX;
                    }

                    isAgentFacingRight = inputState == InputState.RunRight;

                    // If agent face left, flip the sprite
                    Entity.Transform.Scale.X = isAgentFacingRight ? normalScaleX : -normalScaleX;

                    // Update the sprite animation and state
                    CurrentAgentAnimation = AgentAnimation.Run;
                    if (playingAnimation == null || playingAnimation.Name != "Run")
                    {
                        playingAnimation = animComponent.Play("Run");
                    }
                }
                else if (inputState == InputState.Shoot)
                {
                    if (animTask != null && !animTask.IsCompleted)
                    {
                        continue;
                    }
                    if (animTask != null && animTask.IsCompleted)
                    {
                        playingAnimation = null;
                    }

                    animTask = null;

                    var rb = new RigidbodyComponent {
                        CanCollideWith = CollisionFilterGroupFlags.CustomFilter1, CollisionGroup = CollisionFilterGroups.DefaultFilter
                    };
                    rb.ColliderShapes.Add(new ColliderShapeAssetDesc {
                        Shape = bulletCS
                    });

                    // Spawns a new bullet
                    var bullet = new Entity
                    {
                        new SpriteComponent {
                            SpriteProvider = SpriteFromSheet.Create(spriteSheet, "bullet")
                        },
                        rb,
                        new BeamScript()
                    };
                    bullet.Name = "bullet";

                    bullet.Transform.Position = (isAgentFacingRight) ? Entity.Transform.Position + bulletOffset : Entity.Transform.Position + (bulletOffset * new Vector3(-1, 1, 1));
                    bullet.Transform.UpdateWorldMatrix();

                    SceneSystem.SceneInstance.RootScene.Entities.Add(bullet);

                    rb.LinearFactor  = new Vector3(1, 0, 0);
                    rb.AngularFactor = new Vector3(0, 0, 0);
                    rb.ApplyImpulse(isAgentFacingRight ? new Vector3(25, 0, 0) : new Vector3(-25, 0, 0));

                    // Start animation for shooting
                    CurrentAgentAnimation = AgentAnimation.Shoot;
                    if (playingAnimation == null || playingAnimation.Name != "Attack")
                    {
                        playingAnimation = animComponent.Play("Attack");
                        animTask         = animComponent.Ended(playingAnimation);
                    }
                }
                else
                {
                    CurrentAgentAnimation = AgentAnimation.Idle;
                    if (playingAnimation == null || playingAnimation.Name != "Stance")
                    {
                        playingAnimation = animComponent.Play("Stance");
                    }
                }
            }
        }
Esempio n. 2
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var sprites = Content.Load <SpriteSheet>("UIImages");

            var img1 = new ImageElement {
                Name = "UV 1 stack panel", Source = (SpriteFromTexture) new Sprite(Content.Load <Texture>("uv"))
            };
            var img2 = new ImageElement {
                Name = "UV 2 stack panel", Source = (SpriteFromTexture) new Sprite(Content.Load <Texture>("uv"))
            };

            img3 = new ImageElement {
                Name = "UV 3 stack panel", Source = (SpriteFromTexture) new Sprite(Content.Load <Texture>("uv"))
            };

            stackPanel = new StackPanel {
                Orientation = Orientation.Vertical
            };
            stackPanel.Children.Add(img1);
            stackPanel.Children.Add(img2);
            stackPanel.Children.Add(img3);

            var img4 = new ImageElement {
                Name = "UV grid", Source = (SpriteFromTexture) new Sprite(Content.Load <Texture>("uv"))
            };
            var img5 = new ImageElement {
                Name = "UV grid 2", Source = (SpriteFromTexture) new Sprite(Content.Load <Texture>("uv"))
            };
            var img6 = new ImageElement {
                Name = "Game screen grid", Source = SpriteFromSheet.Create(sprites, "GameScreen")
            };

            img4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            img4.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            img5.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            img5.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            img6.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            img6.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            img6.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);

            grid = new UniformGrid {
                Columns = 2, Rows = 2
            };
            grid.Children.Add(img4);
            grid.Children.Add(img5);
            grid.Children.Add(img6);

            scrollViewer = new ScrollViewer {
                Content = grid, ScrollMode = ScrollingMode.HorizontalVertical
            };

            contentDecorator = new ContentDecorator {
                Content = scrollViewer
            };

            UIComponent.Page = new Engine.UIPage {
                RootElement = contentDecorator
            };
        }
Esempio n. 3
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            sprites = Content.Load <SpriteSheet>("UIImages");

            var lifeBar = new ImageElement {
                Source = SpriteFromSheet.Create(sprites, "Logo"), HorizontalAlignment = HorizontalAlignment.Center
            };

            lifeBar.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);

            var quitGameButton = new Button
            {
                Content = new TextBlock {
                    Text = "Quit Game", Font = Content.Load <SpriteFont>("MicrosoftSansSerif15")
                },
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Left,
                Padding             = Thickness.UniformRectangle(10),
            };

            quitGameButton.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            quitGameButton.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            quitGameButton.Click += (sender, args) => Exit();

            modalButton1Text = new TextBlock {
                Text = "Close Modal window 1", Font = Content.Load <SpriteFont>("MicrosoftSansSerif15")
            };
            var modalButton1 = new Button
            {
                Name                = "Button Modal 1",
                Content             = modalButton1Text,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Padding             = Thickness.UniformRectangle(10),
            };

            modalButton1.Click += ModalButton1OnClick;
            modal1              = new ModalElement {
                Content = modalButton1, Name = "Modal 1"
            };
            modal1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);
            modal1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            modal1.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            modal1.OutsideClick += Modal1OnOutsideClick;

            modalButton2Text = new TextBlock {
                Text = "Close Modal window 2", Font = Content.Load <SpriteFont>("MicrosoftSansSerif15")
            };
            var modalButton2 = new Button
            {
                Name                = "Button Modal 2",
                Content             = modalButton2Text,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Padding             = Thickness.UniformRectangle(10),
            };

            modalButton2.Click += ModalButton2OnClick;
            modal2              = new ModalElement {
                Content = modalButton2, Name = "Modal 2"
            };
            modal2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2);
            modal2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            modal2.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            modal2.OutsideClick += Modal2OnOutsideClick;

            uniformGrid = new UniformGrid {
                Columns = 3, Rows = 3
            };
            uniformGrid.Children.Add(modal1);
            uniformGrid.Children.Add(modal2);
            uniformGrid.Children.Add(lifeBar);
            uniformGrid.Children.Add(quitGameButton);

            UIComponent.RootElement = uniformGrid;
        }
Esempio n. 4
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            sprites = Content.Load <SpriteSheet>("UIImages");

            // Also draw a texture during the clear renderer
            // TODO: Use a custom compositor as soon as we have visual scripting?
            var topChildRenderer = ((SceneCameraRenderer)SceneSystem.GraphicsCompositor.Game).Child;
            var forwardRenderer  = (topChildRenderer as SceneRendererCollection)?.Children.OfType <ForwardRenderer>().FirstOrDefault() ?? (ForwardRenderer)topChildRenderer;

            forwardRenderer.Clear = new ClearAndDrawTextureRenderer {
                Color = forwardRenderer.Clear.Color, Texture = sprites["GameScreen"].Texture
            };

            var lifeBar = new ImageElement {
                Source = SpriteFromSheet.Create(sprites, "Logo"), HorizontalAlignment = HorizontalAlignment.Center
            };

            lifeBar.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);

            var quitText = new TextBlock {
                Text = "Quit Game", Font = Content.Load <SpriteFont>("MicrosoftSansSerif15")
            };

            ApplyTextBlockDefaultStyle(quitText);
            var quitGameButton = new Button
            {
                Content             = quitText,
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Left,
                Padding             = Thickness.UniformRectangle(10),
            };

            ApplyButtonDefaultStyle(quitGameButton);
            quitGameButton.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            quitGameButton.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            quitGameButton.Click += (sender, args) => Exit();

            modalButton1Text = new TextBlock {
                Text = "Close Modal window 1", Font = Content.Load <SpriteFont>("MicrosoftSansSerif15")
            };
            ApplyTextBlockDefaultStyle(modalButton1Text);
            var modalButton1 = new Button
            {
                Name                = "Button Modal 1",
                Content             = modalButton1Text,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Padding             = Thickness.UniformRectangle(10),
            };

            ApplyButtonDefaultStyle(modalButton1);
            modalButton1.Click += ModalButton1OnClick;
            modal1              = new ModalElement {
                Content = modalButton1, Name = "Modal 1"
            };
            modal1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);
            modal1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            modal1.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            modal1.OutsideClick += Modal1OnOutsideClick;

            modalButton2Text = new TextBlock {
                Text = "Close Modal window 2", Font = Content.Load <SpriteFont>("MicrosoftSansSerif15")
            };
            ApplyTextBlockDefaultStyle(modalButton2Text);
            var modalButton2 = new Button
            {
                Name                = "Button Modal 2",
                Content             = modalButton2Text,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Padding             = Thickness.UniformRectangle(10),
            };

            ApplyButtonDefaultStyle(modalButton2);
            modalButton2.Click += ModalButton2OnClick;
            modal2              = new ModalElement {
                Content = modalButton2, Name = "Modal 2"
            };
            modal2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2);
            modal2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            modal2.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            modal2.OutsideClick += Modal2OnOutsideClick;

            uniformGrid = new UniformGrid {
                Columns = 3, Rows = 3
            };
            uniformGrid.Children.Add(modal1);
            uniformGrid.Children.Add(modal2);
            uniformGrid.Children.Add(lifeBar);
            uniformGrid.Children.Add(quitGameButton);

            UIComponent.Page = new Engine.UIPage {
                RootElement = uniformGrid
            };
        }
Esempio n. 5
0
        protected override void LoadScene()
        {
            // Allow user to resize the window with the mouse.
            Game.Window.AllowUserResizing = true;

            // Create and initialize "Xenko Samples" Text
            var xenkoSampleTextBlock = new ContentDecorator
            {
                BackgroundImage = SpriteFromSheet.Create(SplashScreenImages, "xenko_sample_text_bg"),
                Content         = new TextBlock
                {
                    Font      = WesternFont,
                    TextSize  = 60,
                    Text      = "Xenko UI Particles",
                    TextColor = Color.White,
                },
                Padding             = new Thickness(35, 15, 35, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            xenkoSampleTextBlock.SetPanelZIndex(1);


            //*********************************
            // Confetti button
            var buttonImage = SpriteFromSheet.Create(SplashScreenImages, "button_long");

            var xenkoButtonConfetti = new Button
            {
                NotPressedImage = buttonImage,
                PressedImage    = buttonImage,
                MouseOverImage  = buttonImage,

                Content = new TextBlock
                {
                    Font      = WesternFont,
                    TextColor = Color.White,
                    Text      = "Click here to start the game over",
                    TextSize  = 24
                },

                HorizontalAlignment = HorizontalAlignment.Right,
                Padding             = new Thickness(90, 22, 25, 35),
//                BackgroundColor = Color.DarkOrchid
            };

            xenkoButtonConfetti.SetPanelZIndex(1);
            xenkoButtonConfetti.SetGridRow(1);

            xenkoButtonConfetti.Click += delegate
            {
                fusePercentage = 1f;
                desiredState   = GameState.NewGame;
                var effectOffset = new Vector3(45 - xenkoButtonConfetti.RenderSize.X / 2, -5, 0);
                SpawnParticles(xenkoButtonConfetti.WorldMatrix.TranslationVector + effectOffset, Prefab, 2f);
            };
            //*********************************

            //*********************************
            // Stars button
            var buttonStars = SpriteFromSheet.Create(SplashScreenImages, "button_short");

            var xenkoButtonStars = new Button
            {
                NotPressedImage = buttonStars,
                PressedImage    = buttonStars,
                MouseOverImage  = buttonStars,

                Content = new TextBlock
                {
                    Font      = WesternFont,
                    TextColor = Color.White,
                    Text      = "Congratulations",
                    TextSize  = 24
                },

                HorizontalAlignment = HorizontalAlignment.Right,
                Padding             = new Thickness(90, 22, 25, 35),
//                BackgroundColor = Color.DarkOrchid
            };

            xenkoButtonStars.SetPanelZIndex(1);
            xenkoButtonStars.SetGridRow(4);

            xenkoButtonStars.Click += delegate
            {
                desiredState = GameState.EndGame;
                var effectOffset = new Vector3(45 - xenkoButtonStars.RenderSize.X / 2, -5, 0);
                SpawnParticles(xenkoButtonStars.WorldMatrix.TranslationVector + effectOffset, Prefab, 2f);
            };
            //*********************************

            var bottomBar = CreateBottomBar();

            bottomBar.SetPanelZIndex(1);
            bottomBar.SetGridRow(6);

            var grid = new Grid
            {
                MaximumWidth        = virtualWidth,
                MaximumHeight       = virtualHeight,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 0
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 1
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 2
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 3
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 4
            grid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 100)); // 5
            grid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 50));  // 5
            grid.ColumnDefinitions.Add(new StripDefinition());
            grid.LayerDefinitions.Add(new StripDefinition());

            grid.Children.Add(xenkoSampleTextBlock);
            grid.Children.Add(xenkoButtonConfetti);
            grid.Children.Add(xenkoButtonStars);
            grid.Children.Add(bottomBar);

            // Add the background
            var background = new ImageElement {
                Source = SpriteFromSheet.Create(SplashScreenImages, "background_uiimage"), StretchType = StretchType.Fill
            };

            background.SetPanelZIndex(-1);

            Entity.Get <UIComponent>().Page = new UIPage {
                RootElement = new UniformGrid {
                    Children = { background, grid }
                }
            };
        }