예제 #1
0
        public void HandleInput(MouseState mState, KeyboardState kState, bool click, Func<Keys, bool> keyWentDown, World world) {
            var mouseTransformed = Vector2.Transform(mState.Position.ToVector2(), Matrix.Invert(Transform)).ToPoint();

            if(!MouseDownPosTransformed.HasValue && mState.LeftButton == ButtonState.Pressed) {
                MouseDownPosTransformed = mouseTransformed;
            }
            if(MouseDownPosTransformed.HasValue && mState.LeftButton == ButtonState.Released) {
                MouseDownPosTransformed = null;
            }

            HandleSelection(click, mouseTransformed, kState, keyWentDown, world);
            HandleZoom(mState, kState);
            HandleClickDrag(mouseTransformed);
            HandleArrowScrolling(kState);
            HandleReset(kState);
        }
예제 #2
0
        private void HandleSelection(bool click, Point mouseTransformed, KeyboardState kState, Func<Keys, bool> keyWentDown, World world) {
            if(Following != null) {
                if(!Following.Active) {
                    Following = null;
                } else {
                    Center = Following.CenterPosition.ToPoint();
                }
            }

            if(kState.IsKeyDown(Keys.LeftControl) || kState.IsKeyDown(Keys.RightControl)) {
                if(keyWentDown(Keys.Right)) {
                    var actives = world.CreatureObjs.Where(c => c.Active).ToArray();
                    var ndx = ThreadSafeRandom.Instance.Next(0, actives.Length);
                    Following = actives[ndx];
                }
            }

            if(click) {
                var clicked = world.ActiveGameObjs
                    .OfType<GameObjects.CreatureComponents.Creature>()
                    .FirstOrDefault(g => Vector2.Distance(g.CenterPosition, mouseTransformed.ToVector2()) < g.Radius);

                if(clicked != null) {
                    if(clicked != Following) {
                        if(Following != null) {
                            Following.ShowInfo = false;
                        }
                        Following = clicked;
                        Following.ShowInfo = true;
                    } else {
                        Following.ShowInfo = false;
                        Following = null;
                    }
                }
            }
        }