Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var balle_x, balle_y, dep_x, dep_y;
  2.  
  3. var briques = [];
  4.  
  5. function setup() {
  6.   balle_x = Hasard(300) + 100;
  7.   balle_y = Hasard(300) + 400;
  8.   dep_x = 5 * Hasard(100) / 100 + 5; // un réel [0,3]
  9.   dep_y = 5 * Hasard(100) / 100 + 5; // un réel [-3, 3]
  10.   for (var x = 0; x <= 22; x++) {
  11.     for (var y = 0; y <= 10; y++) {
  12.       briques.push(true);
  13.     }
  14.   }
  15. }
  16.  
  17. function draw() {
  18.   Initialiser();
  19.   CerclePlein(balle_x, balle_y, 20, 'bleu');
  20.  
  21.   for (var x = 0; x <= 22; x++) {
  22.     for (var y = 0; y <= 10; y++) {
  23.       if (briques[y * 22 + x]) {
  24.         RectanglePlein(11 + 70 * x, 11 + 20 * y, 68, 18, 'red');
  25.       }
  26.     }
  27.   }
  28.  
  29.   balle_x = balle_x + dep_x;
  30.   balle_y = balle_y + dep_y;
  31.  
  32.   var cellX = Math.floor((balle_x - 11) / 70);
  33.   var cellY = Math.floor((balle_y - 11) / 20);
  34.  
  35.   if (0 <= cellX && cellX <= 22 && 0 <= cellY && cellY <= 10 && briques[cellY * 22 + cellX]) {
  36.     var ref_x = cellX * 70;
  37.     var ref_y = cellY * 20;
  38.     if (ref_x <= balle_x && balle_x <= ref_x + 1) {
  39.       dep_x = -dep_x;
  40.     } else {
  41.       dep_y = -dep_y;
  42.     }
  43.     RectanglePlein(11 + 70 * cellX, 11 + 20 * cellY, 68, 18, 'purple');
  44.     briques[cellY * 22 + cellX] = false;
  45.   }
  46.  
  47.   if (balle_x > 1621 || balle_x < 0) {
  48.     dep_x = -dep_x * 1.05;
  49.   }
  50.   if (balle_y < 0) {
  51.     dep_y = -dep_y * 1.05;
  52.   }
  53.   if (balle_y > 840) {
  54.     if (mouseX <= balle_x && balle_x <= mouseX + 200) {
  55.       dep_y = -dep_y * 1.05;
  56.     } else {
  57.       balle_y = 500;
  58.       balle_x = Hasard(300) + 100;
  59.     }
  60.   }
  61.  
  62.   RectanglePlein(mouseX, 850, 200, 10, 'green');
  63.   if (balle_x > 10 && balle_x < 20 && balle_y > mouseY && balle_y < mouseY + 100) {
  64.     dep_x = -dep_x;
  65.   }
  66.  
  67. }
  68.  
  69. FrameRate = 30;
  70. Loop(-1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement