-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
193 lines (133 loc) · 2.92 KB
/
Player.java
File metadata and controls
193 lines (133 loc) · 2.92 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package sample;
/**
* Classe représentant l'entité de la personne qui joue (aka, la sorcière).
*
* La sorcière est représentée par un cercle.
*/
public class Player extends Entity {
private double timeSinceCollision= 0;
private double radius;
private double vy;
private double ay;
private int color=1;
private boolean invincible;
/**
* Constructeur de la classe Player.
*
* @param x Coordonnée x initiale du joueur
* @param y Coordonnée y initiale du joueur
* @param r Rayon du cercle représentant la sorcière
*/
public Player(double x, double y, double r) {
super(x, y);
this.radius = r;
this.vy = 0;
this.ay = -400;
this.renderer = new PlayerRenderer(this);
}
/**
* Retourne le rayon du cercle représentant la sorcière.
* @return en pixels
*/
public double getRadius() {
return radius;
}
/**
* Retourne la coordonnée x du joueur.
*
* @return un double
*/
public double getX() {
return x;
}
/**
* Retourne la coordonnée y du joueur.
*
* @return un double
*/
public double getY() {
return y;
}
/**
* Indique si le joueur est invincible.
*
* @return booleen: true si le joueur est invincible, sinon false
*/
public boolean getInvincible() {
return this.invincible;
}
/**
* Définit le joueur comme invincible.
*
* @param booleen invincible
*/
public void setInvincible(boolean invincible) {
this.invincible = invincible;
}
public void tick(double dt) {
// Mise à jour de la vitesse par rapport à l'axe y
vy += dt * ay;
// Mise à jour de la position
y += dt * vy;
// intervalle pour la vitesse
vy = Math.min(vy, 300);
vy = Math.max(vy, -300);
if (invincible) {
timeSinceCollision += dt;
// Si le temps écoulé dépasse 3 secondes, l'invincibilité prend fin
if (timeSinceCollision > 3) {
invincible = false;
timeSinceCollision = 0;
}
}
}
/**
* Renvoie la couleur de l'obstacle.
*
* @return int
*/
public int getColor() {
return color;
}
/**
* Remplace la couleur actuelle par une nouvelle couleur aléatoire
*/
public void randomizeColor() {
int newColor;
do {
newColor = (int) (Math.random() * 4);
} while (newColor == this.color);
this.color = newColor;
}
/**
* Fait sauter la sorcière
*/
public void jump() {
vy = Math.max(vy, 0);
vy += 200;
}
/**
* Définit la coordonnée y de l'objet.
*
* @param y La nouvelle coordonnée y de l'objet.
*/
public void setY(double y) {
this.y = y;
}
/**
*Retourne la largeur de la sorcière.
*
* @return width double: la largeur de la sorcière ( cercle représentant la sorcière)
*/
public double getWidth() {
return this.getRadius() * 2;
}
/**
*Retourne la hauteur de la sorcière.
*
* @return hright double: la largeur de la sorcière ( cercle représentant la sorcière)
*/
public double getHeight() {
return this.getRadius() * 2;
}
}