Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var balle_x, balle_y, dep_x, dep_y;
- var briques = [];
- function setup() {
- balle_x = Hasard(300) + 100;
- balle_y = Hasard(300) + 400;
- dep_x = 5 * Hasard(100) / 100 + 5; // un réel [0,3]
- dep_y = 5 * Hasard(100) / 100 + 5; // un réel [-3, 3]
- for (var x = 0; x <= 22; x++) {
- for (var y = 0; y <= 10; y++) {
- briques.push(true);
- }
- }
- }
- function draw() {
- Initialiser();
- CerclePlein(balle_x, balle_y, 20, 'bleu');
- for (var x = 0; x <= 22; x++) {
- for (var y = 0; y <= 10; y++) {
- if (briques[y * 22 + x]) {
- RectanglePlein(11 + 70 * x, 11 + 20 * y, 68, 18, 'red');
- }
- }
- }
- balle_x = balle_x + dep_x;
- balle_y = balle_y + dep_y;
- var cellX = Math.floor((balle_x - 11) / 70);
- var cellY = Math.floor((balle_y - 11) / 20);
- if (0 <= cellX && cellX <= 22 && 0 <= cellY && cellY <= 10 && briques[cellY * 22 + cellX]) {
- var ref_x = cellX * 70;
- var ref_y = cellY * 20;
- if (ref_x <= balle_x && balle_x <= ref_x + 1) {
- dep_x = -dep_x;
- } else {
- dep_y = -dep_y;
- }
- RectanglePlein(11 + 70 * cellX, 11 + 20 * cellY, 68, 18, 'purple');
- briques[cellY * 22 + cellX] = false;
- }
- if (balle_x > 1621 || balle_x < 0) {
- dep_x = -dep_x * 1.05;
- }
- if (balle_y < 0) {
- dep_y = -dep_y * 1.05;
- }
- if (balle_y > 840) {
- if (mouseX <= balle_x && balle_x <= mouseX + 200) {
- dep_y = -dep_y * 1.05;
- } else {
- balle_y = 500;
- balle_x = Hasard(300) + 100;
- }
- }
- RectanglePlein(mouseX, 850, 200, 10, 'green');
- if (balle_x > 10 && balle_x < 20 && balle_y > mouseY && balle_y < mouseY + 100) {
- dep_x = -dep_x;
- }
- }
- FrameRate = 30;
- Loop(-1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement