import java.awt.Color; import java.awt.Component; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.Arc2D; /** * Contains model information and drawing routines for the Wedge. */ public class WedgeDude extends Player { public static final Color WEDGE_COLOR = new Color(40, 145, 240); public static final long MOUTH_TIME = 150L; public static final int RADIUS = 17; public static final double MAX_MOUTH_ANGLE = 125.0; public static final int DRAW_BOUNDARY = 4; /** Time mouth motion cycle started */ private long mouthReferenceTime = System.currentTimeMillis(); /** Degree to which the mouth is open */ private double mouthPhase; /** How dead WedgeDude is, i.e. what part of the death sequence to display */ private double die; public WedgeDude() { this(10, 14, Direction.WEST); } public WedgeDude(int gridX, int gridY, Direction direction) { super(gridX, gridY, direction); } public void die() { this.die = 0.025; } public synchronized void move(WedgeWorld world, Direction direction) { if (this.die == 0.0) super.move(world, direction); } public Rectangle getBoundingBox() { return new Rectangle(getPixelX() - RADIUS - 1, getPixelY() - RADIUS - 1, 2 * RADIUS + DRAW_BOUNDARY, 2 * RADIUS + DRAW_BOUNDARY); } public synchronized void updateModel() { super.updateModel(); // Handle mouth movement long now = System.currentTimeMillis(); long ticks = now - this.mouthReferenceTime; this.mouthPhase = (ticks % MOUTH_TIME) / (double)MOUTH_TIME; if (this.die > 0.0) this.die += 0.025; } public void draw(Graphics2D g2d, Component c) { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (this.die < 1.0) { double midAngle = getDirection().getAngle(); double mouthAngle = this.die == 0.0 ? this.mouthPhase * MAX_MOUTH_ANGLE : this.die * 360.0; Arc2D.Double wd = new Arc2D.Double(getPixelX() - RADIUS, getPixelY() - RADIUS, 2 * RADIUS, 2 * RADIUS, midAngle + mouthAngle / 2, 360.0 - mouthAngle, Arc2D.PIE); if (this.die == 0.0) g2d.setColor(WEDGE_COLOR); else g2d.setColor(Color.LIGHT_GRAY); g2d.fill(wd); } } }