I am supposed to create a hit the target class with multiple classes. First place a ball that moves horizontally on the cavas, then create another class with a square that shoot up three balls when the user click the mouse.

This class extends Active Objects. Any ideas?

Member Avatar for Dukane

OK...what code do you have?

I have the first class Hit the target class as follows:

import jave.awt.*;
import object.draw.*;

public class HitTheTarget extends ActiveObject {
private static final int SIZE=15;
private static final int DELAY_TIME = 2;
private DrawingCanvas canvas;
private FilledOval ballGraphic;

public HitTheTarget(Location initialLocation, DrawingCanvas, aCanvas); {
canvas = aCanvas;
ballGraphic FilledOval (initialLocation, SIZE, SIZE, canvas);
start ();
}

public void run(){


I have no idea how to continue and make the ball appear on the canavs and be moving horizontally.

import jave.awt.*;
import object.draw.*;

public class HitTheTarget extends ActiveObject {
private static final int SIZE=15;
private static final int DELAY_TIME = 2;
private DrawingCanvas canvas;
private FilledOval ballGraphic;

public HitTheTarget(Location initialLocation, DrawingCanvas, aCanvas); {
canvas = aCanvas;
ballGraphic FilledOval (initialLocation, SIZE, SIZE, canvas);
start ();
}

Sorry you have done nothing so far. In the code which you provided we can only see declaration of some variables and not realy suceful setup of canvas and drawing of ball.
So firstly do static view of your ball, than make it move(maybe timing like move 1pixel/100ms).Next you want to know x,y positions of ball on event. Then create your hit box area where you will geting again x,y coordinates on event. Then last thing remains is to compare this two sets of cordinates to see if you hit/miised

I also have the run ()

public void run (){
         while(ball Graphic.getX() < canvas.getWidth(){
                  ballGraphic.move(X_SPEED, 0);
                  pause (DELAY_TIME);
        }
        ballGraphic.removeFromCanvas();
    }

}

I thought that this run method should make the ball appear on the canvas and be moving, but it does not. I am new to this so it is taking me a while to get it.

I am supposed to first place the ball on the canvas and make it move, then move to the other classes such as the square that it the shooter, and the three balls that are supposed to shoot up when the user clicks.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.