Exemplo n.º 1
0
        public Scene(string name, AvocadoGame game)
        {
            Game            = game;
            Name            = name;
            graphicsDevice  = game.GraphicsDevice;
            Content         = new ContentManager(game.Services);
            BackgroundColor = Color.Black;

            var             settings = Game.GameSettings;
            ViewportAdapter adapter  = null;

            switch (settings.ViewportType)
            {
            case ViewportType.Default:
                adapter = new DefaultViewportAdapter(Game.GraphicsDevice);
                break;

            case ViewportType.Scaling:
                adapter = new ScalingViewportAdapter(game.GraphicsDevice, settings.VirtualResolution.X, settings.VirtualResolution.Y);
                break;

            case ViewportType.Window:
                adapter = new WindowViewportAdapter(game.Window, graphicsDevice);
                break;
            }
            Camera = new Camera(adapter);

            EntityManager    = new EntityManager(this);
            CollisionManager = new CollisionManager(this);
            BehaviorManager  = new BehaviorManager(this);
            RenderManager    = new RenderManager(this, graphicsDevice);
        }
Exemplo n.º 2
0
        void LoadGui()
        {
            var viewportAdapter = new DefaultViewportAdapter(_sceneHandler._graphicsDevice);
            var guiRenderer     = new GuiSpriteBatchRenderer(_sceneHandler._graphicsDevice, () => Matrix.Identity);
            var font            = _sceneHandler._content.Load <BitmapFont>("Sensation");
            var JoinButton      = new Button {
                Content = "Start"
            };

            JoinButton.PressedStateChanged += OnJoinButtonClick;
            BitmapFont.UseKernings          = false;
            Skin.CreateDefault(font);
            chatText = new TextBox {
                Text = "Send message", Position = new Point(0, 150)
            };
            var controlTest = new StackPanel
            {
                Items =
                {
                    chatText,
                    JoinButton
                },
                VerticalAlignment = VerticalAlignment.Bottom
            };

            var demoScreen = new Screen
            {
                Content = controlTest,
            };

            _guiSystem = new GuiSystem(viewportAdapter, guiRenderer)
            {
                ActiveScreen = demoScreen
            };
        }
Exemplo n.º 3
0
        public void Camera2D_LookAt_Test()
        {
            var graphicsDevice  = TestHelper.CreateGraphicsDevice();
            var viewportAdapter = new DefaultViewportAdapter(graphicsDevice);
            var camera          = new Camera2D(viewportAdapter);

            camera.LookAt(new Vector2(100, 200));

            Assert.AreEqual(new Vector2(-300, -40), camera.Position);
        }
Exemplo n.º 4
0
        public GuiSystem CreateUI(GraphicsDevice graphicsDevice)
        {
            var viewportAdapter = new DefaultViewportAdapter(graphicsDevice);
            var guiRenderer     = new GuiSpriteBatchRenderer(graphicsDevice, () => Matrix.Identity);

            return(new GuiSystem(viewportAdapter, guiRenderer)
            {
                ActiveScreen = CreateScreen()
            });
        }
        public override void LoadContent()
        {
            var viewportAdapter = new DefaultViewportAdapter(_graphicsDevice);

            _camera = new OrthographicCamera(viewportAdapter);

            _playerSprite = new PlayerSprite(LoadTexture(PlayerFighter),
                                             LoadAnimation(PlayerAnimationTurnLeft),
                                             LoadAnimation(PlayerAnimationTurnRight));

            _playerSprite.Position = new Vector2(0, 0);
        }
Exemplo n.º 6
0
        public override void Initialize()
        {
            _viewportAdapter = new DefaultViewportAdapter(GraphicsDevice);
            _camera          = new Camera2D(_viewportAdapter);
            _mapRenderer     = new TiledMapRenderer(GraphicsDevice);

            _fpsCounter = new FramesPerSecondCounter();

            base.Initialize();

            _players = new List <Client.Model.Player>();
            SignalR();
        }
Exemplo n.º 7
0
        public void DefaultViewportAdapter_Test()
        {
            var graphicsDevice  = TestHelper.CreateGraphicsDevice();
            var viewportAdapter = new DefaultViewportAdapter(graphicsDevice);

            graphicsDevice.Viewport = new Viewport(0, 0, 1024, 768);

            Assert.AreEqual(1024, viewportAdapter.ViewportWidth);
            Assert.AreEqual(768, viewportAdapter.ViewportHeight);
            Assert.AreEqual(viewportAdapter.ViewportWidth, viewportAdapter.VirtualWidth);
            Assert.AreEqual(viewportAdapter.ViewportHeight, viewportAdapter.VirtualHeight);
            Assert.AreEqual(Matrix.Identity, viewportAdapter.GetScaleMatrix());
        }
Exemplo n.º 8
0
        public void Camera2D_GetBoundingRectangle_Test()
        {
            var graphicsDevice = TestHelper.CreateGraphicsDevice();
            var viewport       = new DefaultViewportAdapter(graphicsDevice);
            var camera         = new Camera2D(viewport);

            camera.Move(new Vector2(2, 0));
            camera.Move(new Vector2(0, 3));

            var boundingRectangle = camera.GetBoundingRectangle();

            Assert.AreEqual(2, boundingRectangle.Left, 0.01);
            Assert.AreEqual(3, boundingRectangle.Top, 0.01);
            Assert.AreEqual(802, boundingRectangle.Right, 0.01);
            Assert.AreEqual(483, boundingRectangle.Bottom, 0.01);
        }
        protected override void Initialize()
        {
            base.Initialize();

            _backgroundRectangle = new Texture2D(GraphicsDevice, 1, 1);
            _backgroundRectangle.SetData(new[] { Color.CadetBlue });
            _eventRectangle = new Texture2D(GraphicsDevice, 1, 1);
            _eventRectangle.SetData(new[] { Color.IndianRed });

            var viewportAdapter = new DefaultViewportAdapter(Editor.graphics);

            _camera = new OrthographicCamera(viewportAdapter);
            ResetCameraPosition();

            CurrentLayer     = GROUND;
            CurrentLevel     = 1;
            _groundTexture   = Editor.Content.Load <Texture2D>("Atlas/ground");
            _buildingTexture = Editor.Content.Load <Texture2D>("Atlas/buildings");

            // load atlas
            Atlas = new Dictionary <string, TextureAtlas>();
            var groundTiles   = GetGroundTiles();
            var buildingTiles = GetBuildingTiles();
            var objectTiles   = GetGameObjects();

            var groundAtlas   = new TextureAtlas(GROUND, _groundTexture, groundTiles);
            var buildingAtlas = new TextureAtlas(BUILDINGS, _buildingTexture, buildingTiles);

            Atlas.Add(GROUND, groundAtlas);
            Atlas.Add(BUILDINGS, buildingAtlas);

            GameObjects = GetGameObjects();
            LevelEvents = new List <GameEditorEvent>();

            // start with empty levels
            for (var i = 0; i < 5; i++)
            {
                var newLevel = new Level();
                _levels.Add(newLevel);
            }

            _draggedTile = null;

            OnInitialized(this, EventArgs.Empty);
        }
        protected override void Initialize()
        {
            base.Initialize();

            // the default viewport adapater is the simplest, it doesn't do any scaling at all
            // but is used by a Camera2D if no other adapter is specified.
            // this is often useful if you have a game with a large map and you want the player to see
            // more of the map on a bigger screen.
            _defaultViewportAdapter = new DefaultViewportAdapter(GraphicsDevice);

            // the scaling viewport adapter stretches the output to fit in the viewport, ignoring the aspect ratio
            // this works well if the aspect ratio doesn't change a lot between devices
            // or you don't like the black bars of the boxing adapter
            _scalingViewportAdapter = new ScalingViewportAdapter(GraphicsDevice, 800, 480);

            // the boxing viewport adapter uses letterboxing or pillarboxing to maintain aspect ratio
            // it's a little more complicated and needs to listen to the window client size changing event
            _boxingViewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);//, 88, 70);

            // typically you'll only ever want to use one viewport adapter for a game, but in this sample we'll be
            // switching between them.
            _currentViewportAdapter = _boxingViewportAdapter;
        }
Exemplo n.º 11
0
        void LoadGui()
        {
            var viewportAdapter = new DefaultViewportAdapter(_sceneHandler._graphicsDevice);
            var guiRenderer     = new GuiSpriteBatchRenderer(_sceneHandler._graphicsDevice, () => Matrix.Identity);
            var font            = _sceneHandler._content.Load <BitmapFont>("Sensation");

            BitmapFont.UseKernings = false;
            Skin.CreateDefault(font);
            var JoinButton = new Button {
                Content = "Join to server"
            };

            IPTextBox = new TextBox {
                Text = "127.0.0.1", HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom
            };
            NameTextBox = new TextBox {
                Text = "Name", HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom
            };
            JoinButton.PressedStateChanged += ChatText_PressedStateChanged;
            var controlTest = new StackPanel
            {
                Items =
                {
                    new StackPanel
                    {
                        Items =
                        {
                            new Label("Name:")
                            {
                                HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom,
                            },
                            NameTextBox,
                        },
                        Orientation = Orientation.Horizontal
                    },
                    new StackPanel
                    {
                        Items =
                        {
                            new Label("Ip:")
                            {
                                HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom,
                            },
                            IPTextBox,
                        },
                        Orientation = Orientation.Horizontal
                    },
                    JoinButton
                }

                ,
                VerticalAlignment   = VerticalAlignment.Centre,
                HorizontalAlignment = HorizontalAlignment.Centre,
                Spacing             = 5
            };


            var demoScreen = new Screen
            {
                Content = controlTest
            };

            _guiSystem = new GuiSystem(viewportAdapter, guiRenderer)
            {
                ActiveScreen = demoScreen
            };
        }
Exemplo n.º 12
0
        protected override void LoadContent()
        {
            var viewportAdapter = new DefaultViewportAdapter(GraphicsDevice);
            var guiRenderer     = new GuiSpriteBatchRenderer(GraphicsDevice, () => Matrix.Identity);
            var font            = Content.Load <BitmapFont>("Sensation");

            BitmapFont.UseKernings = false;
            Skin.CreateDefault(font);

            //var parser = new MarkupParser();

            //var mainScreen = new Screen
            //{
            //    Content = parser.Parse("Features/MainWindow.mgeml", new object())
            //};

            //var textBox = mainScreen.FindControl<TextBox>("TextBox");
            //var statusLabel = mainScreen.FindControl<Label>("StatusLabel");

            //textBox.CaretIndexChanged += (sender, args) =>
            //    statusLabel.Content = $"Ln {textBox.LineIndex + 1}, Ch {textBox.CaretIndex + 1}";



            var stackTest = new DemoViewModel("Stack Panels",
                                              new StackPanel
            {
                Items =
                {
                    new Button {
                        Content = "Press Me", HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top
                    },
                    new Button {
                        Content = "Press Me", HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom
                    },
                    new Button {
                        Content = "Press Me", HorizontalAlignment = HorizontalAlignment.Centre, VerticalAlignment = VerticalAlignment.Centre
                    },
                    new Button {
                        Content = "Press Me", HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch
                    },
                }
            });

            var dockTest = new DemoViewModel("Dock Panels",
                                             new DockPanel
            {
                Items =
                {
                    new Button {
                        Content = "Dock.Top", AttachedProperties ={                                     { DockPanel.DockProperty, Dock.Top    } }
                    },
                    new Button {
                        Content = "Dock.Bottom", AttachedProperties ={                                     { DockPanel.DockProperty, Dock.Bottom } }
                    },
                    new Button {
                        Content = "Dock.Left", AttachedProperties ={                                     { DockPanel.DockProperty, Dock.Left   } }
                    },
                    new Button {
                        Content = "Dock.Right", AttachedProperties ={                                     { DockPanel.DockProperty, Dock.Right  } }
                    },
                    new Button {
                        Content = "Fill"
                    }
                }
            });

            var controlTest = new DemoViewModel("Basic Controls",
                                                new StackPanel
            {
                Margin      = 5,
                Orientation = Orientation.Vertical,
                Items       =
                {
                    new Label("Buttons")
                    {
                        Margin = 5
                    },
                    new StackPanel
                    {
                        Orientation = Orientation.Horizontal,
                        Spacing     = 5,
                        Items       =
                        {
                            new Button       {
                                Content = "Enabled"
                            },
                            new Button       {
                                Content = "Disabled", IsEnabled = false
                            },
                            new ToggleButton {
                                Content = "ToggleButton"
                            }
                        }
                    },

                    new Label("TextBox")
                    {
                        Margin = 5
                    },
                    new TextBox              {
                        Text = "TextBox"
                    },

                    new Label("CheckBox")
                    {
                        Margin = 5
                    },
                    new CheckBox             {
                        Content = "Check me please!"
                    },

                    new Label("ListBox")
                    {
                        Margin = 5
                    },
                    new ListBox              {
                        Items =              { "ListBoxItem1",  "ListBoxItem2",  "ListBoxItem3"  }, SelectedIndex =                          0
                    },

                    new Label("ProgressBar")
                    {
                        Margin = 5
                    },
                    new ProgressBar          {
                        Progress = 0.5f, Width = 100
                    },

                    new Label("ComboBox")
                    {
                        Margin = 5
                    },
                    new ComboBox             {
                        Items =              { "ComboBoxItemA", "ComboBoxItemB", "ComboBoxItemC" }, SelectedIndex =0, HorizontalAlignment = HorizontalAlignment.Left
                    }
                }
            });

            var demoScreen = new Screen
            {
                Content = new DockPanel
                {
                    LastChildFill = true,
                    Items         =
                    {
                        new ListBox
                        {
                            Name = "DemoList",
                            AttachedProperties  = { { DockPanel.DockProperty, Dock.Left } },
                            ItemPadding         = new Thickness(5),
                            VerticalAlignment   = VerticalAlignment.Stretch,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            SelectedIndex       = 0,
                            Items ={ controlTest, stackTest, dockTest }
                        },
                        new ContentControl
                        {
                            Name            = "Content",
                            BackgroundColor = new Color(30, 30, 30)
                        }
                    }
                }
            };

            _guiSystem = new GuiSystem(viewportAdapter, guiRenderer)
            {
                ActiveScreen = demoScreen
            };

            var demoList    = demoScreen.FindControl <ListBox>("DemoList");
            var demoContent = demoScreen.FindControl <ContentControl>("Content");

            demoList.SelectedIndexChanged += (sender, args) => demoContent.Content = (demoList.SelectedItem as DemoViewModel)?.Content;
            demoContent.Content            = (demoList.SelectedItem as DemoViewModel)?.Content;
        }