// Gecko Class // Gecko.java // Imports import java.awt.*; import java.applet.Applet; import java.util.*; public class Gecko extends DirectionalSprite { // Gecko action flags (extended sprite action flags, must be > 2) public static final int SA_ADDGILAMONSTER = 3, SA_ADDBULLET = 7; public static Image[][] image; public int shoot; public Point bulletdir; /** Constructor*/ public Gecko(Component comp) { super(comp, image, 0, 1, 0, new Point(42, 437), new Point(0, 0), 30, Sprite.BA_STOP, 0); } /** Initializes the images.*/ public static void initResources(Applet app, MediaTracker tracker, int id) { 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/Hero" + i + j + ".gif"); // "Res/Gecko" + i + j + ".gif"); tracker.addImage(image[i][j], id); } } } /** Changes the collision square to be smaller the the actual image.*/ protected void setCollision() { collision = new Rectangle(position.x + 6, position.y + 6, position.width - 6, position.height - 6); } /** This updates the status of the gecko*/ public BitSet update() { BitSet action = super.update(); // Toggle the frame and clear the velocity if (velocity.x != 0 || velocity.y != 0) { frame = 1 - frame; setVelocity(new Point(0, 0)); } // End if statement--reset velocity // Did he shoot? if (shoot >= 1) { /** This sets the flag to add a bullet.*/ shoot = 0; action.set(Sprite.SA_ADDSPRITE); action.set(Gecko.SA_ADDBULLET); } // End if statement--did he shoot? if (WarMan.level == 1) { if (position.y < 2) { /** Does he exit the room to the top?*/ // reposition the gecko position.y = 471; WarMan.roomchange = 1; if (WarMan.room == 5) WarMan.room = 2; else if (WarMan.room == 6) WarMan.room = 3; else if (WarMan.room == 7) WarMan.room = 4; else if (WarMan.room == 8) WarMan.room = 5; else if (WarMan.room == 9) WarMan.room = 6; } // End if statement--go to top? if (position.y > 472) { /** Does he exit the room to the bottom?*/ // reposition the gecko position.y = 3; WarMan.roomchange = 1; if (WarMan.room == 2) WarMan.room = 5; else if (WarMan.room == 3) WarMan.room = 6; else if (WarMan.room == 4) WarMan.room = 7; else if (WarMan.room == 5) WarMan.room = 8; else if (WarMan.room == 6) WarMan.room = 9; } // End if statement--go to bottom? if (position.x < 2) { /** Does he exit the room to the left?*/ // reposition the gecko position.x = 471; WarMan.roomchange = 1; if (WarMan.room == 1) WarMan.badcount = 0; else if (WarMan.room == 2) WarMan.room = 1; else if (WarMan.room == 3) WarMan.room = 2; else if (WarMan.room == 5) WarMan.room = 4; else if (WarMan.room == 8) WarMan.room = 7; else if (WarMan.room == 9) WarMan.room = 8; } // End if statement--go to left? if (position.x > 472) { /** Does he exit the room to the right?*/ // reposition the gecko position.x = 3; WarMan.roomchange = 1; if (WarMan.room == 1) WarMan.room = 2; else if (WarMan.room == 2) WarMan.room = 3; else if (WarMan.room == 4) WarMan.room = 5; else if (WarMan.room == 7) WarMan.room = 8; else if (WarMan.room == 8) WarMan.room = 9; } // End if statement--go to right? } // End if statement--if (WarMan.level == 1) return action; } // End update function protected Sprite addSprite(BitSet action) { /** This adds a bullet if the flag is set.*/ if (action.get(Gecko.SA_ADDBULLET)) { switch (direction) { case 0: return new Bullet(component, new Point((position.x + 1), position.y), new Point(0, -15)); case 1: return new Bullet(component, new Point((position.x + 5), position.y + 5), new Point(15, -15)); case 2: return new Bullet(component, new Point((position.x + 6), position.y), new Point(15, 0)); case 3: return new Bullet(component, new Point((position.x + 15), position.y + 3), new Point(15, 15)); case 4: return new Bullet(component, new Point((position.x + 22), position.y + 6), new Point(0, 15)); case 5: return new Bullet(component, new Point((position.x + 17), position.y + 17), new Point(-15, 15)); case 6: return new Bullet(component, new Point((position.x + 1), position.y + 22), new Point(-15, 0)); case 7: return new Bullet(component, new Point((position.x + 5), position.y + 17), new Point(-15, -15)); } // End switch statement } // End if statement return null; } // End function addSprite } // End class Gecko