import java.applet.*; import java.awt.*; import java.util.*; public class PBall extends Thread { public static final int ria = 6; public static final double MAXSPEED = 17; public static final double MINSPEED = 1; public static final double speeddec = 0.4; public static final double speedinc = 0.4; public static final int SLEEP = 20; public int BallNo; public PBall ball[]; public int ox, oy, x, y; public double XValue, YValue; public double t1, t2, ANGDIF, CANGLE; public double speed; public Direction di; public Color bc, fc, cc; public boolean Exist; Region re[]; Graphics g; Flipper LB, RB; Game parent; public PBall (int bno, Region rearg[], Graphics garg, Game p) { BallNo = bno; re = rearg; g = garg; bc = Color.black; fc = Color.gray; cc = Color.lightGray; Exist = true; parent = p; ANGDIF = 0; CANGLE = 0; di = new Direction (0, 0); } public void setOBall (PBall b[]) { ball = b; } public void setBar (Flipper l, Flipper r) { LB = l; RB = r; } public void setBallXY (int xarg, int yarg) { x = xarg; y = yarg; } public void setBallXYValue (double xarg, double yarg) { XValue = xarg; YValue = yarg; } public void getXYValue () { XValue = speed * Math.cos (Direction.getRand(di.tangle)); YValue = speed * Math.sin (Direction.getRand(di.tangle)); } public void delay () { try { Thread.sleep (SLEEP); } catch (InterruptedException e) {}; } public void SetBallColor (Color f, Color b) { fc = f; bc = b; } public void checkspeed () { if (speed > MAXSPEED) speed = MAXSPEED; } public double TouchBall (PBall b) { double nangle = 0, nnangle = 0; double dis, aa, bb; int nx, ny; aa = (double) (b.x-x); bb = (double) (b.y-y); dis = Math.sqrt (aa*aa+bb*bb); if (dis < b.ria+ria+2) { nx = b.ox; ny = b.oy; aa = (double) (nx-x); bb = (double) (ny-y); dis = Math.sqrt (aa*aa+bb*bb); nnangle = 360*Math.acos(Math.abs(aa)/dis)/(2*Math.PI); if (aa*bb > 0) nangle = 90 - nnangle; else nangle = -1*(90-nnangle); if (nangle == 0) nangle = 180; } return (nangle); } public boolean Nextstep () { Direction ndi = new Direction (di.angle, di.phase); double i, accspeed; int j; boolean endball = false; synchronized (this) { ox = x; oy = y; x += (int) XValue; y += (int) YValue; for (j=0; j0 || i<-1) { ndi.calangle (this); ndi.reflect (this, i); di.setDirection (ndi.angle, ndi.phase); re[j].CheckSpeed (this); checkspeed (); getXYValue (); x = ox; y = oy; break; } else { if (i==-1) { endball = true; break; } } } i = LB.reachBar (this); if (i != 0) { ndi.calangle (this); ANGDIF = Math.abs(ndi.tangle-LB.cangle); accspeed = 3*LB.cpower*(90 - ANGDIF)/90; ndi.reflect (this, i); di.setDirection (ndi.angle, ndi.phase); speed += accspeed; checkspeed (); getXYValue (); x = ox; y = oy; } else { i = RB.reachBar (this); if (i != 0) { ndi.calangle (this); ANGDIF = Math.abs(ndi.tangle-RB.cangle); accspeed = 3*RB.cpower*(90 - ANGDIF)/90; ndi.reflect (this, i); di.setDirection (ndi.angle, ndi.phase); speed += accspeed; checkspeed (); getXYValue (); x = ox; y = oy; } } for (j=0; j