title: movement code c++
body: <p>I am making a game in C++ using DirectX. I have a basic AI drawn. I want the AI to move around in a square, for example:</p>
  
  <ul>
  <li>the AI moves up the Z axis until it reaches 25,</li>
  <li>then the AI moves  along the X axis by 25,</li>
  <li>then down the Z axis by 25,</li>
  <li>then back along the X axis until it has completed a full movement in the shape of a square.</li>
  </ul>
  
  <p>Here is what I have so far; this makes the AI move 25 up the Z axis, then 25 down the Z axis over and over again.</p>
  
  <pre><code>if (ghost_moves_forward == true)
  {
      ghost_Z -= ghost_movement;
  }
  else if (ghost_moves_forward == false)
  {
      ghost_Z += ghost_movement;
  }
  
  
  if (ghost_Z &gt;= 25)
  {
      ghost_moves_forward = true;
  }
  if (ghost_Z &lt;= -25)
  {
      ghost_moves_forward = false;
  }
  </code></pre>
  
  <p>Thank you in advance.</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <pre><code>float ghost_X = 0; //make the AI move along the x axis
  float ghost_Z = 0; // makes the AI move along the Z axis
  int ghost_movement = 1; // speed the AI moves
  bool ghost_moves_forward = true; // true when AI moves forward, false when its moving sideways
  bool ghost_moves_sideways = true;// true when moving sideways, false when moving forwards
  </code></pre>
  
  <p>I am using <code>ghost_X</code> and <code>ghost_Z</code> for the translation positions of the AI.</p>
  
  <pre><code>D3DXMatrixTranslation( &amp;g_matLocal, ghost_X, 0, ghost_Z );
  </code></pre>