changed ball and bar for a sprite
This commit is contained in:
48
assets/js/Levels.js
Normal file
48
assets/js/Levels.js
Normal file
@ -0,0 +1,48 @@
|
||||
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;
|
||||
case 2:
|
||||
map = [].concat(
|
||||
this.row(0, [3, 3, 3, 0, 3, 3, 0, 0]),
|
||||
this.row(1, [0, 0, 3, 0, 3, 0, 3, 0]),
|
||||
this.row(2, [0, 0, 3, 0, 3, 0, 3, 0]),
|
||||
this.row(3, [3, 0, 3, 0, 3, 0, 3, 0]),
|
||||
this.row(4, [0, 3, 3, 0, 3, 3, 0, 0])
|
||||
);
|
||||
break;
|
||||
default:
|
||||
map = [].concat(
|
||||
this.row(0, [1, 3, 1, 3, 1, 3, 1, 3]),
|
||||
this.row(1, [3, 1, 3, 1, 3, 1, 3, 1]),
|
||||
this.row(2, [1, 3, 1, 3, 1, 3, 1, 3]),
|
||||
this.row(3, [3, 1, 3, 1, 3, 1, 3, 1]),
|
||||
this.row(4, [1, 3, 1, 3, 1, 3, 1, 3])
|
||||
);
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user