1 import java.awt.*;
2 import java.awt.geom.*;
3 import java.util.*;
4
5 /**
6
7 */
8 public class CarShape implements MoveableShape
9 {
10 /**
11
12 @param x
13 @param y
14 @param width
15 */
16 public CarShape(int x, int y, int width)
17 {
18 this.x = x;
19 this.y = y;
20 this.width = width;
21 }
22
23 public void move()
24 {
25 x++;
26 }
27
28 public void draw(Graphics2D g2)
29 {
30 Rectangle2D.Double body
31 = new Rectangle2D.Double(x, y + width / 6,
32 width - 1, width / 6);
33 Ellipse2D.Double frontTire
34 = new Ellipse2D.Double(x + width / 6, y + width / 3,
35 width / 6, width / 6);
36 Ellipse2D.Double rearTire
37 = new Ellipse2D.Double(x + width * 2 / 3, y + width / 3,
38 width / 6, width / 6);
39
40 //
41 Point2D.Double r1
42 = new Point2D.Double(x + width / 6, y + width / 6);
43 //
44 Point2D.Double r2
45 = new Point2D.Double(x + width / 3, y);
46 //
47 Point2D.Double r3
48 = new Point2D.Double(x + width * 2 / 3, y);
49 //
50 Point2D.Double r4
51 = new Point2D.Double(x + width * 5 / 6, y + width / 6);
52 Line2D.Double frontWindshield
53 = new Line2D.Double(r1, r2);
54 Line2D.Double roofTop
55 = new Line2D.Double(r2, r3);
56 Line2D.Double rearWindshield
57 = new Line2D.Double(r3, r4);
58
59 g2.draw(body);
60 g2.draw(frontTire);
61 g2.draw(rearTire);
62 g2.draw(frontWindshield);
63 g2.draw(roofTop);
64 g2.draw(rearWindshield);
65 }
66
67 private int x;
68 private int y;
69 private int width;
70 }