I am trying to implement a snake game in C# using the WPF forms. Well I know to implement the snake game, where the snake is controlled by the keyboard. But how would I do it, if I wanted to control the snake using a mouse rather than a keyboard?
Tell me more
×
Game Development Stack Exchange is a question and answer site for
professional and independent game developers. It's 100% free, no registration required.
|
|
On your gamefield element add a
And in an appropriate spot in the worm class (such as an update method, or called from the Target/Position setters):
With this logic it would try to close in the longest orthogonal distance (x or y) first, and then go zigzag to the cursor when the distance is the same in both x and y, other options would be to use a line drawing algorithm to make it go more smoothly towards the cursor. There is a few other things to consider as well, such as what do we do if the worm reaches the mouse, does it stop, or do we allow it to first pass the cursor and then double back thus hitting itself? |
|||
|