// Written by Larry Landwehr 12/95 import java.util.*; import java.awt.*; import java.applet.Applet; //-------------------------------------------------- class kaboomPanel extends Panel implements Runnable { KaBoom kaboom; Thread thread; int nlines; Line lines[] = new Line[100]; Bomb bomb = new Bomb(); Object pick; Image offscreen; boolean explode = false; Dimension offscreensize; Graphics offgraphics; //---- kaboomPanel(KaBoom kaboom) { this.kaboom = kaboom; } //---- int addLine(int x, int y, int p, int q) { Line n = new Line(); n.set(x, y, p, q); lines[nlines] = n; return nlines++; } //---- void addBomb(int x, int y) { bomb.set(x, y); } //---- public void run() { while (true) { repaint(); try { Thread.sleep(100); } catch (InterruptedException e) { break; } } } //---- public void paintLine(Graphics g, Line n) { g.setColor(Color.blue); g.drawLine(n.x, n.y, n.p, n.q); } //---- public void paintBomb(Graphics g, Bomb b) { g.setColor(Color.red); g.fillRect(b.x, b.y, 5, 5); } //---- public synchronized void update(Graphics g) { Dimension d = size(); if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) { offscreen = createImage(d.width, d.height); offscreensize = d; offgraphics = offscreen.getGraphics(); offgraphics.setFont(getFont()); } if (explode == true) { for (int i=0; i<3; i++) { offgraphics.setColor(Color.red); offgraphics.fillRect(0, 0, d.width, d.height); g.drawImage(offscreen, 0, 0, null); offgraphics.setColor(Color.yellow); offgraphics.fillRect(0, 0, d.width, d.height); g.drawImage(offscreen, 0, 0, null); } for (int i=0; i0) ? 3.0 : -3.0; } return; } s = (double)dy / (double)dx; this.mx = 3.0 / Math.sqrt(1.0 + s*s); this.my = Math.abs(s * this.mx); if (dx<0) this.mx = -this.mx; if (dy<0) this.my = -this.my; } } //-------------------------------------------------- class Bomb { int x, y; int ox, oy; public void set(int x, int y) { this.x = x; this.y = y; this.ox = x; this.oy = y; } public void restore() { this.x = this.ox; this.y = this.oy; } public void move(int x, int y) { this.x = x; this.y = y; } public double dist(int x, int y) { double dist; dist = (this.x - x) * (this.x - x) + (this.y - y) * (this.y - y); return(dist); } }