-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
29 lines (23 loc) · 929 Bytes
/
Copy pathBlock.java
File metadata and controls
29 lines (23 loc) · 929 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
public class Block extends GameObject {
public static final int SIZE = 32;
public Block (double x, double y) {
super( x*SIZE, y*SIZE, SIZE, SIZE, "Assets/tile-brick.png");
}
public boolean isTouchingX(GameObject gameObject, double ratio) {
double overlap = this.getWidth() * ratio;
return (Math.abs( this.getX()-gameObject.getX() ) < overlap);
}
public boolean isTouchingY(GameObject gameObject, double ratio) {
double overlap = this.getHeight() * ratio;
return (Math.abs( this.getY()-gameObject.getY() ) < overlap);
}
public boolean isTouchingY (GameObject player) {
return this.getY() <= player.getY() + player.getHeight() && player.getY() <= this.getY() + this.getHeight()/2;
}
public boolean isTouching(GameObject gameObject) {
return isTouchingY(gameObject) && isTouchingX(gameObject, 0.75);
}
public Block(double x, double y, String image) {
super( x*SIZE, y*SIZE, SIZE, SIZE, image);
}
}