Home
- Teachnogy और विज्ञान की नई दुनिया (9)
- महत्वपूर्ण जानकारियां। (9)
- नई ज्ञान 😍 (7)
- News of the Day (5)
- हम और हमारी दुनिया 🌍 (5)
- More... (4)
- Computer Science (1)
Game of Our Jharkhand
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flappy Bird Game</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #70c5ce; overflow: hidden; font-family: sans-serif; }
canvas { display: block; margin: 0 auto; background: #70c5ce; }
#score {
position: absolute;
top: 20px;
left: 20px;
color: white;
font-size: 24px;
font-weight: bold;
}
</style>
</head>
<body>
<div id="score">Score: 0</div>
<canvas id="gameCanvas" width="320" height="480"></canvas>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
let frames = 0;
let score = 0;
const gravity = 0.25;
const gap = 85;
const bird = {
x: 50,
y: 150,
width: 30,
height: 30,
velocity: 0,
draw() {
ctx.fillStyle = 'yellow';
ctx.fillRect(this.x, this.y, this.width, this.height);
},
update() {
this.velocity += gravity;
this.y += this.velocity;
if (this.y + this.height > canvas.height) {
this.y = canvas.height - this.height;
this.velocity = 0;
}
},
flap() {
this.velocity = -5;
}
};
const pipes = [];
pipes[0] = {
x: canvas.width,
y: Math.floor(Math.random() * -100)
};
function drawPipes() {
for (let i = 0; i < pipes.length; i++) {
ctx.fillStyle = 'green';
ctx.fillRect(pipes[i].x, pipes[i].y, 50, 200);
ctx.fillRect(pipes[i].x, pipes[i].y + 200 + gap, 50, canvas.height);
}
}
function updatePipes() {
for (let i = 0; i < pipes.length; i++) {
pipes[i].x--;
// Add new pipe
if (pipes[i].x === 150) {
pipes.push({
x: canvas.width,
y: Math.floor(Math.random() * -100)
});
}
// Increase score
if (pipes[i].x === bird.x) {
score++;
document.getElementById('score').innerText = 'Score: ' + score;
}
// Collision detection
if (
bird.x + bird.width > pipes[i].x &&
bird.x < pipes[i].x + 50 &&
(bird.y < pipes[i].y + 200 || bird.y + bird.height > pipes[i].y + 200 + gap)
) {
alert('Game Over! Your Score: ' + score);
document.location.reload();
}
}
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
bird.draw();
drawPipes();
}
function update() {
bird.update();
updatePipes();
}
function loop() {
update();
draw();
frames++;
requestAnimationFrame(loop);
}
document.addEventList
ener('keydown', function(e) {
if (e.code === 'Space') bird.flap();
});
loop();
</script>
</body>
</html>
Www.futureworld333.blogspot.com
Popular posts
-
Amezing sites of internet 12th Lesson-14 Internet and network Study of computer science.... network and internet ...
-
श्री बंशीधर मन्दिर नगर उंटारी (गढ़वा) श्री बंशीधर भगवान। वो ब्रह्म या भाग्य लिखने वाले जो बंशी धारण करते हैं। इस सौ सा...
-
info@paharimandirranchi.com Darshan Tim ing : 4:30 am to 9:00 pm P AHARI M ANDIR R ANCHI ABOUT DARSHAN & AARTI EVENTS & GALLE...
-
Video of the program श्री बंशीधर नगर : अनुमंडल मैदान में गणतंत्र दिवस के मुख्य समारोह में कई कार्यक्रम आयोजित किया गया। कार्यक्रम के ...