// Spiderling Class // Spiderling.java // Imports import java.awt.*; import java.applet.Applet; import java.util.BitSet; public class Spiderling extends Sprite { // Spider action flags (extended sprite action flags, must be > 2) public static final int SA_ADDSPIDER = 3; protected static Image[] image = new Image[6]; /**Constructor*/ public Spiderling(Component comp, Point pos) { super(comp, image, 0, 1, 20, pos, new Point(0, 0), 10, Sprite.BA_DIE); } /** Initialize the images.*/ public static void initResources(Applet app, MediaTracker tracker, int id) { for (int i = 0; i < 6; i++) { image[i] = app.getImage(app.getCodeBase(), "Res/Spling" + i + ".gif"); tracker.addImage(image[i], id); } } public BitSet update() { BitSet action = new BitSet(); // Die? if (frame >= 5) { action.set(Sprite.SA_KILL); action.set(Sprite.SA_ADDSPRITE); action.set(Spiderling.SA_ADDSPIDER); return action; } // Increment the frame incFrame(); return action; } protected Sprite addSprite(BitSet action) { // Add spider? if (action.get(Spiderling.SA_ADDSPIDER)) return new Spider(component, new Point(position.x, position.y)); return null; } }