bool move = true; private void Form1_KeyDown(object sender, KeyEventArgs e) { int x = pictureBox1.Location.X; int y = pictureBox1.Location.Y; if (e.KeyCode == Keys.W) y -= 5; else if (e.KeyCode == Keys.S) y += 5; else if (e.KeyCode == Keys.A) x -= 5; else if (e.KeyCode == Keys.D) x += 5; { pictureBox1.Location = new Point(x, y); } if (move == false) { pictureBox1.Location = new Point(0, 0); } } private void Form1_Load(object sender, EventArgs e) { timer1.Interval = 50; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { if (pictureBox1.Bounds.IntersectsWith(pictureBox2.Bounds)) { pictureBox1.BackColor = Color.Black; move = false; } else { pictureBox1.BackColor = Color.Blue; } }
if (move == false) ...
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)