diff --git a/breakout/breakout.html b/breakout/breakout.html index 66388a6..dc81081 100644 --- a/breakout/breakout.html +++ b/breakout/breakout.html @@ -27,6 +27,7 @@

CanvasBreak

+ diff --git a/breakout/breakout.js b/breakout/breakout.js index 0849e73..55f854b 100644 --- a/breakout/breakout.js +++ b/breakout/breakout.js @@ -25,6 +25,7 @@ var brick_height = 20; var brick_lines = 5; var brick_columns = screen_width / brick_width; + var bricks = brick_lines * Math.floor(brick_columns); //keys var KEY_LEFT = 37; @@ -41,9 +42,9 @@ var bricks_board = new Array(); - for(var i=0; i=0 && xspace<=9 && yspace>=0 && yspace<=4)]; } + var bricks_draw = function(column, line){ + ctx.fillStyle = "#5FF"; + ctx.strokeStyle = "black"; + ctx.lineWidth = 2; + ctx.beginPath(); + ctx.rect(column*brick_width, line*brick_height, brick_width, brick_height); + ctx.fill(); + ctx.stroke(); + + } var update = function(){ //clear the screen @@ -80,19 +91,23 @@ ctx.fill(); if(ball_moving){ - //alert(ball_y); bricks_point = bricks_collided(ball_x, ball_y); - if (bricks_point[0]>0 && bricks_point[0]<=10 && bricks_point[1]>0 && bricks_point[1]<=5 && (bricks_board[parseInt(bricks_point[1],10)-1][parseInt(bricks_point[0],10)]==1)){ - bricks_board[parseInt(bricks_point[1],10)-1][parseInt(bricks_point[0],10)] = 0; - - ball_ydirection *= -1; - } - else { - if(ball_x - ball_speed <= 0 || ball_x >= screen_width - ball_radius) - ball_xdirection *= -1; - if(ball_y - ball_speed <= ball_radius / 2 || bar_collided()) + if (bricks_point[2]==true) { + if (bricks_board[bricks_point[0]][bricks_point[1]]==1) { ball_ydirection *= -1; - } + bricks_board[bricks_point[0]][bricks_point[1]]=0; + bricks--; + if (bricks==0){ + alert('Parabés, voce ganhou!'); + ball_moving = false; + } + } + } + if(ball_x - ball_speed <= 0 || ball_x >= screen_width - ball_radius) + ball_xdirection *= -1; + if(ball_y - ball_speed <= ball_radius / 2 || bar_collided()) + ball_ydirection *= -1; + ball_x += ball_speed * ball_xdirection; ball_y += ball_speed * ball_ydirection; @@ -107,13 +122,10 @@ ctx.fillStyle = "#5FF"; ctx.strokeStyle = "black"; ctx.lineWidth = 2; - for(var i=0; i