Beispiel #1
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            GUI.LoadGUI(Content.Load<SpriteFont>("gui\\fonts\\font"));
            DebugTextures.LoadTextures(GraphicsDevice);

            hud = new GUI();
            if (File.Exists("maps\\map1.bin"))
            {
                map = Map.Load("maps\\map1.bin");
                foreach (var c in map.colliders)
                {
                    c.debugSprite = DebugTextures.GenerateHollowRectangele(c.width, c.height, 2, Color.DarkRed);
                    c.debugOrigin = new Vector2(c.width / 2f, c.height / 2f);
                }
            }
            else
            {
                map = new Map();
            }

            screenCenter = new Vector2(GraphicsDevice.Viewport.Width / 2f, GraphicsDevice.Viewport.Height / 2f);
            screenBottomLeft = new Vector2(0, GraphicsDevice.Viewport.Height);
            screenBottomRight = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
            screenTopLeft = new Vector2(0, 0);
            screenTopRight = new Vector2(GraphicsDevice.Viewport.Width, 0);

            GUI.buttons.Add(new Button(screenTopLeft + new Vector2(150, 150), "PLACE COLLIDER", true, DebugTextures.GenerateRectangle(150, 150, Color.Sienna), GUI.defaultFont, PlaceCollider));
            GUI.buttons.Add(Button.Debug("PLACE TILE", 150, 150, Color.DarkSeaGreen, PlaceTiles));

            previousState = Mouse.GetState();
        }
Beispiel #2
0
        public void PlaceCollider()
        {
            currentAction = Action.PlacingCollider;

            if (Input.LeftMouseButtonDown(false) && !colClicked) // clicked
            {
                colPosition1 = Input.mousePosition / resolutionScale;
                colClicked = true;
            }
            else if (colClicked)
            {
                colPosition2 = Input.mousePosition / resolutionScale;
                if ((int)Math.Abs(colPosition1.X - colPosition2.X) > 0 && (int)Math.Abs(colPosition1.Y - colPosition2.Y) > 0)
                {
                    int width = (int)Math.Abs(colPosition1.X - colPosition2.X);
                    int height = (int)Math.Abs(colPosition1.Y - colPosition2.Y);

                    col = new Collider((colPosition1 + colPosition2) / 2, width, height);
                    col.debugSprite = DebugTextures.GenerateHollowRectangele(width, height, 2, Color.DarkRed);
                    col.debugOrigin = new Vector2(width / 2, height / 2);

                    if (Input.LeftMouseButtonDown(false)) // clicked
                    {
                        currentAction = Action.None;
                        colClicked = false;
                        map.colliders.Add(col);
                    }
                }
            }
        }