-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrick.java
More file actions
50 lines (40 loc) · 758 Bytes
/
Brick.java
File metadata and controls
50 lines (40 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.awt.*;
public class Brick
{
public static final int WIDTH = 50;
public static final int HEIGHT = 25;
private int x, y;
public Brick(int x, int y)
{
this.x = x;
this.y = y;
}
public Brick move(int dx, int dy)
{
return new Brick(x+dx, y+dy);
}
public Rectangle getBounds()
{
return new Rectangle(x-WIDTH/2, y-HEIGHT/2, WIDTH, HEIGHT);
}
public boolean intersects(Ball b)
{
return b.getBounds().intersects(getBounds());
}
public Ball affect(Ball b)
{
Ball ret = b;
while(intersects(ret))
ret = ret.move(0, -1);
return ret;
}
public Point getLocation()
{
return new Point(x,y);
}
public void draw(Graphics g)
{
g.setColor(Color.RED);
g.fillRect(x-WIDTH/2, y-HEIGHT/2, WIDTH-1, HEIGHT-1);
}
}