I am making a snake game. I have got it to animate. I just want it to follow the mouse pointer. I am able to find the mouse cursor position. I am also to get my snake to move to the right. What I want is to get my snake to move in the direction in the mouse pointer.
private void timer1_Tick(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
SolidBrush greenBrush = new SolidBrush(Color.Green);
SolidBrush blackBrush = new SolidBrush(Color.Black);
Rectangle rect_green = new Rectangle(340 + x, 280 + y, 100, 10);
Rectangle rect_black = new Rectangle(240 + x, 280 + y, 100, 10);
g.FillRectangle(greenBrush, rect_green);
g.FillRectangle(blackBrush, rect_black);
if (x >= 340)
{
x = 340;
}
x += 5;
greenBrush.Dispose();
g.Dispose();
if (MouseButtons == MouseButtons.Left)
{
Graphics g_two = this.CreateGraphics();
SolidBrush greenBrush_two = new SolidBrush(Color.Green);
SolidBrush blackBrush_two = new SolidBrush(Color.Black);
Rectangle rect_green_two = new Rectangle(340 + x, 280 + y, 10, 100);
Rectangle rect_black_two = new Rectangle(340 + x, 180 + y, 10, 100);
g_two.FillRectangle(greenBrush_two, rect_green_two);
g_two.FillRectangle(blackBrush_two, rect_black_two);
y += 5;
greenBrush_two.Dispose();
g_two.Dispose();
}
}