-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
31 lines (26 loc) · 858 Bytes
/
Block.java
File metadata and controls
31 lines (26 loc) · 858 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
import java.awt.*;
public class Block implements Constants {
// x and y are the coordinates of the top left corner of the block
public final int x;
public final int y;
public Color color = grey;
public Block(int x, int y) { // Constructor
this.x = x * SIZE;
this.y = y * SIZE;
}
// Draw the block
public void draw(Graphics g) {
g.setColor(this.color);
g.fillRect(this.x, this.y, SIZE, SIZE);
this.setColor(grey);
}
// Check if the player is colliding with the block
public boolean isColliding(float x, float y, int radius) {
return (this.x <= x + radius * 2 && x <= (this.x + SIZE) &&
this.y <= y + radius * 2 && y <= (this.y + SIZE));
}
// Getters and setters
public void setColor(Color color) {
this.color = color;
}
}