   Programming more than just 4 degrees of movement in a 2D game...
  I've got a 2D (DX9) game that I'm working on and right now the character can drive (a tank) in 4 different directions. Easy enough. But I actually have 16 different directions that the sprite can face. So how would I go about the programming for 16 directions?Right now I'm just adjusting the x and y for the 4 directions (up, down, left, right). Easy enough. What I'd like is to have forward move the vehicle forward, and left or right turns slightly in the respective direction.Any code examples would be great. I'm using C++. I thinking it shouldn't be too hard but my brain is fuzzy right now and I've never seen a code example of this.Edit: I think 2D vectors will do the trick. I'm going to give it a shot and see if it works. Feel free to reply anyway and yell at me for being dumb.Another Edit: I'm not going to be just rotating the tank via game code, it actually has 16 different frames depending on which way it's facing... So how can I limit the 2D vector to one of those 16 directions? Does that make sense?   
  I feel like I'm getting both closer and farther away to the solution at the same time. Any help would be appreciated.   ;  You can just use sin and cos to calculate the position change based on angle and speed.x += cos (angle) * feet_per_sec * time_incrementy += sin (angle) * feet_per_sec * time_incrementThe angle would have to be in radians.  If you're using degrees, just multiply the angle by PI/180.  The time increment is the time in seconds for the current frame.  At 24 frames per sec, the value would be 1/24 or roughly .04167.  Hope this helps.   ;  You can use trig like Coderx suggested, or since you know you will only be using 16 directions, just using vector values is pretty simple. Consider  if you are in the quadrant where x and y are both positive. The four vectors you need to know for this quadrant would simply be:{1.0, 0.0} -- Moving at 0 degrees{2.0, 1.0} -- Moving at 22.5 degrees{1.0, 1.0} -- Moving at 45 degrees{1.0, 2.0} -- Moving at 67.5 degrees(Don't forget to normalize your vec)As you can see it is trivial to get these vectors for the remaining 3 quadrants, and once you know them you can avoid using trig if you so desire.Tank games are fun, good luck!Edit: To better fit in line with Coderx's example, you simply multiply your normalized vector by a scalar (in this case feet/sec and sec/frame) to achieve different speeds.   ;Quote:Original post by shadowcomplexYou can use trig like Coderx suggested, or since you know you will only be using 16 directions, just using vector values is pretty simple. Consider  if you are in the quadrant where x and y are both positive. The four vectors you need to know for this quadrant would simply be:{1.0, 0.0} -- Moving at 0 degrees{2.0, 1.0} -- Moving at 22.5 degrees{1.0, 1.0} -- Moving at 45 degrees{1.0, 2.0} -- Moving at 67.5 degrees(Don't forget to normalize your vec)As you can see it is trivial to get these vectors for the remaining 3 quadrants, and once you know them you can avoid using trig if you so desire.Tank games are fun, good luck!Edit: To better fit in line with Coderx's example, you simply multiply your normalized vector by a scalar (in this case feet/sec and sec/frame) to achieve different speeds.This was exactly what I was looking for. I knew I was on the right track but didn't quite know the best way to do it for the 16 specific values. Thank you!   