Beispiel #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            ContentLoader.LoadTexture("Ryu Intro Sheet", Texture2D.FromStream(GraphicsDevice, File.Open("Ryu Intro Sheet.png", FileMode.Open)));

            // Test, remove later.
            GameObjectAnimated ryuIntro = new GameObjectAnimated();

            ryuIntro.CurrentAnimation = Animation.ReadAnimationFile("intro_ryu_idle.pcaf");
            ryuIntro.CurrentAnimation.Play();

            objManager.GetObjects().Add(ryuIntro);

            GameCamera MainCamera = new GameCamera(new Rectangle(0, 0, 256, 224))
            {
                IsEnabled = true
            };

            objManager.GetObjects().Add(MainCamera);

            GraphicsDevice.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;

            base.Initialize();
        }
        public void WPFMouseDown(MouseEventArgs e)
        {
            ComboBox comboBox = MainWindow.mainWindow.ObjectComboBox;

            ComboBoxObjectInfoItem item = comboBox.SelectedItem as ComboBoxObjectInfoItem;
            Vector2 worldPos            = Vector2.Transform(new Vector2((float)e.GetPosition(MainWindow.mainWindow.Viewport).X, (float)e.GetPosition(MainWindow.mainWindow.Viewport).Y), Matrix.Invert(objectManager.CurrentCamera.Transform));

            // Placing objects
            if (e.LeftButton == MouseButtonState.Pressed && SelectionType == SelectionType.OBJECT && item != null && !guiManager.UIHovered)
            {
                MapGameObject mapObject = new MapGameObject(item.GameObject.Copy());

                if (item.GameObject == null)
                {
                    Console.WriteLine("GameObjectInfo is null!");
                }

                mapObject.SetPosition(objectManager.PreviewObject.GetPosition());

                mapObject.CurrentAnimation = objectManager.PreviewObject.CurrentAnimation;
                mapObject.Properties       = item.GameObject.Properties;
                mapObject.Info             = item.GameObject.Copy();
                mapObject.HelperRectangles = item.GameObject.HelperRectangles;

                objectManager.GetObjects().Add(mapObject);

                UpdateObjectTree();
            }

            // Selecting objects
            if (e.LeftButton == MouseButtonState.Pressed && SelectionType == SelectionType.SELECTION && !guiManager.UIHovered)
            {
                // Ensure the mouse is not already over a selected object.
                bool isSelectionHovered = false;

                foreach (GameObject obj in objectManager.SelectionObject.Selection)
                {
                    if (obj.GetBoundingBox().Intersects(new Rectangle((int)worldPos.X, (int)worldPos.Y, 1, 1)))
                    {
                        isSelectionHovered = true;
                    }
                }

                if (!isSelectionHovered || (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)))
                {
                    if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
                    {
                        objectManager.SelectionObject.Selection = new List <GameObject>();
                    }


                    foreach (GameObject obj in objectManager.GetObjects())
                    {
                        if (new Rectangle((int)worldPos.X, (int)worldPos.Y, 1, 1).Intersects(obj.GetBoundingBox()) && !objectManager.SelectionObject.Selection.Contains(obj) && obj != objectManager.PreviewObject && obj.Visible)
                        {
                            if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
                            {
                                if (objectManager.SelectionObject.Selection.Count == 0)
                                {
                                    objectManager.SelectionObject.Selection.Add(obj);
                                }

                                else
                                {
                                    objectManager.SelectionObject.Selection[0] = obj;
                                }
                            }
                            else
                            {
                                objectManager.SelectionObject.Selection.Add(obj);
                            }

                            GameObjectAnimated animObj = objectManager.SelectionObject.Selection[0] as GameObjectAnimated;

                            if (animObj != null && animObj.CurrentAnimation != null)
                            {
                                animObj.CurrentAnimation.SetCurrentMS(0);
                                animObj.CurrentAnimation.Play();
                            }
                            if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                UpdateLayerBox();
            }

            if (e.LeftButton == MouseButtonState.Pressed && objectManager.SelectionObject.Selection.Count > 0)
            {
                OldPositions = new List <Vector2>();

                foreach (GameObject obj in objectManager.SelectionObject.Selection)
                {
                    OldPositions.Add(obj.GetPosition());
                }

                isMoving = true;
            }

            /// OBJECT MOVING

            // Get relative position to origin of selection
            if (objectManager.SelectionObject.Selection != null)
            {
                foreach (GameObject gameObject in objectManager.SelectionObject.Selection)
                {
                    if (gameObject is MapGameObject)
                    {
                        grabOffset[gameObject] = worldPos - gameObject.GetPosition();
                    }
                }
            }
        }