title: Android implementation walking through game map, diagonal movement does not work correctly
body: <p>The situation looks like that when main character (chibi1) walks vertically or horizontally everything works fine. The problem is when we want to move diagonally. The main character miss destined map's field, then moves ahead and stops in various fields.</p>
  <p>In code, the problem is that I do not know what to put in the right side of equation <code>stepsSkew = ?WHAT?;</code> in order to have as a result approximately 1 (it's computed as double) when main character moves one diagonal field (two as a result when 2 diagonal fields and so on). Horizontal and vertical variables that are responsible for counting that fields that is <code>stepsX</code> and <code>stepsY</code> also computes movement similarly like one field horizonally/vertically passed gives approximately 1 (its double e.g. 1.007134) and that works.</p>
  <p><strong>I'm thinking maybe of using Pythagorean theorem in this equation but how exactly should it looks like in this example? But maybe I am wrong...</strong></p>
  <p>Variable <code>steps</code> just counts those steps already passed like 1,2,3, ... .</p>
  <p>Full code looks like this:</p>
  <p>GameSurface.java</p>
  <pre><code>public class GameSurface extends SurfaceView implements SurfaceHolder.Callback {
  
      int movingVectorX, movingVectorY;
      double stepX, stepY, stepsX, stepsY, stepsSkew;
      List&lt;Integer&gt; pathX = new ArrayList&lt;&gt;(), pathY = new ArrayList&lt;&gt;(), movingVectorsX = new ArrayList&lt;&gt;(), movingVectorsY = new ArrayList&lt;&gt;();
  
      @Override
      public void draw(Canvas canvas) {
          super.draw(canvas);
  
          (...)
  
          movementControl(canvas);
      }
  
  (...)
  </code></pre>
  <p>movementControl()</p>
  <pre><code>    private void movementControl() {
      stepX = Math.abs(getChibiXCenterWhenTapUp - chibi1.getX() - (chibi1.getWidth() / 2));
      stepY = Math.abs(getChibiYCenterWhenTapUp - chibi1.getY() - (chibi1.getHeight() / 2));
  
      if (movingVectorX != 0 &amp;&amp; movingVectorY == 0)
          stepsX = stepX / cellWidth;
      if (movingVectorX == 0 &amp;&amp; movingVectorY != 0)
          stepsY = stepY / cellHeight;
      if (movingVectorY != 0 &amp;&amp; movingVectorX != 0) {
          // HERE IS A PROBLEM
          stepsSkew = ?WHAT?;
      }
  
  
      steps = (int) (stepsX + stepsY + stepsSkew);
  
      if (pathX.size() &gt; 1 &amp;&amp; pathY.size() &gt; 1) {
          if ((chibi1.getX() + (chibi1.getWidth() / 2) &lt; pathX.get(steps)) &amp;&amp; !drawerOn)
              movingVectorX = 1;
          if ((chibi1.getX() + (chibi1.getWidth() / 2) &gt; pathX.get(steps)) &amp;&amp; !drawerOn)
              movingVectorX = -1;
          if ((chibi1.getY() + (chibi1.getHeight() / 2) &lt; pathY.get(steps)) &amp;&amp; !drawerOn)
              movingVectorY = 1;
          if ((chibi1.getY() + (chibi1.getHeight() / 2) &gt; pathY.get(steps)) &amp;&amp; !drawerOn)
              movingVectorY = -1;
      }
  
      if (steps &lt; (pathY.size() - 1)) {
          chibi1.setMovingVector(movingVectorsX.get(steps), movingVectorsY.get(steps));
      }
  
      if (steps &gt;= (pathY.size() - 1)) {
          chibi1.setMovingVector(0, 0);
          if (selectedNode != enemyNode) {
               chibi1.setX((cellWidth * ((chibi1.getX() / cellWidth))) + (cellWidth / 2) - (chibi1.getWidth() / 2));
               chibi1.setY(((cellHeight) * ((chibi1.getY() / cellHeight))) + (cellHeight / 2) - (chibi1.getHeight() / 2));
          }
          movingVectorY = 0;
          movingVectorX = 0;
          steps = 0;
          }
      }
  </code></pre>
  <p>GestureListener.java</p>
  <pre><code>    @Override
      public boolean onSingleTapUp(MotionEvent e) {
         setValuesOnTapUp(e);
  
         (...)
  
         return true;
     }
  
     (...)
  </code></pre>
  <p>setValuesOnTapUp()</p>
  <pre><code>    void setValuesOnTapUp(MotionEvent e) {
  
      (...)
  
      gs.getChibiXCenterWhenTapUp = gs.chibi1.getX() + (gs.chibi1.getWidth() / 2);
      gs.getChibiYCenterWhenTapUp = gs.chibi1.getY() + (gs.chibi1.getHeight() / 2);
  }
  </code></pre>
  <p>I know there is much of it and if you need some more informaton please just ask.</p>
  <p>Thank you!</p>