コード例 #1
0
        public Editor(string[] args)
        {
            // Create the main window.
            window = new RenderWindow(new VideoMode(Configuration.Width, Configuration.Height), "Level Editor");
            window.SetFramerateLimit(60);

            // Listen for window events.
            window.Closed             += OnClose;
            window.MouseWheelScrolled += OnScroll;
            window.MouseButtonPressed += OnPress;
            window.KeyPressed         += KeyPressed;

            // Load all the components that we have created.
            components         = ComponentLoader.GetComponents();
            selectedComponents = new List <Component>();

            background = new Vertex[4]
            {
                new Vertex(new Vector2f(0, 0), new Color(0x3E, 0x5A, 0x8E)),
                new Vertex(new Vector2f(Configuration.Width, 0), new Color(0x3E, 0x5A, 0x8E)),
                new Vertex(new Vector2f(Configuration.Width, Configuration.Height), new Color(0x82, 0xAB, 0xE3)),
                new Vertex(new Vector2f(0, Configuration.Height), new Color(0x82, 0xAB, 0xE3))
            };

            clock = new Clock();
            grid  = new AllignmentGrid();
            map   = new Map();

            if (args.Any())
            {
                map = MapHelper.LoadMap($"{Configuration.MapLocations}\\{args.First()}");
                map.Load();
            }
        }
コード例 #2
0
        private void Update(float deltaT)
        {
            if (IsPlacingGoal)
            {
                map.GoalPosition  = MapHelper.GetBottomLeftOfGrid(window.Position);
                map.Goal.Position = map.GoalPosition;
            }
            else if (IsPlacingStart)
            {
                map.StartPosition  = MapHelper.GetBottomLeftOfGrid(window.Position);
                map.Start.Position = map.StartPosition;
            }
            else if (IsDeleting)
            {
                selectedComponents.Clear();
                foreach (var component in map.Components)
                {
                    var mousePos = MapHelper.GetBottomLeftOfGrid(window.Position);
                    if (component.Visual.GetGlobalBounds().Contains(mousePos.X, mousePos.Y))
                    {
                        component.Visual.Scale = new Vector2f(1.2f, 1.2f);
                        selectedComponents.Add(component);
                    }
                    else
                    {
                        component.Visual.Scale = new Vector2f(1f, 1f);
                    }
                }
            }
            else
            {
                currentComponent.Position        = MapHelper.GetBottomLeftOfGrid(window.Position);
                currentComponent.Visual.Position = currentComponent.Position;
            }

            if (frame % 60 == 0)
            {
                components = ComponentLoader.GetComponents();
            }
        }