-
Notifications
You must be signed in to change notification settings - Fork 0
/
Obstacle.pde
72 lines (57 loc) · 1.84 KB
/
Obstacle.pde
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
public abstract class Obstacle implements IDisplayable{
private Player player;
private PVector position;
private PVector size;
private PImage image;
private float damage;
private int bonus;
private PVector collisionThreshold;
private boolean passed = false;
public Obstacle(Player player, PVector position, PVector size, PImage image, float damage, int bonus){
this.player = player;
this.position = position;
this.size = size;
this.image = image;
this.damage = damage;
this.bonus = bonus;
this.collisionThreshold = new PVector();
}
public Player getPlayer(){
return this.player;
}
public PVector getPosition(){
return this.position;
}
public void setPosition(PVector position){
this.position = position;
}
public PVector getSize(){
return this.size;
}
public PImage getImage(){
return this.image;
}
public abstract void updatePosition();
public abstract void display();
protected boolean playerCheckCollision(){
if(player.getPosition().y < this.position.y && !passed){
player.addScore(this.bonus);
passed = true;
}
return(player.getPosition().x < position.x + size.x - collisionThreshold.x &&
player.getPosition().x + player.getSize().x > position.x + collisionThreshold.x &&
player.getPosition().y < position.y + size.y - collisionThreshold.y &&
player.getPosition().y + player.getSize().y > position.y + collisionThreshold.y);
}
protected abstract void collisionHandler();
public float getDamage(){
return this.damage;
}
public void setCollisionThreshold(float x, float y){
this.collisionThreshold.x = x;
this.collisionThreshold.y = y;
}
public boolean isPassed(){
return passed;
}
}