import java.awt.*; public class Person { // Create a new color for everyone private Color personColor = new Color((int)(Math.random()*255), (int)(Math.random()*255), (int)(Math.random()*255)); // Start in the middle and randomly create movement private double x = GodSim.width/2; private double y = GodSim.height/2; private double xMove = (Math.random() * 3)-1.5; private double yMove = (Math.random() * 3)-1.5; private Image personImage; public Person(Image personImage) { this.personImage = personImage; } // Are you on his good site? public boolean saved() { return (personColor.getRed() < 64); } // Display you while you're living and moving public boolean displayLive(Graphics g) { // Draw you g.setColor(personColor); g.fillRect((int)x, (int)y, 18, 18); g.drawImage(personImage, (int)x+1, (int)y+1, null); // If you hit the boundaries of the world, turn you back if (x+xMove > GodSim.width-18 || x+xMove < 0) xMove = -xMove; if (y+yMove > GodSim.height-18 || y+yMove < 0) yMove = -yMove; // Move you x+=xMove; y+=yMove; // Russian roulette - do you die? if (Math.random() > .999) return false; else return true; } // Display you after death (with some parameters) public void displayDead(Graphics g, int x, int y, int xoffset) { g.setColor(personColor); g.fillRect(x+xoffset, y, 18, 18); g.drawImage(personImage, x+1+xoffset, y+1, null); } }