// Scorpion Class // Scorpion.java // Imports import java.awt.*; import java.applet.Applet; import java.util.*; public class Scorpion extends Sprite { public static Image[][] image; private static Random rand = new Random(System.currentTimeMillis()); public Scorpion(Component comp, int dir, int speedInc) { super(comp, image[dir], 0, 1, 1, new Point((dir == 0) ? (comp.size().width - image[dir][0].getWidth(comp)) : 0, 60 + Math.abs(rand.nextInt() % 5) * 44), new Point((dir == 0) ? (-speedInc) : (speedInc), 0), 30, Sprite.BA_DIE); } public static void initResources(Applet app, MediaTracker tracker, int id) { image = new Image[2][2]; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) { image[i][j] = app.getImage(app.getCodeBase(), "Res/Scorp" + i + j + ".gif"); tracker.addImage(image[i][j], id); } } protected void setCollision() { collision = new Rectangle(position.x + 3, position.y + 3, position.width - 6, position.height - 6); } public BitSet update() { // See if the scorpion escaped BitSet action = super.update(); if (action.get(Sprite.SA_KILL)) WarMan.scorpioncount--; return action; } }