-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.java
38 lines (33 loc) · 915 Bytes
/
Block.java
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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
public class Block {
// instance variables
private int width, height;
private int xPos, yPos;
private Color color;
private int pointValue;
private Breakout breakout;
// constructor
public Block(Breakout out,int x, int y, Color c, int pv) {
width = 50;
height = 30;
xPos = x;
yPos = y;
color = c;
pointValue = pv;
breakout = out;
}
// methods
public void paint(Graphics g) {
g.setColor(color);
g.fillRect(xPos, yPos, width, height);
}
public Rectangle getBounds() {
return new Rectangle(xPos, yPos, width, height);
}
public boolean collision() {
return this.getBounds().intersects(breakout.getBall().getBounds());
// is the paddle being intersected with the ball
}
}