<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="400" height="400" style="border:10px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag. </canvas> <script> var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); // Bird var birdY = canvas.height/2; var birdDY = 0; var birdRadius = 20; // Bird size is 20 // Pipe var pipeX = canvas.width; var pipeH = Math.random()*canvas.height/3; // Bigger gap var pipeGap = 150; // Bigger gap // Colors var birdColor = "yellow"; var pipeColor = "green"; // Game over var gameOver = false; // Score var score = 0; function drawBird() { ctx.beginPath(); ctx.arc(canvas.width/4, birdY, birdRadius, 0, Math.PI*2); ctx.fillStyle = birdColor; ctx.fill(); ctx.closePath(); } function drawPipe() { ctx.beginPath(); ctx.rect(pipeX, 0, 50, pipeH); ctx.rect(pipeX, pipeH + pipeGap, 50, canvas.height - pipeH); ctx.fillStyle = pipeColor; ctx.fill(); ctx.closePath(); } function drawScore() { ctx.font = "32px Fantasy"; ctx.fillStyle = "#000"; ctx.fillText("Score: "+score, 8, 40); } function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); drawBird(); drawPipe(); drawScore(); birdY += birdDY; birdDY += 0.5; // Gravity pipeX -= 2; // When the bird hits the ground if(birdY > canvas.height) { birdDY = 0; birdY = canvas.height; } // When the bird hits the pipe if(birdY < pipeH || birdY > pipeH + pipeGap) { if(pipeX < canvas.width/4 && pipeX > canvas.width/4 - 50) { gameOver = true; } } // When the pipe goes off screen if(pipeX < -50) { pipeX = canvas.width; pipeH = Math.random()*canvas.height/3; score++; // Increase score when bird passes a pipe } // If game over, stop the game if(gameOver) { clearInterval(interval); // Stop the game ctx.font = "30px Arial"; ctx.fillText("Game Over", canvas.width/2, canvas.height/2); } } var interval = setInterval(draw, 20); document.addEventListener("keydown", function(event) { if(!gameOver) { birdDY = -10; // Jump } }); </script> </body> </html>
Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML
. You can also specify the stylesheet information in styles.css
tab and scripts information in scripts.js
tab and start coding.
HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.
<!DOCTYPE html>
<html>
and ends with </html>
<h1>
to <h6>
where <h1>
is the highest important heading and <h6>
is the least important sub-heading.<p>..</p>
tag.<a>
tag.
<a href="https://onecompiler.com/html">HTML online compiler</a>
<img>
tag, where src
attribute consists of image name.<button>..</button>
tag<ul>
for unordered/bullet list and <ol>
for ordered/number list, and the list items are defined in <li>
.<a href="https://onecompiler.com/html">HTML online compiler</a>
CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.
Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.
body{
padding: 25px;
}
.title {
color: #228B22;
font-family: Candara;
}
<table>
tag.<tr>
tag<th>
tag<td>
tag<caption>
tag<script>
is the tag used to write scripts in HTML<script src="script.js"></script>