{"id":1092,"date":"2026-01-07T07:43:38","date_gmt":"2026-01-07T07:43:38","guid":{"rendered":"https:\/\/javigomez.org\/?p=1092"},"modified":"2026-01-10T12:58:07","modified_gmt":"2026-01-10T12:58:07","slug":"juego-de-tenis","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2026\/01\/07\/juego-de-tenis\/","title":{"rendered":"Juego de Tenis"},"content":{"rendered":"\n<p>Es el ya conocido juego de tenis en donde un juega contra la m\u00e1quina. Como el resto de juegos, est\u00e1 la din\u00e1mica de juego, el movimiento de la pala autom\u00e1tica. La gesti\u00f3n de un puntos y final de partida se deja preparada para que quien quiera lo realice a su manera.<\/p>\n\n\n\n<p><a href=\"https:\/\/javigomez.org\/juegosJS\/Tenis.html\">https:\/\/javigomez.org\/juegosJS\/Tenis.html<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/jagode67\/juegosJS\/blob\/main\/Tenis.html\">https:\/\/github.com\/jagode67\/juegosJS\/blob\/main\/Tenis.html<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n    &lt;meta charset=\"UTF-8\">\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    &lt;title>Tenis&lt;\/title>\n&lt;\/head>\n&lt;body>\n    &lt;canvas id=\"fondo\" width=\"800\" height=\"600\">&lt;\/canvas>\n    &lt;script>\n        var fps = 30;\n        var tAnterior = 0;\n\n        var bolaX = 50;\n        var bolaY = 20;\n        var velX = 10;\n        var velY = 4;\n\n        var pala1Y = 250;\n        var pala2Y = 250;\n        const PALA_ANCHO = 10;\n        const PALA_ALTO = 100;\n\n        window.onload = function () {\n            fondo = document.getElementById(\"fondo\");\n            ctx = fondo.getContext(\"2d\");\n            \/\/setInterval(juego, 1000 \/ 30);\n            requestAnimationFrame(ctrJuego);\n            \/\/fondo.addEventListener('mousedown', clickRaton)\n            fondo.addEventListener('mousemove',\n                function (evt) {\n                    var rect = fondo.getBoundingClientRect();\n                    var root = document.documentElement;\n                    pala1Y = Math.min(evt.clientY - rect.top - root.scrollTop, fondo.height - PALA_ALTO);\n                })\n\n        }\n\n        function ctrJuego(timestamp) {\n            var delta = timestamp - tAnterior;\n            if (delta >= 1000 \/ fps) {\n                juego();\n                tAnterior = timestamp;\n            }\n            requestAnimationFrame(ctrJuego);\n        }\n\n        function juego() {\n            mover();\n            mostrar();\n        }\n        function mover() {\n            bolaX += velX;\n            bolaY += velY;\n            \/\/mueve pala bot\n            \/\/Si la bola est\u00e1 por encima del centro de la pala\n            if (bolaY&lt;pala2Y+PALA_ALTO\/2) pala2Y-=6;\n            \/\/Si la bola est\u00e1 por debajo del centro de la pala\n            if (bolaY>pala2Y+PALA_ALTO\/2) pala2Y+=6;\n\n            \/\/Si chocha en la pared del jugador\n            if (bolaX &lt; 0) {\n                if (bolaY > pala1Y &amp;&amp; bolaY &lt; pala1Y + PALA_ALTO) {\n                    velX *= -1;\n                    sepCentro = bolaY - (pala1Y + PALA_ALTO \/ 2);\n                    velY = sepCentro * 0.3;\n                } else {\n                    bolaY = fondo.height \/ 2;\n                    bolaX = fondo.width \/ 2;\n                    velY=4; velX=10;\n                    console.log(\"punto bot\")\n                }\n            }\n            \/\/Si chocha en la pared del bot\n            if (bolaX > fondo.width) {\n                if (bolaY > pala2Y &amp;&amp; bolaY &lt; pala2Y + PALA_ALTO) {\n                    velX *= -1;\n                    sepCentro = bolaY - (pala2Y + PALA_ALTO \/ 2);\n                    velY = sepCentro * 0.3;\n                } else {\n                    bolaY = fondo.height \/ 2;\n                    bolaX = fondo.width \/ 2;\n                    velY=4; velX=10;\n                    console.log(\"punto jugador\")\n                }\n            }\n            if (bolaY &lt; 0 || bolaY > fondo.height) velY *= -1;\n        }\n        function mostrar() {\n            \/\/campo\n            ctx.fillStyle = 'black';\n            ctx.fillRect(0, 0, fondo.width, fondo.height);\n            \/\/red\n            for (i = 0; i &lt; fondo.height; i += 40) {\n                ctx.fillStyle = 'white';\n                ctx.fillRect(fondo.width \/ 2 - 1, i, 2, 20);\n            }\n            \/\/pala jugador \n            ctx.fillStyle = 'white';\n            ctx.fillRect(0, pala1Y, PALA_ANCHO, PALA_ALTO);\n\n            \/\/pala  bot\n            ctx.fillStyle = 'white';\n            ctx.fillRect(fondo.width - PALA_ANCHO, pala2Y, PALA_ANCHO, PALA_ALTO);\n\n            \/\/bola\n            ctx.fillStyle = \"white\";\n            ctx.beginPath();\n            ctx.arc(bolaX, bolaY, 10, 0, Math.PI * 2, true);\n            ctx.fill();\n        }\n    &lt;\/script>\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Es el ya conocido juego de tenis en donde un juega contra la m\u00e1quina. Como el resto de juegos, est\u00e1 la din\u00e1mica de juego, el &hellip; <\/p>\n","protected":false},"author":1,"featured_media":1093,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[204,207,366],"class_list":["post-1092","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-javascript","tag-juego","tag-tenis"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/1092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/comments?post=1092"}],"version-history":[{"count":2,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/1092\/revisions"}],"predecessor-version":[{"id":1098,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/1092\/revisions\/1098"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media\/1093"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=1092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=1092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=1092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}