Ejemplo n.º 1
0
        public Vector2 Update()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                mousePos.X -= MOUSE_SPEED / Camera.GetZoom();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                mousePos.X += MOUSE_SPEED / Camera.GetZoom();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                mousePos.Y -= MOUSE_SPEED / Camera.GetZoom();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                mousePos.Y += MOUSE_SPEED / Camera.GetZoom();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                if (!(Points.Count > 0 && mousePos == Points[Points.Count - 1]))
                {
                    Points.Add(mousePos);
                }
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Delete) && Points.Count > 0)
            {
                Points.RemoveAt(Points.Count - 1);
            }

            return(mousePos);
        }
Ejemplo n.º 2
0
        public void Draw(SpriteBatch spriteBatch)
        {
            for (var i = 0; i < Points.Count; ++i)
            {
                Vector2 distance;
                if (i + 1 == Points.Count)
                {
                    distance = mousePos - Points[i];
                }
                else
                {
                    distance = Points[i + 1] - Points[i];
                }

                var length = Math.Pow(distance.X, 2) + Math.Pow(distance.Y, 2);
                length = Math.Sqrt(length);
                var angle = (float)Math.Atan2(distance.Y, distance.X);
                var box   = new Rectangle((int)Points[i].X, (int)Points[i].Y, (int)length, 3);
                spriteBatch.Draw(line, box, null, Color.White, angle, new Vector2(0, line.Height / 2F), SpriteEffects.None, 1f);
            }

            foreach (var point in Points)
            {
                spriteBatch.Draw(dot, point, null, Color.White, 0, new Vector2(dot.Width / 2F, dot.Height / 2F), 1 / Camera.GetZoom(), SpriteEffects.None, 1f);
            }
        }