This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body { | |
| background: #222; | |
| color: #ddd; | |
| white-space: pre; | |
| font-family: monospace; | |
| } | |
| a { | |
| color: #6482c8; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <body> | |
| <canvas id="canvas" width="800" height="500"></canvas> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <body> | |
| <canvas id="canvas" width="800" height="500"></canvas> | |
| <script src="./pong.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let ctx, p1_y, p2_y, p1_points, p2_points | |
| const h=500, w=800, p_w=20, p_h=200, p1_x = 10, p2_x = w - p_w - 10 | |
| function setup(){ | |
| const canvas = document.getElementById("canvas") | |
| ctx = canvas.getContext("2d") | |
| // inicializa as posições y do p1 e do p2 para metade da tela | |
| p1_y = p2_y = (h / 2) - (p_h/2) | |
| // inicializa os pontos dos jogadores como 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let ball_y_orientation, ball_x_orientation, ball_x, ball_y | |
| function initBall(){ | |
| console.log(`${p1_points} VS ${p2_points}`) | |
| ball_y_orientation = Math.pow(2, Math.floor( Math.random() * 2 )+1) - 3 | |
| ball_x_orientation = Math.pow(2, Math.floor( Math.random() * 2 )+1) - 3 | |
| ball_x = w / 2 -10 | |
| ball_y = h / 2 -10 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let ctx, p1_y, p2_y, p1_points, p2_points | |
| let ball_y_orientation, ball_x_orientation, ball_x, ball_y | |
| const h=500, w=800, p_w=20, p_h=200, p1_x = 10, p2_x = w - p_w - 10 | |
| function setup(){ | |
| const canvas = document.getElementById("canvas") | |
| ctx = canvas.getContext("2d") | |
| // inicializa as posições y do p1 e do p2 para metade da tela | |
| p1_y = p2_y = (h / 2) - (p_h/2) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function drawRect(x,y,w,h,color="#fff"){ | |
| ctx.fillStyle = color | |
| ctx.fillRect(x,y,w,h) | |
| ctx.fillStyle = "#000" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function draw(){ | |
| // fundo | |
| drawRect(0,0,w,h,"#000") | |
| // player 1 | |
| drawRect(p1_x, p1_y, p_w, p_h) | |
| // player 2 | |
| drawRect(p2_x, p2_y, p_w, p_h) | |
| // barra lateral | |
| drawRect(w/2 -5,0,5,h) | |
| // bola |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let ctx, p1_y, p2_y, p1_points, p2_points | |
| let ball_y_orientation, ball_x_orientation, ball_x, ball_y | |
| const h=500, w=800, p_w=20, p_h=200, p1_x = 10, p2_x = w - p_w - 10 | |
| function setup(){ | |
| const canvas = document.getElementById("canvas") | |
| ctx = canvas.getContext("2d") | |
| // inicializa as posições y do p1 e do p2 para metade da tela | |
| p1_y = p2_y = (h / 2) - (p_h/2) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let p1_key, p2_key | |
| document.addEventListener("keydown",function(ev){ | |
| // keyCode 87 = w, keycode 83 = s | |
| if(ev.keyCode == 87 || ev.keyCode == 83){ | |
| p1_key = ev.keyCode | |
| } | |
| // keycode 38 = arrowUp, keycode 40 = arrowDown | |
| else if(ev.keyCode== 38 || ev.keyCode==40) | |
| p2_key = ev.keyCode | |
| }) |
OlderNewer