Hey everyone,
Just repeating below some things I fleshed out on Discord.
My wife downloaded Word Cookie on her phone, so I was playing it a little bit. It looks like a bezier curve of some kind is drawn between the first letter you touch and the current location you drag to. I'd like to simplify that to just drawing a line for now. It should be easy to just poll the mouse or touch screen for the current position to determine where the line is being drawn. I think there is some capability to vector draw rays in MonoGame. I think we can look at that to draw lines between letters unless people have a different preference.
It looks like drawing simple lines in MonoGame is not an option. What do you guys feel about an extension method like this for starters?
public static class SpriteBatchExtensionMethods
{
public static void DrawLine(this SpriteBatch spriteBatch, Vector2 lineStart, Vector2 lineEnd, Color color, int width = 1)
{
Texture2D pixel = new Texture2D(spriteBatch.GraphicsDevice, 1, 1);
pixel.SetData<Color>(new Color[] { color });
Rectangle rectangle = new Rectangle((int)lineStart.X, (int)lineStart.Y, (int)(lineEnd - lineStart).Length() + width, width);
Vector2 vectorNormal = Vector2.Normalize(lineStart - lineEnd);
float angle = (float)Math.Acos(Vector2.Dot(vectorNormal, -Vector2.UnitX));
if (lineStart.Y > lineEnd.Y)
angle = MathHelper.TwoPi - angle;
spriteBatch.Draw(pixel, rectangle, null, color, angle, Vector2.Zero, SpriteEffects.None, 0);
}
}
Using the extension method in practice:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.DrawLine(new Vector2(15, 15), new Vector2(90, 95), Color.Black, 5);
spriteBatch.DrawLine(new Vector2(100, 38), new Vector2(300, 38), Color.Orange, 12);
spriteBatch.End();
base.Draw(gameTime);
}
I'd like to see us design an InputManager class that contains two sub-classes. A MouseManager and a TouchPadManager. Then our Controller can reference the InputManager that will handle farming the input poll to either touchscreen or mouse. I'm up for other models as well depending on what people want.
I'm happy to focus on the TouchPadManager for starts (or most of the input code).
-Brett