package shotcaller; import java.awt.*; import java.applet.*; import java.util.*; import javax.swing.*; import java.math.*; import java.awt.event.*; import javax.swing.event.MouseInputAdapter; public class shot extends Applet { public void mouseMoved(MouseEvent e){ x = e.getX(); y = e.getY(); } public class cue { int x; int y; } public class ball { double grav =.6; double damp =.98; int rad = 12; double x; double y; double vx =0; double vy =0; int m = 3; } int i = 0; int j = 0; Object ball; int bmax = 8; ball[] b = new ball [8]; public void fold(){ for (i= 0; i < bmax; i++){ b[i] = new ball(); } b[0].x=70; b[1].x=387; b[2].x=414; b[3].x=444; b[4].x=444; b[5].x=444; b[6].x=414; b[7].x=-100; b[0].y=132; b[1].y=132; b[2].y=117; b[3].y=103; b[4].y=134; b[5].y=165; b[6].y=150; b[0].vx+=40; } public int x = 0; public int y = 0; java.util.Timer timer; Graphics doublebuffer; Image offscreen; private final int WIDTH =550; private final int HEIGHT = 300; public void init(){ fold(); cue c = new cue(); this.setSize(WIDTH,HEIGHT); timer = new java.util.Timer(); timer.schedule(new gameTask(),0,1*5); offscreen = createImage(640,480); doublebuffer = offscreen.getGraphics(); } class gameTask extends TimerTask { public void run(){ repaint(); for (i = 0; i<8; i++){ if(b[i].x>520){ b[i].vx*=-1; } if(b[i].y>270){ b[i].vy*=-1; }if(b[i].y<10){ b[i].vy*=-1; } if(b[i].x<10){ b[i].vx*=-1; } b[i].vx*=b[i].damp; b[i].vy*=b[i].damp; b[i].x +=b[i].vx; b[i].y +=b[i].vy; for (j=1; j<8; j++){ double dx = b[j].x-b[i].x; double dy = b[j].y-b[i].y; double dist = Math.sqrt(dx*dx+dy*dy); if(dist