/* Ball class */ import java.awt.*; import java.applet.*; class Ball { int initx, inity, level, current, x, y, latency; int dx, dy; Image image; Color bgcolor; String name; boolean moving = false; Applet applet; public Ball (String _name, Image i, Applet _applet, Color _color) { image = i; bgcolor = _color; applet = _applet; setPos(0, 0); setdelta(10, 10); name = _name; current = 0; } public void setPos(int _x, int _y) { x = _x; y = _y; } public void setdelta(int _dx, int _dy) { dx = _dx; dy = _dy; } public void setVars(int x, int y, int lvl, int late) { initx = x - 2; inity = y - 14; setPos(initx, inity); level = lvl; moving = true; latency = late; } public void paint(Graphics g) { g.drawImage(image, x, y, applet); } public void hide(Graphics g) { g.setColor(bgcolor); g.fillRect(x, y, image.getWidth(applet), image.getHeight(applet) - 2); } public void move(Graphics g) { if (latency > 0) { latency--; return; } if (moving) { hide(g); y += dy; if (Math.random() < 0.5) x -= dx; else x += dx; current++; if (current > level) { x = initx; y = inity; current=0; } setPos(x, y); paint(g); } } }