{"id":3249,"date":"2025-07-25T14:35:01","date_gmt":"2025-07-25T14:35:01","guid":{"rendered":"https:\/\/fe.up.pt\/iaces\/?page_id=3249"},"modified":"2025-07-25T14:45:15","modified_gmt":"2025-07-25T14:45:15","slug":"testa-o-novo-jogo-agora","status":"publish","type":"page","link":"https:\/\/fe.up.pt\/iaces\/testa-o-novo-jogo-agora\/","title":{"rendered":"Testa o novo jogo agora!"},"content":{"rendered":"\n<style>\n  #flappy-container {\n    width: 100%;\n    max-width: 400px;\n    margin: auto;\n    text-align: center;\n    font-family: 'Verdana', sans-serif;\n  }\n\n  canvas {\n    width: 100%;\n    height: auto;\n    background: #70c5ce;\n    border-radius: 12px;\n  }\n\n  #score-display {\n    margin-top: 10px;\n    font-size: 18px;\n    color: #333;\n  }\n\n  #restart-btn {\n    margin-top: 10px;\n    padding: 8px 16px;\n    background: #1e88e5;\n    color: white;\n    border: none;\n    border-radius: 6px;\n    font-size: 16px;\n    cursor: pointer;\n    display: none;\n  }\n\n  #restart-btn:hover {\n    background: #1565c0;\n  }\n<\/style>\n\n<div id=\"flappy-container\">\n  <canvas id=\"flappy\" width=\"320\" height=\"480\"><\/canvas>\n  <div id=\"score-display\">Pontua\u00e7\u00e3o: 0 | M\u00e1xima: 0<\/div>\n  <button id=\"restart-btn\">Recome\u00e7ar<\/button>\n<\/div>\n\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function () {\n    const canvas = document.getElementById(\"flappy\");\n    const ctx = canvas.getContext(\"2d\");\n    const scoreDisplay = document.getElementById(\"score-display\");\n    const restartBtn = document.getElementById(\"restart-btn\");\n\n    const bridgeEmoji = \"\ud83c\udf09\";\n    const boomEmoji = \"\ud83d\udca5\";\n    const gap = 140;\n    const gravity = 1.0;\n    const jump = -8;\n\n    let bird, pipes, score, highScore, velocity, gameOver, animationFrame;\n\n    function initGame() {\n      bird = { x: 50, y: 150, size: 30 };\n      pipes = [];\n      velocity = 0;\n      score = 0;\n      gameOver = false;\n      highScore = parseInt(localStorage.getItem(\"flappyHighScore\")) || 0;\n\n      pipes.push({\n        x: canvas.width,\n        y: Math.floor(Math.random() * -150) - 50\n      });\n\n      restartBtn.style.display = \"none\";\n      scoreDisplay.textContent = `Pontua\u00e7\u00e3o: 0 | M\u00e1xima: ${highScore}`;\n\n      cancelAnimationFrame(animationFrame);\n      requestAnimationFrame(gameLoop);\n    }\n\n    function drawEmoji(context, emoji, x, y, size) {\n      context.font = `${size}px serif`;\n      context.fillText(emoji, x, y + size * 0.75);\n    }\n\n    function flap() {\n      if (!gameOver) velocity = jump;\n    }\n\n    function gameLoop() {\n      ctx.clearRect(0, 0, canvas.width, canvas.height);\n\n      \/\/ Bird physics\n      velocity += gravity;\n      bird.y += velocity;\n\n      \/\/ Pipes logic\n      for (let i = 0; i < pipes.length; i++) {\n        const pipe = pipes[i];\n        pipe.x -= 2;\n\n        \/\/ Draw pipes\n        ctx.fillStyle = \"#228B22\";\n        ctx.fillRect(pipe.x, pipe.y, 50, 200);\n        ctx.fillRect(pipe.x, pipe.y + 200 + gap, 50, canvas.height);\n\n        \/\/ Add new pipe\n        if (pipe.x === 150) {\n          pipes.push({\n            x: canvas.width,\n            y: Math.floor(Math.random() * -150) - 50\n          });\n        }\n\n        \/\/ Score increment\n        if (pipe.x + 50 === bird.x) {\n          score++;\n          if (score > highScore) {\n            highScore = score;\n            localStorage.setItem(\"flappyHighScore\", highScore);\n          }\n        }\n\n        \/\/ Collision\n        const inPipeRange = bird.x + bird.size > pipe.x && bird.x < pipe.x + 50;\n        const hitTopPipe = bird.y < pipe.y + 200;\n        const hitBottomPipe = bird.y + bird.size > pipe.y + 200 + gap;\n\n        if (inPipeRange && (hitTopPipe || hitBottomPipe)) {\n          gameOver = true;\n        }\n      }\n\n      \/\/ Check ground or top collision\n      if (bird.y + bird.size >= canvas.height || bird.y < 0) {\n        gameOver = true;\n      }\n\n      \/\/ Draw bird\n      drawEmoji(ctx, gameOver ? boomEmoji : bridgeEmoji, bird.x, bird.y, bird.size);\n\n      \/\/ Update score display\n      scoreDisplay.textContent = `Pontua\u00e7\u00e3o: ${score} | M\u00e1xima: ${highScore}`;\n\n      if (!gameOver) {\n        animationFrame = requestAnimationFrame(gameLoop);\n      } else {\n        restartBtn.style.display = \"inline-block\";\n      }\n    }\n\n    \/\/ Event listeners\n    document.addEventListener(\"keydown\", (e) => {\n      if (e.code === \"Space\" || e.code === \"ArrowUp\") flap();\n    });\n    document.addEventListener(\"touchstart\", (e) => {\n      e.preventDefault();\n      flap();\n    }, { passive: false });\n\n    restartBtn.addEventListener(\"click\", initGame);\n\n    \/\/ Start the game on load\n    initGame();\n  });\n<\/script>\n\n","protected":false},"excerpt":{"rendered":"<p>Pontua\u00e7\u00e3o: 0 | M\u00e1xima: 0 Recome\u00e7ar<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"categoria_pag":[],"class_list":["post-3249","page","type-page","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/fe.up.pt\/iaces\/wp-json\/wp\/v2\/pages\/3249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fe.up.pt\/iaces\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/fe.up.pt\/iaces\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/fe.up.pt\/iaces\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fe.up.pt\/iaces\/wp-json\/wp\/v2\/comments?post=3249"}],"version-history":[{"count":5,"href":"https:\/\/fe.up.pt\/iaces\/wp-json\/wp\/v2\/pages\/3249\/revisions"}],"predecessor-version":[{"id":3266,"href":"https:\/\/fe.up.pt\/iaces\/wp-json\/wp\/v2\/pages\/3249\/revisions\/3266"}],"wp:attachment":[{"href":"https:\/\/fe.up.pt\/iaces\/wp-json\/wp\/v2\/media?parent=3249"}],"wp:term":[{"taxonomy":"categoria_pag","embeddable":true,"href":"https:\/\/fe.up.pt\/iaces\/wp-json\/wp\/v2\/categoria_pag?post=3249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}