-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
25 lines (21 loc) · 752 Bytes
/
Block.java
File metadata and controls
25 lines (21 loc) · 752 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
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 = yellow;
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 + WIDTH / 4, this.y + SIZE / 2, SIZE, SIZE);
}
// 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));
}
}