Checking the levels
This commit is contained in:
		
							
								
								
									
										15
									
								
								Ball.js
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								Ball.js
									
									
									
									
									
								
							@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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); 
 | 
			
		||||
 | 
			
		||||
@ -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]),
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user