Added the bricks (and improve the bouncing)

This commit is contained in:
2021-11-14 23:49:49 +01:00
parent 0f4a403edb
commit 7493713529
12 changed files with 303 additions and 111 deletions

39
Levels.js Normal file
View File

@ -0,0 +1,39 @@
class Levels {
load(lvl) {
let map = [];
switch (+lvl) {
case 1:
map = [].concat(
this.row(0, [1, 0, 1, 0, 0, 1, 0, 1]),
this.row(1, [1, 1, 1, 1, 1, 1, 1, 1]),
this.row(3, [0, 1, 1, 1, 1, 1, 1, 0]),
this.row(4, [1, 1, 1, 1, 1, 1, 1, 1])
);
break;
default:
map = [].concat(
this.row(0, [1, 1, 1, 1, 1, 1, 1, 1]),
this.row(1, [1, 1, 1, 1, 1, 1, 1, 1]),
this.row(2, [1, 1, 1, 1, 1, 1, 1, 1]),
this.row(3, [1, 1, 1, 1, 1, 1, 1, 1]),
this.row(4, [1, 1, 1, 1, 1, 1, 1, 1])
);
break;
}
return this.toBricks(map);
}
row(r, bricksTypes) {
let row = [];
for (var i = 0; i < bricksTypes.length; i++) row.push([bricksTypes[i], i, r]);
return row;
}
toBricks(map) {
let bricks = [];
map.forEach(b => {
if (b[0] > 0) bricks.push(new Brick(b[0], b[1], b[2]));
});
return bricks;
}
}