// GilaMonster Class // GilaMonster.java // Imports import java.awt.*; import java.applet.Applet; import java.util.*; public class GilaMonster extends DirectionalSprite { // Action flag to add baby spider (extended sprite action flags, must be > 2) public static final int SA_ADDSPIDERLING = 4; public static Image[][] image; protected static Random rand = new Random( System.currentTimeMillis()); public GilaMonster(Component comp) { super(comp, image, 0, 1, 4, new Point(comp.size().width - image[2][0].getWidth(comp), 45), new Point(1, 0), 50, Sprite.BA_WRAP, 6); } public GilaMonster(Component comp, Point pos) { super(comp, image, 0, 1, 4, pos, new Point(1, 0), 90, Sprite.BA_WRAP, 2); } public static void initResources(Applet app, MediaTracker tracker, int id) { /** Initialize gila monster images.*/ image = new Image[8][2]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 2; j++) { image[i][j] = app.getImage(app.getCodeBase(), "Res/GilaMo" + i + j + ".gif"); tracker.addImage(image[i][j], id); } } } public BitSet update() { /** This updates the gila monster.*/ // Call parent's update() BitSet action = super.update(); /** This sets the flag to add a new spider at random time intervals*/ if (rand.nextInt() % 20 == 0) { action.set(Sprite.SA_ADDSPRITE); action.set(GilaMonster.SA_ADDSPIDERLING); } return action; } protected Sprite addSprite(BitSet action) { /** Give birth to a new spider?*/ if (action.get(GilaMonster.SA_ADDSPIDERLING)) { WarMan.badcount += 1; return new Spiderling(component, new Point(position.x, position.y)); } return null; } protected void setCollision() { collision = new Rectangle(position.x + 3, position.y + 3, position.width - 6, position.height - 6); } }