GRA DLA JEDNEJ OSOBY -->pasek w prawo/<--pasek w lewo DO WSTAWIENIA TEGO ELEMENTU STOSUJE SIE PONIZSZY KOD <style type="text/css">body, a, a:hover {cursor: url(http://profilki.pl/files/cur/1041.png) 0 0, default;}</style> <center> <script type="text/javascript"> // zmienne Globalne. var ballX = 150; var ballY = 150; var ballDX = 2; var ballDY = 4; var boardX = 300; var boardY = 300; var racquetX= 150; var racquetH= 10; var racquetD = boardY - racquetH; var racquetW = 150; var canvas; var ctx; var gameLoop; var titleFontSize = "bold 24px Georgia"; var contentFontSize = "normal 12px Arial"; function drawGameCanvas() { canvas = document.getElementById("gameBoard"); if (canvas.getContext) { ctx = canvas.getContext("2d"); gameLoop = setInterval(drawBall, 16); window.addEventListener('keydown', whatKey, true); } } function drawBall() { // wyczyść okienko z gra ctx.clearRect(0, 0, boardX, boardY); // wypelnij okienko z gra ctx.fillStyle = "black"; ctx.beginPath(); ctx.rect(0, 0, boardX, boardY); ctx.closePath(); ctx.fill(); // rysuj pilke ctx.fillStyle = "yellow"; ctx.beginPath(); ctx.arc(ballX, ballY, 15, 0, Math.PI * 2, true); ctx.closePath(); ctx.fill(); // rysuj belke ctx.fillStyle = "yellow"; ctx.beginPath(); ctx.rect(racquetX, racquetD, racquetW, racquetH); ctx.closePath(); ctx.fill(); // zmiana pozycji pilki ballX += ballDX; ballY += ballDY; // odpijanie pilki od krawedzi prawej i lewej if (ballX + ballDX > boardX - 15 || ballX + ballDX < 15) ballDX = -ballDX; // Odbicie piłki od gory okna if (ballY + ballDY < 15) ballDY = -ballDY; // Gdy piłka uderza o dolna krawędz, sprawdz czy dotknela belki else if (ballY + ballDY > boardY - 15) { // gdy dotknela belki, odbij ja if (ballX > racquetX && ballX < racquetX + racquetW) ballDY = -ballDY; // inaczej gra jest skonczona else { clearInterval(gameLoop); ctx.font = titleFontSize; ctx.fillStyle = "white"; ctx.fillText("Przegrales", 90, 130); ctx.font = contentFontSize; ctx.fillStyle = "white"; ctx.fillText("Odswiez strone, by powtorzyc", 70, 150); } } } function whatKey(evt) { switch (evt.keyCode) { case 37: racquetX = racquetX - 20; if (racquetX < 0) racquetX = 0; break; case 39: racquetX = racquetX + 20; if (racquetX > boardX - racquetW) racquetX = boardX - racquetW; break; } } </script> </head> <body onLoad="drawGameCanvas()"> <div id="center"> <canvas id="gameBoard" width="300" height="300"></canvas> </div> </body> </center> HOME
-->pasek w prawo/<--pasek w lewo DO WSTAWIENIA TEGO ELEMENTU STOSUJE SIE PONIZSZY KOD <style type="text/css">body, a, a:hover {cursor: url(http://profilki.pl/files/cur/1041.png) 0 0, default;}</style> <center> <script type="text/javascript"> // zmienne Globalne. var ballX = 150; var ballY = 150; var ballDX = 2; var ballDY = 4; var boardX = 300; var boardY = 300; var racquetX= 150; var racquetH= 10; var racquetD = boardY - racquetH; var racquetW = 150; var canvas; var ctx; var gameLoop; var titleFontSize = "bold 24px Georgia"; var contentFontSize = "normal 12px Arial"; function drawGameCanvas() { canvas = document.getElementById("gameBoard"); if (canvas.getContext) { ctx = canvas.getContext("2d"); gameLoop = setInterval(drawBall, 16); window.addEventListener('keydown', whatKey, true); } } function drawBall() { // wyczyść okienko z gra ctx.clearRect(0, 0, boardX, boardY); // wypelnij okienko z gra ctx.fillStyle = "black"; ctx.beginPath(); ctx.rect(0, 0, boardX, boardY); ctx.closePath(); ctx.fill(); // rysuj pilke ctx.fillStyle = "yellow"; ctx.beginPath(); ctx.arc(ballX, ballY, 15, 0, Math.PI * 2, true); ctx.closePath(); ctx.fill(); // rysuj belke ctx.fillStyle = "yellow"; ctx.beginPath(); ctx.rect(racquetX, racquetD, racquetW, racquetH); ctx.closePath(); ctx.fill(); // zmiana pozycji pilki ballX += ballDX; ballY += ballDY; // odpijanie pilki od krawedzi prawej i lewej if (ballX + ballDX > boardX - 15 || ballX + ballDX < 15) ballDX = -ballDX; // Odbicie piłki od gory okna if (ballY + ballDY < 15) ballDY = -ballDY; // Gdy piłka uderza o dolna krawędz, sprawdz czy dotknela belki else if (ballY + ballDY > boardY - 15) { // gdy dotknela belki, odbij ja if (ballX > racquetX && ballX < racquetX + racquetW) ballDY = -ballDY; // inaczej gra jest skonczona else { clearInterval(gameLoop); ctx.font = titleFontSize; ctx.fillStyle = "white"; ctx.fillText("Przegrales", 90, 130); ctx.font = contentFontSize; ctx.fillStyle = "white"; ctx.fillText("Odswiez strone, by powtorzyc", 70, 150); } } } function whatKey(evt) { switch (evt.keyCode) { case 37: racquetX = racquetX - 20; if (racquetX < 0) racquetX = 0; break; case 39: racquetX = racquetX + 20; if (racquetX > boardX - racquetW) racquetX = boardX - racquetW; break; } } </script> </head> <body onLoad="drawGameCanvas()"> <div id="center"> <canvas id="gameBoard" width="300" height="300"></canvas> </div> </body> </center> HOME
DO WSTAWIENIA TEGO ELEMENTU STOSUJE SIE PONIZSZY KOD <style type="text/css">body, a, a:hover {cursor: url(http://profilki.pl/files/cur/1041.png) 0 0, default;}</style> <center> <script type="text/javascript"> // zmienne Globalne. var ballX = 150; var ballY = 150; var ballDX = 2; var ballDY = 4; var boardX = 300; var boardY = 300; var racquetX= 150; var racquetH= 10; var racquetD = boardY - racquetH; var racquetW = 150; var canvas; var ctx; var gameLoop; var titleFontSize = "bold 24px Georgia"; var contentFontSize = "normal 12px Arial"; function drawGameCanvas() { canvas = document.getElementById("gameBoard"); if (canvas.getContext) { ctx = canvas.getContext("2d"); gameLoop = setInterval(drawBall, 16); window.addEventListener('keydown', whatKey, true); } } function drawBall() { // wyczyść okienko z gra ctx.clearRect(0, 0, boardX, boardY); // wypelnij okienko z gra ctx.fillStyle = "black"; ctx.beginPath(); ctx.rect(0, 0, boardX, boardY); ctx.closePath(); ctx.fill(); // rysuj pilke ctx.fillStyle = "yellow"; ctx.beginPath(); ctx.arc(ballX, ballY, 15, 0, Math.PI * 2, true); ctx.closePath(); ctx.fill(); // rysuj belke ctx.fillStyle = "yellow"; ctx.beginPath(); ctx.rect(racquetX, racquetD, racquetW, racquetH); ctx.closePath(); ctx.fill(); // zmiana pozycji pilki ballX += ballDX; ballY += ballDY; // odpijanie pilki od krawedzi prawej i lewej if (ballX + ballDX > boardX - 15 || ballX + ballDX < 15) ballDX = -ballDX; // Odbicie piłki od gory okna if (ballY + ballDY < 15) ballDY = -ballDY; // Gdy piłka uderza o dolna krawędz, sprawdz czy dotknela belki else if (ballY + ballDY > boardY - 15) { // gdy dotknela belki, odbij ja if (ballX > racquetX && ballX < racquetX + racquetW) ballDY = -ballDY; // inaczej gra jest skonczona else { clearInterval(gameLoop); ctx.font = titleFontSize; ctx.fillStyle = "white"; ctx.fillText("Przegrales", 90, 130); ctx.font = contentFontSize; ctx.fillStyle = "white"; ctx.fillText("Odswiez strone, by powtorzyc", 70, 150); } } } function whatKey(evt) { switch (evt.keyCode) { case 37: racquetX = racquetX - 20; if (racquetX < 0) racquetX = 0; break; case 39: racquetX = racquetX + 20; if (racquetX > boardX - racquetW) racquetX = boardX - racquetW; break; } } </script> </head> <body onLoad="drawGameCanvas()"> <div id="center"> <canvas id="gameBoard" width="300" height="300"></canvas> </div> </body> </center> HOME