From 85c2b5a1c916a78c3f0508169384f8de7b78e024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81sar=20Medeiros?= Date: Tue, 7 Feb 2012 10:28:44 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Implementado=20a=20identifica=C3=A7=C3=A3o?= =?UTF-8?q?=20de=20quando=20todos=20os=20blocos=20foram=20destru=C3=ADdos.?= =?UTF-8?q?=20Corrigido=20o=20controle=20de=20colis=C3=A3o=20com=20os=20br?= =?UTF-8?q?icks.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- breakout/breakout.html | 6 +++- breakout/breakout.js | 62 +++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/breakout/breakout.html b/breakout/breakout.html index 66388a6..eeb4343 100644 --- a/breakout/breakout.html +++ b/breakout/breakout.html @@ -5,7 +5,7 @@ body { background: #000; } - h1 { + h1, label{ color: #FFF; font-size: 25px; text-transform: uppercase; @@ -24,9 +24,13 @@

CanvasBreak

+ + +
+ diff --git a/breakout/breakout.js b/breakout/breakout.js index 0849e73..0a9abe5 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; + if (valido==true){ + var elebi = document.getElementById('coordX'); + elebi.value=bricks; + //alert("colidi"); + }*/ + return [Math.floor(xspace), Math.floor(yspace), (xspace>=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 +97,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 +128,10 @@ ctx.fillStyle = "#5FF"; ctx.strokeStyle = "black"; ctx.lineWidth = 2; - for(var i=0; i Date: Wed, 15 Feb 2012 20:31:54 -0300 Subject: [PATCH 2/2] justes no HTML e JS --- breakout/breakout.html | 5 +---- breakout/breakout.js | 8 +------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/breakout/breakout.html b/breakout/breakout.html index eeb4343..dc81081 100644 --- a/breakout/breakout.html +++ b/breakout/breakout.html @@ -5,7 +5,7 @@ body { background: #000; } - h1, label{ + h1 { color: #FFF; font-size: 25px; text-transform: uppercase; @@ -24,9 +24,6 @@

CanvasBreak

- - -
diff --git a/breakout/breakout.js b/breakout/breakout.js index 0a9abe5..55f854b 100644 --- a/breakout/breakout.js +++ b/breakout/breakout.js @@ -60,13 +60,7 @@ var xspace = Math.floor((ball_x + ball_radius)/brick_width); var yspace = Math.floor((ball_y - ball_radius - ball_speed)/brick_height); -/* var valido = xspace>=0 && xspace<=9 && yspace>=0 && yspace<=4; - if (valido==true){ - var elebi = document.getElementById('coordX'); - elebi.value=bricks; - //alert("colidi"); - }*/ - return [Math.floor(xspace), Math.floor(yspace), (xspace>=0 && xspace<=9 && yspace>=0 && yspace<=4)]; + return [xspace, yspace, (xspace>=0 && xspace<=9 && yspace>=0 && yspace<=4)]; } var bricks_draw = function(column, line){