Hello,

I am coming across a problem where my isMoving() acessor method is not working properly. The program works decently, (I have to fix a few values to make it more visually sound) but the animation is fine. However, if isMoving() ever returns true, the Launcher class will not create the first projectile, but the x and y velocities constantly change.

My more Java-wise friend was unable to figure out what was wrong with the code ( he suspected there was something wrong with the VisibleImage or with the xMove variable) but when I was going through checking what worked and what didn't, the only thing that caused problems was the isMoving() method.



 import java.awt.*;
import objectdraw.*;
 
public class Launcher extends WindowController{  
  private static final int LEFT = 1;
  private static final int WIDTH = 800;
  private static final int TOP = 1;
  private static final int HEIGHT = 430;
  private static final int GROUND_HEIGHT=20;
  private static final double X_VELOCITY = 5;
  private static final double Y_VELOCITY = -8;
 
  Projectile ball;
  Image picture;
  FilledRect ground;
 
  public void begin(){
    picture = getImage ("record2.gif");
    ground = new FilledRect(LEFT,TOP+HEIGHT,WIDTH,GROUND_HEIGHT,canvas);
    ground.setColor(Color.GREEN);
    new FramedRect(LEFT,TOP,WIDTH,HEIGHT+GROUND_HEIGHT, canvas);
  }
  //On mouse press, the launcher is supposed to display the animation of the ball falling in a trajectory. If there is already a ball moving, the program will not make another ball until it has ceased moving.
  public void onMousePress(Location point){ 
    if (ball == null){
      ball = new Projectile( picture, point, X_VELOCITY, Y_VELOCITY, ground, WIDTH+LEFT, canvas );
    }
    else if (!ball.isMoving()){
      ball = new Projectile( picture, point, X_VELOCITY, Y_VELOCITY, ground, WIDTH+LEFT, canvas );      
    }
    while (ball.isMoving()) {
    }
  }
 
}





 import java.awt.*;
import objectdraw.*;
 
public class Projectile extends ActiveObject{
  private VisibleImage fallingGraphic;
  private DrawingCanvas canvas;
  private static double yVelocity;
  private static double xMove = 5;
  private final double Y_ACCELERATION = 2.5;
  private final double GROUND_HEIGHT = 20;
  //private double xVelocity = 0;
  private static final double X_ACCELERATION = .1;
  private static final double Y_STEP = 2;
  private static final int DELAY_TIME = 35;
  private FilledRect borderRight;
// sorry for it being disorganized, I was editing this constantly to attempt to fix the program. 
 
  //constructor for the projectile, a visible image
 
  public Projectile (Image graphicDrop, Location initialLoc, double velocityX, double velocityY, FilledRect boundryGround, int boundryRight, DrawingCanvas aCanvas) {
    canvas = aCanvas;
    borderRight = boundryGround;
    fallingGraphic =  new VisibleImage(graphicDrop, initialLoc,  canvas);
    yVelocity = velocityY;
    //xVelocity = velocityX;
    start(); 
  }
// acessor methods for getX and getY, and also the problematic isMoving.
  public double getX() {
    return fallingGraphic.getX();
  }
  public double getY() {
    return fallingGraphic.getY();
  }
  public boolean isMoving() {
    if (Math.abs(yVelocity) > 0) { // || Math.abs(xMove) > 0) {
      return true;
    } 
    else {
      return false;
    }
  }
 
  public void run() {
   // System.out.println("0 yVelocity before loop" + yVelocity);  
    xMove = 5;
    if (yVelocity != 0) {
      while (fallingGraphic.getY() <= borderRight.getY() && fallingGraphic.getX() <= borderRight.getWidth() && yVelocity !=0) { // if the fallingGraphic is above the bottom rectangle, it is to the left of the right boundry and the velocity is greater than zero, it will fall in an arc and accelerate in the y direction, and decelerate in the x direction.
        fallingGraphic.move(xMove, yVelocity);
        yVelocity += Y_ACCELERATION;  
        xMove -= X_ACCELERATION;
        System.out.println("1 yVelocity after loop" + yVelocity + ", xV" +  xMove);
        pause(DELAY_TIME);   
        if (Math.abs(yVelocity) <.5 && xMove <1) { // if the y or x velocity is below a certain value, it will stop moving.
          yVelocity = 0;
          xMove = 0;
        }
        if (fallingGraphic.getY() >= borderRight.getY() - GROUND_HEIGHT && yVelocity != 0) { // if the graphic hits the ground border, the velocity will be reversed.
          System.out.println("2 yVelocity after loop" + yVelocity + ", xV" +  xMove);
          fallingGraphic.move(xMove, -yVelocity);        
          yVelocity = -yVelocity/2 + Y_ACCELERATION;
          yVelocity += Y_ACCELERATION;
          xMove -= X_ACCELERATION;
          pause(DELAY_TIME);
          if (Math.abs(yVelocity) < .5 && xMove <1) {
            yVelocity = 0;
            xMove = 0;
          }
        }
// if the graphic hits the right border, the x velocity is reversed.
        if (fallingGraphic.getX() >= borderRight.getWidth() -20 && yVelocity != 0) {
          fallingGraphic.move(-xMove, yVelocity);  
          yVelocity += Y_ACCELERATION;
          xMove = -xMove + X_ACCELERATION;
          xMove -= X_ACCELERATION;
          pause( DELAY_TIME) ;
        }
      }
    }
   }
    }
Any help would greatly be appreciated. I am very new to Java so I apologize if this is a very simple question.