I have the following code and am trying to get the flappy bird to rise in the air which any part of the canvas is clicked.
I think I have placed the if statement wrong or there is some error with it.
if(c.onclick="True"){
birdDY==9;
}
Could the error in this code be pointed out along with an explanation for where it should go?
Whole code:
<style>
#block{
width: 50px;
height: 500px;
background-color: greenyellow;
position: relative;
left: 400px;
animation: block 2s infinite linear;
}
@keyframes block{
0%{left:400px}
100%{left:-50px}
}
#hole{
width: 50px;
height: 150px;
background-color: white;
position: relative;
left: 400px;
top: -500px;
animation: block 2s infinite linear;
}
</style>
<body style="height: 100vh; background: #111; text-align: center;">
<canvas id="c" width="400" height="400"></canvas>
<div id="block"></div>
<script>
//set up context
context = c.getContext("2d");
//create bird
const bird = new Image();
bird.src = "bird.png";
//create variables
var canvasSize = 400;
var birdSize=30;
var birdX = 0;
var birdY =200;
var birdDY = 0;
var score = 0;
var bestScore=0;
var interval = 30; //the speed at which the game is played
c.onclick = () => (birdDY = 9) ;
setInterval(() => {
context.fillStyle = "skyblue";
context.fillRect(0,0,canvasSize,canvasSize); // Draw sky
birdY -= birdDY -= 0.5; // Gravity
context.drawImage(bird, birdX, birdY, birdSize, birdSize); // Draw bird (multiply the birdSize by a number to adjust size)
context.fillStyle = "black";
context.fillText(`Flappy Birds`, 170, 10); //x and y
context.fillText(`Score: ${score++}`,350, 380); // Draw score
context.fillStyle = "green";
context.fillRect(300,20,canvasSize,canvasSize); // Draw blocks
}, interval)
</script>
</body>