import java.applet.*; import java.awt.*; import java.util.*; public class Flipper extends Thread { public static final int LEFT = 1; public static final int RIGHT = -1; public static final int WIDTH = 33; public static final int delay = 20; public static final double ANGLESTEP = 15; public double MAXANGLE = 45; public int x, y, power, cpower; public double MINANGLE, angle, cangle; public Game parent; public int type; PBall ball[]; public Flipper (int x1, int y1, double mina, Game p, int t) { x = x1; y = y1; type = t; MINANGLE = mina; MAXANGLE = MAXANGLE * type; angle = mina; parent = p; power = 0; cpower = 0; cangle = 0; } public void setBall (PBall b[]) { ball = b; } public void showBar (Graphics g, Color c1, Color c2) { Polygon p = new Polygon (); double ta1, ta2; int nx1, ny1, nx2, ny2, nx3, ny3; ta1 = -1 * type * angle; ta2 = 90 + ta1; ny1 = y + (int) (WIDTH * Math.sin (Direction.getRand(ta1))); nx1 = x + (int) (type * WIDTH * Math.cos (Direction.getRand(ta1))); ny2 = y + (int) (PBall.ria * Math.sin (Direction.getRand(ta2))); nx2 = x + (int) (type * PBall.ria * Math.cos (Direction.getRand(ta2))); ny3 = ny1 + (int) (PBall.ria * Math.sin (Direction.getRand(ta2))); nx3 = nx1 + (int) (type * PBall.ria * Math.cos (Direction.getRand(ta2))); p.addPoint (x, y); p.addPoint (nx1, ny1); p.addPoint (nx3, ny3); p.addPoint (nx2, ny2); g.setColor (c1); g.fillPolygon (p); g.setColor (c2); g.drawPolygon (p); p = null; } public void delay (int d) { try { Thread.sleep(d); } catch (InterruptedException e) {}; } public double reachBar (PBall b) { Polygon p = new Polygon (); double nangle = 0, ta1, ta2; int nx1, ny1, nx2, ny2, nx3, ny3; double cthick; ta1 = -1 * type * angle; ta2 = 90 + ta1; cthick = Math.max ((double) PBall.ria, Math.sqrt(b.YValue*b.YValue+b.XValue*b.XValue)+2); ny1 = y-PBall.ria + (int) ((WIDTH+PBall.ria) * Math.sin (Direction.getRand(ta1))); nx1 = x + (int) (type * (WIDTH+PBall.ria) * Math.cos (Direction.getRand(ta1))); ny2 = y-PBall.ria + (int) (cthick * Math.sin (Direction.getRand(ta2))); nx2 = x + (int) (type * cthick * Math.cos (Direction.getRand(ta2))); ny3 = ny1 + (int) (cthick * Math.sin (Direction.getRand(ta2))); nx3 = nx1 + (int) (type * cthick * Math.cos (Direction.getRand(ta2))); p.addPoint (x, y-PBall.ria); p.addPoint (nx1, ny1); p.addPoint (nx3, ny3); p.addPoint (nx2, ny2); if (p.inside (b.x, b.y)) { nangle = angle; } if (p.inside (b.x, b.y)) { nangle = angle; } if (p.inside (b.x, b.y)) { nangle = angle; } if (p.inside (b.x, b.y)) { nangle = angle; } p = null; if (nangle != 0) { cpower = power; cangle = ta2; } return (nangle); } public void checktouch (PBall ba) { double nangle, i, accspeed; synchronized (ba) { i = reachBar (ba); if (i != 0) { ba.di.setDirection (cangle); accspeed = 3*cpower*(90 - ba.ANGDIF)/90; ba.di.reflect (ba, i); ba.speed += accspeed; ba.checkspeed (); ba.getXYValue (); } } } public void BarUp () { switch (type) { case LEFT: if (angle < MAXANGLE) { angle += ANGLESTEP; power ++; for (int i=0; i MAXANGLE) { angle -= ANGLESTEP; power ++; for (int i=0; i MINANGLE) { angle -= ANGLESTEP; power = 0; for (int i=0; i