SAMPLE APPLET:
ASSIGNMENT: The collision detection algorithm used in this applet is far from perfect (as you can see by observing the behavior of the applet). BUT it is reasonably simple.
There are a few things you need to do to get this to work:
int[] x = {5, 100, 170, 200, 280}; //starting x position
int[] y = {5, 100, 170, 200, 280}; //starting y position
int[] xDir = {1, 1, -1, -1, -1}; //positive one
int[] yDir = {1, 1, -1, 1, 1};
int[] xInc = {3, 2, 3, 1, 1};
int[] yInc = {1, 2, 1, 2, 2};
Color[] color = {Color.red, Color.blue, Color.green,
Color.black, Color.cyan};
All this goes before the init method.
First: import
import java.util.*;
Second: declare
Random r;
Third: initialize
r = new Random();