Bonjour à tous ! Voilà je suis un petit féru d'informatique et de programmation depuis mes 9 ans mais voilà j'ai un problème avec mon jeu de billard. La balle ne s'arrête pas comme je veux et elle fait des "Arrondis". J'ai besoin de votre aide

Le code

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
//VARIABLES
float y = 0;
float w = 150;
float h = 40;
float x = width - 100;
 
float hauteur;
float largeur;
 
 
boolean view = false;
boolean clicked = false;
 
boolean return_to_menu_boolean = false;
 
float ballSize = 25;
float ballSpeed = 5;
 
//BALL SETTINGS
PVector ball;
 
//Holl settings
PVector trou1;
PVector trou2;
PVector trou3;
PVector trou4;
PVector trou5;
PVector trou6;
int holeSize = 15;
 
//Settings balls
PVector vell;
boolean shot_line;
float powerShoot;
 
//Table settings 
float xt;
float yt;
 
//cursor settings
int xBox = 10;
int yBox = 200;
 
int yCursor = yBox / 1 + yBox - 5;
 
//variables options panel
boolean show_options_panel = false;
 
String ActualLanguage = "Français";
 
boolean click = false;
 
boolean show_language_options_dropdown = false;
 
int maxSpeedX = 25;
int maxSpeedY = 25;
 
void setup(){
 
 fullScreen();
 
 //PAGE
 background(255);
 stroke(0);
 noFill();
 
 hauteur = height;
 largeur = width;
 
 xt = largeur * 5 / 7;
 yt = hauteur * 5 / 7;
 
 reset();
 smooth();
}
 
void draw(){
 
  if(return_to_menu_boolean == false){
  menu();
  table();
  }else{
    return_to_menu();
  }
  ball_system();
  if(shot_line == true){
  }else{
   if(vell.x == 0 && vell.y == 0){
     println("Ball stop");
     shot_line = true; 
 }
   stoping_ball(); 
  }
 
  if(show_options_panel == true){
   show_options();
   shot_line = false;
  }
 
  if(show_language_options_dropdown == true){
    show_language_options();
  }
 
  fill(0);
  text("Vell x:" + vell.x, 500, 850);
  text("Vell y:" + vell.y, 650, 850);
}
 
void table(){
  fill(79, 134, 58);
  //tapis vert
  rect(largeur / 2 - xt /2, hauteur / 2 - yt / 2, xt, yt, 30);
  //bordure du tap
  noFill();
  stroke(135, 135, 135  );
  strokeWeight(15);
  rect(largeur / 2 - xt /2, hauteur / 2 - yt / 2, xt, yt, 30);
 
  //TROUS DU TAPIS
  strokeWeight(15);
  fill(0);
  //trous du milieu
  ellipse(largeur / 2, hauteur / 7 , 50, 50);
  ellipse(largeur / 2, hauteur * 6 / 7, 50, 50);
  //trous à gauche
  ellipse(largeur / 7 + 8, hauteur / 7 + 10 * 2, 50, 50);
  ellipse(largeur  / 7 + 8, hauteur * 6 / 7 - 10 * 2, 50, 50);
  //trous à droite
  ellipse(largeur * 6 / 7 - 8, hauteur / 7 + 10 * 2, 50, 50);
  fill(255);
  ellipse(largeur * 6 / 7 - 8, hauteur * 6 / 7 - 10 * 2  , 50, 50);
  //ligne du milieu du tapis
  strokeWeight(3);
  stroke(255);
  line(largeur / 2 + 290, height / 2 - 315, largeur / 2 + 290, height / 2 + 315);
  //arc du cercle du milieu du tapis
  fill(79, 134, 58);
  arc(largeur / 2 + 292, height / 2, 450, 450, -1.57, PI - 1.57);
  //point au centre
  fill(255);
  ellipse(largeur / 2 + 312, height / 2, 5, 5);
 
  //arc de cercle haut à droite
  fill(79, 134, 58);
  stroke(79, 134, 58);
  arc(largeur * 6 / 7 - 8, hauteur / 7 + 4 * 2, 90, 98, 1.55, PI);
  fill(0);
  stroke(0);
  ellipse(largeur * 6 / 7 - 8, hauteur / 7 + 10 * 2, 35,35);
 
  //arc de cercle milieu en haut
  fill(79, 134, 58);
  stroke(79, 134, 58);
  arc(largeur / 2, hauteur / 7 + 4 * 2, 90, 98, 0, PI);
  fill(0);
  stroke(0);
  ellipse(largeur / 2, hauteur / 7 , 35,35);
 
  //arc de cercle milieu en haut
  fill(79, 134, 58);
  stroke(79, 134, 58);
  arc(largeur / 2, hauteur * 6 / 7  - 8, 90, 98, -3.14, 0.01);
  fill(0);
  stroke(0);
  ellipse(largeur / 2, hauteur * 6 / 7 , 35,35);
 
  //arc de cercle bas à droite
  fill(79, 134, 58);
  stroke(79, 134, 58);
  arc(largeur * 6 / 7 - 8, hauteur * 6 / 7 - 10 * 2 + 10, 90, 98, 3.092, 4.7099977);
  fill(0);
  stroke(0);
  ellipse(largeur * 6 / 7 - 8, hauteur * 6 / 7 - 10 * 2, 35,35);
 
  //arc de cercle haut à gauche
  fill(79, 134, 58);
  stroke(79, 134, 58);
  arc(largeur / 7 + 8, hauteur / 7 + 8, 90, 98, 0, PI / 2);
  fill(0);
  stroke(0);
  ellipse(largeur / 7 + 8, hauteur / 7 + 20, 35,35);
 
  //arc de cercle bas à gauche
  fill(79, 134, 58);
  stroke(79, 134, 58);
  arc(largeur / 7 + 7, hauteur * 6 / 7 - 4 * 2, 90, 98, -1.55, 0);
  fill(0);
  stroke(0);
  ellipse(largeur / 7 + 7, hauteur * 6 / 7 - 10 * 2, 35,35);
}
 
void menu(){
 background(206, 220, 173);
 noStroke();
 fill(79, 134, 58);
 rect(x,y,w,h);
 textSize(15);
 fill(255);
 text("Menu", 45, 25);
 fill(255);
 if(mousePressed && clicked == false){
   clicked = true;
  if(mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h){
   view = !view;
   //click sur le bouton menu
   shot_line = false;
   println("Menu");
   delay(200);
  }
  if(view){//detection si le menu est déroulé
  if(mouseX>x && mouseX <x+w && mouseY>y+40 && mouseY <y+h+40){
    show_options_panel = true;
    println("Options");
    delay(200);
  }
 
  if(mouseX>x && mouseX <x+w && mouseY>y+80 && mouseY <y+h+80){
    return_to_menu_boolean = true;
    println("Retour");
    delay(200);
  }
  }
 
  if(mouseX > (width / 4) * 3 - 20 && mouseX < (width / 4) * 3 + 20 && mouseY > height / 4 && mouseY < height / 4 + 20){
    show_options_panel = false;
    show_language_options_dropdown = false;
   }else if(mouseX > width / 4 + 300 && mouseX < width / 4 + 350 && mouseY < height / 4 + 75 && mouseY > height / 4 + 50){
     if(click == false){
     click = true;
     show_language_options_dropdown = !show_language_options_dropdown;
     click = false;
     delay(100);
     }
   }else if(mouseX > width / 4 + 50 && mouseX < width / 4 + 350 && mouseY < height / 4 + 105 && mouseY > height / 4 + 80 && show_language_options_dropdown == true){//options
     if(ActualLanguage == "Français"){
     ActualLanguage = "English";
     }else{
       ActualLanguage = "Français";
     }
     show_language_options_dropdown = false;
   }else if(mouseX > width / 4 + 450 && mouseX < width / 4 + 600 && mouseY > height / 4 + 400 && mouseY < height / 4 + 425){//sauvegarder
     show_options_panel = false;
     show_language_options_dropdown = false;
     //ecriture fichier csv
   }else if(mouseX > width / 4 + 625 && mouseX < width / 4 + 775 && mouseY > height / 4 + 400 && mouseY < height / 4 + 425){//annuler
   println("Annuler");
     show_options_panel = false;
     show_language_options_dropdown = false;
   }
 
  clicked = false;
 }
 
 if(view){//affiche dropdown du menu
   fill(79, 134, 58);
   rect(x,y+ 40,w,h);
   fill(255);
   text("Options", 45, 25+40);
 
   fill(79, 134, 58);
   rect(x,y+ 80,w,h);
   fill(255);
   text("Retour", 45, 25+80);
 }
}
 
void return_to_menu(){
 
}
 
void placing_ball(){
}
 
 
void reset() {
  ball =  new PVector(largeur / 2 + 312, height / 2, 0);
  trou1 = new PVector(largeur / 2, hauteur / 7,  0);
  trou2 = new PVector(largeur / 2, hauteur * 6 / 7,  0);
  trou3 = new PVector(largeur / 7 + 8, hauteur / 7 + 10 * 2,  0);
  trou4 = new PVector(largeur  / 7 + 8, hauteur * 6 / 7 - 10 * 2,  0);
  trou5 = new PVector(largeur * 6 / 7 - 8, hauteur / 7 + 10 * 2,  0);
  trou6 = new PVector(largeur * 6 / 7 - 8, hauteur * 6 / 7 - 10 * 2,  0);
  vell = new PVector( 0, 0, 0);
  shot_line = true;
}
 
void ball_system(){
  ball.x+=vell.x;
  ball.y+=vell.y;
  if(shot_line){
    stroke(255, 255, 0);
    text("Mouse X:" + mouseX, 500, 100);
    text("Mouse Y:" + mouseY, 750, 100);
    line(mouseX, mouseY, ball.x, ball.y);
  }
  stroke(0, 64, 0);
  fill(0);
  stroke(0);
  fill(255);
  ellipse(ball.x, ball.y, 20, 20);
  if (dist(ball.x, ball.y, trou1.x, trou1.y)<holeSize) {
    println("POINT!");
    reset();
  }else if(dist(ball.x, ball.y, trou2.x, trou2.y)<holeSize){
   println("POINT!");
    reset(); 
  }else if(dist(ball.x, ball.y, trou3.x, trou3.y)<holeSize){
   println("POINT!");
    reset(); 
  }else if(dist(ball.x, ball.y, trou4.x, trou4.y)<holeSize){
   println("POINT!");
    reset(); 
  }else if(dist(ball.x, ball.y, trou5.x, trou5.y)<holeSize){
   println("POINT!");
    reset(); 
  }else if(dist(ball.x, ball.y, trou6.x, trou6.y)<holeSize){
   println("POINT!");
    reset(); 
  }else if (ball.x<250||ball.x>1355) {
    vell.x *= -1;
  }else if(ball.y<145||ball.y>755){
    vell.y *= -1;
  }
}
 
void mousePressed() {
  if(shot_line == true){
  shot_line = false;
 
  vell.x = 0.1 * (ball.x-mouseX);
  vell.y = 0.1 * (ball.y-mouseY);
 
  if(vell.x > maxSpeedX){
    vell.x = maxSpeedX;
  }
 
  if(vell.y > maxSpeedY){
    vell.y = maxSpeedY;
  }
 
  if(vell.x < -maxSpeedX){
    vell.x = -maxSpeedX;
  }
 
  if(vell.y < -maxSpeedY){
    vell.y = -maxSpeedY;
  }
 
  }
}
 
 
void stoping_ball(){
  double CoeffFrictionX;
  double CoeffFrictionY;
 
 if(vell.x > -0.1 && vell.x < 0.1 && vell.y > -0.1 && vell.y < 0.1){
   vell.x = 0;
   vell.y = 0;
   println("Done " + vell.x + vell.y);
 }
 
 
  if(vell.x > 0 && vell.x != 0){
    CoeffFrictionX = 0.1;
    vell.x-= CoeffFrictionX;
    println("Vell x " + vell.x);
  }else if(vell.x < 0 && vell.x != 0){
    CoeffFrictionX = -0.1;
    vell.x-= CoeffFrictionX;
    println("Vell x " + vell.x);
  }
 
  if(vell.y > 0 && vell.y != 0){
    CoeffFrictionY = 0.1;
    vell.y-= CoeffFrictionY;
    println("Vell y " + vell.y);
  }else if(vell.y < 0 && vell.y != 0){
    CoeffFrictionY = -0.1;
    vell.y -= CoeffFrictionY;
    println("Vell y " + vell.y);
  }
}
 
void show_options(){
   //fond de la page options et carrée pour fermer
   textSize(20);
   fill(255);
   rect(width / 4, height / 4, width / 2, height / 2); 
   fill(255,0,0);
   rect(width / 4 * 3 - 20 , height / 4, 20, 20);
   fill(0);
   text("X", width / 4 * 3 - 15 , height / 4 + 17); 
 
   //langue
   fill(155);
   rect(width / 4 + 50, height / 4 + 50,  300, 30);
   fill(0);
   text(ActualLanguage, width / 4 + 50, height / 4 + 55,  300, 30);
   stroke(0);
   fill(155);
   rect(width / 4 + 300, height / 4 + 50,  50, 30);
   fill(0);
   text("▼", width / 4 + 315, height / 4 + 75);
   fill(155);
   rect(width / 4 + 450, height / 4 + 400,  150, 30);
   fill(0);
   text("Sauvegarder", width / 4 + 465, height / 4 + 405,  150, 30);
   fill(155);
   rect(width / 4 + 625, height / 4 + 400,  150, 30);
   fill(0);
   text("Annuler", width / 4 + 660, height / 4 + 405,  150, 30);
}
 
void show_language_options(){
    fill(155);
    rect(width / 4 + 50, height / 4 + 80,  300, 30);
    fill(0);
    if(ActualLanguage == "Français"){
    text("English", width / 4 + 50, height / 4 + 105);
    }else{
      text("Français", width / 4 + 50, height / 4 + 105);
    }
}
Merci de votre aide !