import java.awt.*; import java.net.*; public class Pill { public static final int PROZAC = 1; public static final int PAXIL = 2; public static final int VALIUM = 3; public static final int RITALIN = 4; private int type; // Start in the middle and randomly create movement private double x = JavaPsychiatrist.width/2; private double y = JavaPsychiatrist.height/2; private double xMove = (Math.random() * 3)-1.5; private double yMove = (Math.random() * 3)-1.5; private static Image pillImages[] = new Image[4]; public Pill(int type) { this.type = type; } public int getType() { return type; } // Only the JP knows where it is being run from and can get images public static void imageInit(JavaPsychiatrist temp) { System.out.println(temp.getDocumentBase()); pillImages[0] = temp.getImage(temp.getDocumentBase(), "img_prozac.gif"); pillImages[1] = temp.getImage(temp.getDocumentBase(), "img_paxil.gif"); pillImages[2] = temp.getImage(temp.getDocumentBase(), "img_valium.gif"); pillImages[3] = temp.getImage(temp.getDocumentBase(), "img_ritalin.gif"); } // Display you while you're living and moving public void display(Graphics g) { Image tempImage = pillImages[type-1]; // Draw you g.drawImage(tempImage, (int)x+1, (int)y+1, null); //g.fillRect((int)x+20, (int)y+20, 2, 2); // If you hit the boundaries of the world, turn you back if (x+xMove > JavaPsychiatrist.width-18 || x+xMove < 0) xMove = -xMove; if (y+yMove > JavaPsychiatrist.height-18 || y+yMove < 0) yMove = -yMove; // Move you x+=xMove; y+=yMove; } public double getDistance(int x, int y) { return Math.sqrt(((this.x+20)-x)*((this.x+20)-x) + ((this.y+20)-y)*((this.y+20)-y)); } }