TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nate Wilkins
NA
1
0
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(); } }
Reply
Answers (
0
)
How to change the master page from a winform?
DSLC