Exemple #1
0
        private void UpdateCameraInput()
        {
            if (MouseCondition.Scrolled())
            {
                int scrollDelta = MouseCondition.ScrollDelta;
                _targetExp = MathHelper.Clamp(_targetExp - scrollDelta * _expDistance, _maxExp, _minExp);
            }

            if (RotateLeft.Pressed())
            {
                _targetRotation += MathHelper.Pi / 8f;
            }
            if (RotateRight.Pressed())
            {
                _targetRotation -= MathHelper.Pi / 8f;
            }

            _mouseWorld = Vector2.Transform(InputHelper.NewMouse.Position.ToVector2(), Matrix.Invert(GetView()));

            if (CameraDrag.Pressed())
            {
                _dragAnchor = _mouseWorld;
                _isDragged  = true;
            }
            if (_isDragged && CameraDrag.HeldOnly())
            {
                _xy        += _dragAnchor - _mouseWorld;
                _mouseWorld = _dragAnchor;
            }
            if (_isDragged && CameraDrag.Released())
            {
                _isDragged = false;
            }
        }
Exemple #2
0
        private void UpdateCameraInput(Camera c, int index)
        {
            int x = InputHelper.NewMouse.X;
            int y = InputHelper.NewMouse.Y;

            if (!_isDragged && CameraContains(c, x, y) || _isDragged && _currentCamera == index)
            {
                _currentCamera = index;
                if (MouseCondition.Scrolled())
                {
                    int scrollDelta = MouseCondition.ScrollDelta;
                    SetZoom(c, MathF.Min(MathF.Max(GetZoom(c) - scrollDelta * 0.001f, 0.2f), 10f));
                }

                if (RotateLeft.Pressed())
                {
                    c.Rotation += MathHelper.PiOver4;
                }
                if (RotateRight.Pressed())
                {
                    c.Rotation -= MathHelper.PiOver4;
                }

                if (Forward.Held())
                {
                    c.Z -= 0.1f;
                }
                if (Backward.Held())
                {
                    c.Z += 0.1f;
                }

                if (IncreaseFocal.Held())
                {
                    var temp = c.Z / c.FocalLength;

                    c.FocalLength += 0.01f;

                    c.Z = c.FocalLength * temp;
                }
                if (DecreaseFocal.Held())
                {
                    var temp = c.Z / c.FocalLength;

                    c.FocalLength -= 0.01f;

                    c.Z = c.FocalLength * temp;
                }

                if (ResetCamera.Pressed())
                {
                    c.Scale       = new Vector2(1f, 1f);
                    c.XY          = new Vector2(0f, 0f);
                    c.Z           = 2f;
                    c.Rotation    = 0f;
                    c.FocalLength = 1f;
                }

                _mouseWorld = c.ScreenToWorld(x, y);

                if (CameraDrag.Pressed())
                {
                    _dragAnchor = _mouseWorld;
                    _isDragged  = true;
                }
                if (_isDragged && CameraDrag.HeldOnly())
                {
                    c.XY       += _dragAnchor - _mouseWorld;
                    _mouseWorld = _dragAnchor;
                }
                if (_isDragged && CameraDrag.Released())
                {
                    _isDragged = false;
                }
            }
        }
Exemple #3
0
        private void SingleHover()
        {
            _hoveredEntity = null;
            if (_selection.Rect == null)
            {
                bool   addSelected = false;
                Entity?first       = null;
                // If there's a single element selected, it can have resize handles. Expand it's bounds to see if we're hovering that.
                if (_selectedEntities.Count() == 1)
                {
                    first = _selectedEntities.First();
                    var inset = first.Inset;
                    addSelected = !inset.Contains(Camera.MouseWorld) && Utility.ExpandRect(new RectangleF(inset.X, inset.Y, inset.Width, inset.Height), _edit.HandleDistanceWorld).Contains(Camera.MouseWorld);
                }

                List <Entity> hoversUnderMouse;
                List <Entity> selectedAndHovered;
                if (addSelected)
                {
                    hoversUnderMouse = new QueryFilter(_aabbTree.Query(Camera.MouseWorld), _activeLayers).Append(first !).OrderBy(e => e).ToList();
                    // This can only happen when there's only 1 selection so we can do a special case here.
                    selectedAndHovered = new List <Entity> {
                        first !
                    };
                }
                else
                {
                    hoversUnderMouse   = new QueryFilter(_aabbTree.Query(Camera.MouseWorld), _activeLayers).OrderBy(e => e).ToList();
                    selectedAndHovered = _selectedEntities.Query(Camera.MouseWorld).OrderBy(e => e).ToList();
                }

                var hoverCount = hoversUnderMouse.Count();
                // Skip if there are no hovers.
                if (hoverCount > 0)
                {
                    int cycleReset = 0;
                    // If there's a selection, always give it priority over everything else.
                    if (selectedAndHovered.Count() > 0)
                    {
                        cycleReset = hoverCount - 1 - hoversUnderMouse.IndexOf(selectedAndHovered.Last());
                    }

                    // If we aren't cycling, then select the selection at the top or element at the top.
                    if (_cycleMouse == null)
                    {
                        _cycleIndex = cycleReset;
                    }
                    // If we're current cycling over the hovers, we reset when the mouse moves enough.
                    else if (Vector2.DistanceSquared(_cycleMouse.Value, Camera.MouseWorld) > Utility.ScreenArea(10))
                    {
                        _cycleIndex = cycleReset;
                        _cycleMouse = null;
                    }
                    // If we want to cycle over the hovers, save current mouse position so that we can reset later.
                    if (MouseCondition.Scrolled() && Triggers.SelectionCycle.Held())
                    {
                        _cycleIndex += MathF.Sign(MouseCondition.ScrollDelta);
                        _cycleMouse  = Camera.MouseWorld;
                    }

                    // Now we can do the selection.
                    _hoveredEntity = hoversUnderMouse.ElementAt(Utility.Mod(hoverCount - 1 - _cycleIndex, hoverCount));
                }
                else
                {
                    _cycleIndex = 0;
                    _cycleMouse = null;
                }
            }
        }
Exemple #4
0
        public override void Update()
        {
            if (KeyboardCondition.Pressed(Keys.R))
            {
                Playing = !Playing;
            }

            if (!Playing)
            {
                if (KeyboardCondition.Pressed(Keys.E))
                {
                    if ((byte)Layer < Enum.GetNames(typeof(Layers)).Length - 1)
                    {
                        Layer++;
                    }
                    Label_CurrentLayer.Text.Message = Enum.GetNames(typeof(Layers))[(byte)Layer];
                }
                else if (KeyboardCondition.Pressed(Keys.Q))
                {
                    if ((byte)Layer > 0)
                    {
                        Layer--;
                    }
                    Label_CurrentLayer.Text.Message = Enum.GetNames(typeof(Layers))[(byte)Layer];
                }

                if (MouseCondition.Pressed(MouseButton.RightButton))
                {
                    switch (Layer)
                    {
                    case Layers.StaticObjects:
                        Functions.PlaceStaticObject(Data.MousePosition.X, Data.MousePosition.Y, ObjectType.Wall);
                        break;

                    case Layers.Zombies:
                        Functions.PlaceZombie(Data.MousePosition.X, Data.MousePosition.Y, ZombieType.Regular);
                        break;
                    }
                }

                if (MouseCondition.Pressed(MouseButton.MiddleButton))
                {
                    var thing = Data.World.TestPoint(Functions.ToSim(Data.MousePosition));

                    if (thing != null && thing.Body != null)
                    {
                        if (thing.Body.Tag is StaticObjectTag)
                        {
                            Pool.GameObjects_Static[Functions.ConvertBodyToStaticObject(thing.Body)].Active = false;
                        }
                        else if (thing.Body.Tag is ZombieTag)
                        {
                            Zombies.Active[Functions.ConvertBodyToStaticObject(thing.Body)] = false;
                        }
                    }
                }

                if (MouseCondition.Pressed(MouseButton.LeftButton))
                {
                    var thing = Data.World.TestPoint(Functions.ToSim(Data.MousePosition));

                    if (thing != null && thing.Body != null)
                    {
                        Grabbed       = thing.Body;
                        GrabbedOffset = thing.Body.Position - Functions.ToSim(Data.MousePosition);
                    }
                }

                if (MouseCondition.Released(MouseButton.LeftButton))
                {
                    Grabbed       = null;
                    GrabbedOffset = Vector2.Zero;
                }

                if (Grabbed != null)
                {
                    Grabbed.Position = Functions.ToSim(Data.MousePosition) + GrabbedOffset;
                }

                Camera.Velocity = Vector2.Lerp(Camera.Velocity, Vector2.Zero, .25f);

                if (KeyboardCondition.Held(Keys.A))
                {
                    Camera.Velocity -= new Vector2(CameraSpeed, 0f);
                }
                if (KeyboardCondition.Held(Keys.D))
                {
                    Camera.Velocity += new Vector2(CameraSpeed, 0f);
                }
                if (KeyboardCondition.Held(Keys.W))
                {
                    Camera.Velocity -= new Vector2(0f, CameraSpeed);
                }
                if (KeyboardCondition.Held(Keys.S))
                {
                    Camera.Velocity += new Vector2(0f, CameraSpeed);
                }

                Camera.Position = Vector2.Clamp(Camera.Position, new Vector2(-128 * 12) + Data.ScreenCentre,
                                                new Vector2(128 * 12) - Data.ScreenCentre);

                if (KeyboardCondition.Pressed(Keys.Enter))
                {
                    Functions.SaveLevel(LevelType.Level1);
                }

                Label_CurrentLayer.Update();
            }
            else
            {
                GameScreen.Instance.Update();
            }
        }