Exemplo n.º 1
0
        public override void HandleInput()
        {
            if (InputManager.IsMouseButtonPressed(MouseButton.Left))
            {
                if (InputManager.IsMouseButtonTriggered(MouseButton.Left))
                {
                    lastMouseDown = InputManager.MousePosition;
                }

                if (world.CanDrag)
                {
                    Vector2 delta = InputManager.LastMousePosition.ToVector() -
                                    InputManager.MousePosition.ToVector();

                    world.Camera.Move(-delta);
                }
            }
            else if (InputManager.IsMouseButtonClicked(MouseButton.Left))
            {
                var current = InputManager.MousePosition.ToVector();

                float distance = Vector2.Distance(current,
                                                  lastMouseDown.ToVector());

                if (distance <= clickDistanceThreshold)
                {
                    world.OnClick(current - world.Camera.RawPosition);
                }
            }

            if (InputManager.IsKeyTriggered(Keys.B))
            {
                ScreenManager.AddScreen(new BuildingListScreen(world));
            }

            var mouse = InputManager.MousePosition.ToVector() - world.Camera.RawPosition;

            var selection = world.GetNodePosition(mouse);

            if (InputManager.IsMouseButtonTriggered(MouseButton.Right))
            {
                if (new Rectangle(0, 0, MarsWorld.Size.X, MarsWorld.Size.Y).Contains(selection))
                {
                    var type = InputManager.IsKeyPressed(Keys.LeftShift) ?
                               Enemy.Tank : Enemy.Basic;

                    for (int i = 0; i < 25; i++)
                    {
                        var offset = new Vector2(random.Next(250), random.Next(250));
                        world.AddEnemy(type, mouse - new Vector2(10) + offset);
                    }
                }
            }

            if (InputManager.IsKeyTriggered(Keys.OemTilde))
            {
                MarsWorld.Debug = !MarsWorld.Debug;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the the position of the nearest node (in node units)
        /// </summary>
        /// <returns></returns>
        public virtual Point GetNearestNode()
        {
            var node = world.GetNodePosition(position);

            // clamp values inside the world
            node.X = (int)MathHelper.Clamp(node.X, 0, MarsWorld.Size.X - 1);
            node.Y = (int)MathHelper.Clamp(node.Y, 0, MarsWorld.Size.Y - 1);

            return(node);
        }