Added bricks type 2 and 3
This commit is contained in:
		
							
								
								
									
										22
									
								
								Bricks.js
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								Bricks.js
									
									
									
									
									
								
							@ -12,17 +12,33 @@ class Brick {
 | 
			
		||||
        this.x = (this.w + this.hspace) * column;
 | 
			
		||||
        this.y = 80 + (this.h + this.vspace) * row;
 | 
			
		||||
 | 
			
		||||
        this.alive = true;
 | 
			
		||||
        switch (type) {
 | 
			
		||||
            case 2: this.lives = 2; break;
 | 
			
		||||
            case 3: this.lives = 3; break;
 | 
			
		||||
            default: this.lives = 1; break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    crack() {
 | 
			
		||||
        this.lives--;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    update(ctx) {
 | 
			
		||||
        if (!this.alive) return false;
 | 
			
		||||
        if (this.lives == 0) return false;
 | 
			
		||||
 | 
			
		||||
        switch(this.type) {
 | 
			
		||||
        switch (this.lives) {
 | 
			
		||||
            case 1:
 | 
			
		||||
                ctx.fillStyle = 'blue';
 | 
			
		||||
                ctx.fillRect(this.x + 1, this.y, this.w, this.h);
 | 
			
		||||
                break;
 | 
			
		||||
            case 2:
 | 
			
		||||
                ctx.fillStyle = 'orange';
 | 
			
		||||
                ctx.fillRect(this.x + 1, this.y, this.w, this.h);
 | 
			
		||||
                break;
 | 
			
		||||
            case 3:
 | 
			
		||||
                ctx.fillStyle = 'red';
 | 
			
		||||
                ctx.fillRect(this.x + 1, this.y, this.w, this.h);
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -53,10 +53,10 @@ class GamePlay extends Board {
 | 
			
		||||
                    let r = ball.update(this.ctx, this.bar.x + this.bar.w/2, this.bar.y);
 | 
			
		||||
                    ball.collide( this.bar.x, this.bar.y, this.bar.x + this.bar.w, this.bar.y + this.bar.h );
 | 
			
		||||
                    this.bricks.forEach(b=>{
 | 
			
		||||
                                            if(b.alive){
 | 
			
		||||
                                            if(b.lives>0){
 | 
			
		||||
                                                if ( ball.collide(b.x,b.y,b.x+b.w,b.y+b.h) ) {
 | 
			
		||||
                                                    this.score.add(1);
 | 
			
		||||
                                                    b.alive = false;
 | 
			
		||||
                                                    b.crack();
 | 
			
		||||
                                                }
 | 
			
		||||
                                                
 | 
			
		||||
                                        }});
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								Levels.js
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								Levels.js
									
									
									
									
									
								
							@ -12,20 +12,20 @@ class Levels {
 | 
			
		||||
                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])
 | 
			
		||||
                                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, 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])
 | 
			
		||||
                                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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user