Game Movement -can't get a diagonal to work -can't make movements smoother

Nov 9 2009 9:20 PM
Ugh I have been on this problem for a while and have been searching all over the web for an answer. Im making an RPG game and can't get the movement to work. Having trouble getting a good diagonal movement with only the arrow keys plus I can't get the panel to move smoothley. Any help would be appreciated thanks. heres my code private void Main_GameForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { switch (e.KeyCode) { case Keys.U: UpdatePosition(-_speed, -_speed); break; case Keys.OemPeriod: UpdatePosition(+_speed, +_speed); break; case Keys.O: UpdatePosition(+_speed, -_speed); break; case Keys.M: UpdatePosition(-_speed, +_speed); break; case Keys.J: UpdatePosition(-_speed, 0); break; case Keys.L: UpdatePosition(_speed, 0); break; case Keys.I: UpdatePosition(0, -_speed); break; case Keys.K: UpdatePosition(0, _speed); break; case Keys.F1: _speed++; _speed = Math.Min(10, _speed); Text = "Speed: = " + _speed; break; case Keys.F2: _speed--; _speed = Math.Max(1, _speed); Text = "Speed: = " + _speed; break; default: return; } } private void UpdatePosition(int dx, int dy) { Point newPos = new Point(panel1.Location.X + dx, panel1.Location.Y + dy); newPos.X = Math.Max(0, Math.Min(ClientSize.Width - panel1.Width, newPos.X)); newPos.Y = Math.Max(0, Math.Min(ClientSize.Height - panel1.Height, newPos.Y)); if (newPos != panel1.Location) { panel1.Location = newPos; Invalidate(); } }