title: Following a straight line (via Path?)
body: <p>I'm working on a game which will use projectiles. So I've made a Projectile class and a new instance is created when the user touches the screen:</p>
  
  <pre><code>@Override
  public boolean onTouch(View v, MotionEvent e){
      float touch_x = e.getX();
      float touch_y = e.getY();
      new Projectile(touch_x, touch_y);
  }
  </code></pre>
  
  <p>And the Projectile class:</p>
  
  <pre><code>public class Projectile{
  
      float target_x;
      float target_y;
      Path line;
  
      public Projectile(float x, float y){
          target_x = x;
          target_y = y;
  
          line = new Path();
          line.moveTo(MyGame.mPlayerXPos, MyGame.mPlayerYPos);
          line.lineTo(target_x, target_y);
      }
  }
  </code></pre>
  
  <p>So this makes a Path with 2 points, the player's position and and touch coords. My question is - How can you access points on this line? For example, if I wanted to get the x,y coords of the Projectile at the half point of the line, or the point the Projectile would be at after 100 ticks (moving at a speed of X pixels/tick)?</p>
  
  <p>I also need the Projectile to continue moving after it reaches the final point.. do I need to use line.addPath(line) to keep extending the Path?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I managed to get the Projectiles moving in a straight line, but they're going in strange directions. I had to fudge some code up:</p>
  
  <pre><code>private void moveProjectiles(){
          ListIterator&lt;Projectile&gt; it = Registry.proj.listIterator();
          while ( it.hasNext() ){
              Projectile p = it.next();
              p.TimeAlive++;
  
              double dist = p.TimeAlive * p.Speed;
              float dx = (float) (Math.cos(p.Angle) * dist);
              float dy = (float) (Math.sin(p.Angle) * dist);
  
              p.xPos += dx;
              p.yPos += -dy;
          }
      }
  </code></pre>
  
  <p>The <code>Angle</code> must be the problem.. I'm using this method, which works perfectly:</p>
  
  <pre><code>private double getDegreesFromTouchEvent(float x, float y){
          double delta_x = x - mCanvasWidth/2;
          double delta_y = mCanvasHeight/2 - y;
          double radians = Math.atan2(delta_y, delta_x);
  
          return Math.toDegrees(radians);
      }
  </code></pre>
  
  <p>However, it returns 0-180 for touches above the center of the screen, and 0 to -180 for touches below. Is this a problem?</p>