How to Make a Flappy Bird Game: A Beginner's Guide
//1. Create variables to store the score, the current position of the bird, and the current speed of the bird let score = 0; let birdPosition = 0; let birdSpeed = 1;
//2. Create a function to move the bird that increases by the speed variable function moveBird() { birdPosition += birdSpeed; }
//3. Create a function to draw the bird on the screen function drawBird() { //draw bird in current position }
//4. Create a function to draw the pipes on the screen function drawPipes() { //draw pipes }
//5. Create a function to detect if the bird has collided with the pipes function checkCollision() { //check for collision }
//6. Create a function to update the score when the bird passes through the pipes function updateScore() { score++; }
//7. Create a function to reset the game when the bird has collided with the pipes function resetGame() { //reset game }
//8. Create a loop that will call the moveBird, drawBird, drawPipes, checkCollision, and updateScore functions while (true) { moveBird(); drawBird(); drawPipes(); checkCollision(); updateScore(); if (checkCollision()) { resetGame(); } }
原文地址: https://www.cveoy.top/t/topic/lmtB 著作权归作者所有。请勿转载和采集!