Checking the levels

This commit is contained in:
2021-11-15 00:10:53 +01:00
parent 7493713529
commit 7cf0bfbdbd
3 changed files with 43 additions and 28 deletions

15
Ball.js
View File

@ -127,25 +127,28 @@ class Ball {
collide(x0, y0, x1, y1) { // 0 = hit Left/Right, 1 = hit Up/Down
let r = 20;
if (this.x>=x0 && this.x<=x1 && (this.y+this.size)>=y0 && (this.y+this.size)<y1) {
if (this.x >= x0 && this.x <= x1) {
if ((this.y + this.size) >= y0 && (this.y + this.size) < y1) {
this.bounceB(r);
return true;
}
if (this.x>=x0 && this.x<=x1 && (this.y-this.size)<=y1 && (this.y-this.size)>y0) {
if ((this.y - this.size) <= y1 && (this.y - this.size) > y0) {
this.bounceT(r);
return true;
}
}
if (this.y>=y0 && this.y<=y1 && (this.y+this.size)>=x0 && (this.y-this.size)<x1) {
if (this.y >= y0 && this.y <= y1) {
if ((this.x + this.size) >= x0 && (this.x + this.size) < x1) {
this.bounceR(r);
return true;
}
if (this.y>=y0 && this.y<=y1 && (this.y-this.size)<=x1 && (this.y-this.size)>x0) {
if ((this.x - this.size) <= x1 && (this.x - this.size) > x0) {
this.bounceL(r);
return true;
}
}
return false;
}

View File

@ -3,6 +3,9 @@ class GamePlay extends Board {
super(ctx, key);
this.controls = {
'KeyS': ()=>{
this.nextLevel(++this.level);
},
'KeyX': ()=>{
let b = new Ball();
b.update(this.ctx, this.bar.x + this.bar.w/2, this.bar.y);

View File

@ -10,6 +10,15 @@ class Levels {
this.row(4, [1, 1, 1, 1, 1, 1, 1, 1])
);
break;
case 2:
map = [].concat(
this.row(0, [1, 1, 1, 0, 1, 1, 0, 0]),
this.row(1, [0, 0, 1, 0, 1, 0, 1, 0]),
this.row(2, [0, 0, 1, 0, 1, 0, 1, 0]),
this.row(3, [1, 0, 1, 0, 1, 0, 1, 0]),
this.row(4, [0, 1, 1, 0, 1, 1, 0, 0])
);
break;
default:
map = [].concat(
this.row(0, [1, 1, 1, 1, 1, 1, 1, 1]),