-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerticalBar.java
More file actions
107 lines (78 loc) · 2.31 KB
/
VerticalBar.java
File metadata and controls
107 lines (78 loc) · 2.31 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package sample;
import javafx.animation.AnimationTimer;
public class VerticalBar extends Obstacle{
private double dt;
private double width, height, vx;
public VerticalBar(double x, double y, double width, double height, double vx) {
super(x,y); // mêmes coordonnées que ceux de la classe mère
this.width= width;
this.height= height;
this.vx= vx; // vitesse par rapport à l'axe x
this.color= 1;
this.renderer = new VerticalBarRenderer(this); // rep graphique de VerticalBar
}
/**
* Méthode qui vérifie s'il y a intersection entre la sorcière et VerticalBar en
* comparant leurs coordonnées
* @param player la sorcière
* @return booleen : true si il y'a intersection sinon false
*/
@Override
public boolean intersects(Player player) {
return this.color != player.getColor()
&& player.getX() + player.getRadius() < this.getX() + this.getWidth() / 2
&& player.getX() + player.getRadius()> this.getX() - this.getWidth() / 2
&& player.getY() + player.getRadius()< this.getY() + this.getHeight() / 2
&& player.getY() + player.getRadius()> this.getY() - this.getHeight() / 2;
}
/**
* getter pour obtenir la largeur de l'obstacle
* @return x double :largeur de VerticalBar
*/
@Override
public double getWidth() {
return width;
}
/**
* getter pour obtenir la hauteur de l'obstacle
* @return x double :hauteur de Verticalbar
*/
@Override
public double getHeight() {
return height;
}
/**
* getter pour obtenir la couleur actuelle l'obstacle
* @return color int: couleur actuelle
*/
public int getColor() {
return color;
}
/**
* getter pour obtenir la coordonnée x de l'obstacle
* @return x double :la coorodnnée x
*/
public double getX() {
return x;
}
/**
* getter pour obtenir la coordonnée y de l'obstacle
* @return y double :la coorodnnée y
*/
public double getY() {
return y;
}
/**
* Change la position de VerticalBar à chaque dt
*
* @param dt en secondes (double) :Le temps écoulé depuis la dernière mise à jour.
*/
@Override
public void tick(double dt) {
double newX = x + dt*vx;
if (newX + getWidth() / 2 > ColorsWitch.WIDTH || newX - getWidth() / 2 < 0) {
vx *= -1;
}
else { x = newX; }
}
}