flappy mobile

Make your own flappy

by ElijahCirioli

HTML

<canvas id="myCanvas" width="500" height="500" style="border:1px solid #000000;"></canvas>

JavaScript

/*********************
Make the Flappy Birds
*********************/
//game variables
//BIRD VARIABLES
var maxVel = 10; //bird max falling velocity
var vel = 2; //bird falling velocity--should be less than maxVel
var velInc = 0.7; //change in bird velocity--should be less than 1
var flyingVel = 8; //distance bird will move up when he flaps wings
var birdSize = 64; //size of bird
var birdX = 130; //bird x location
var birdY = 190; //bird starting y location
var birdAnimationRate = 15; //animation speed for bird
//obstacle VARIABLES
var spd = 3; //obstacle speed
var pipeWidth = 64; //width of pipe
var pipeDistance = 100; //distance between pipes
var numobstacles = 100; //number of sets of different obstacles in game
//SCORE VARAIBLES
var scoreSize = 50; //font size for score
var scoreX = 465; //x position of score
var scoreY = 5; //y position of score
var scoreColor = "white"; //color of score
var highscore = 0;
//FRAME RATE
var frameRate = 30;
//ARE YOU PLAYING ON A PHONE?
var mobile = true;
//////////////////////////
//change to your images vvvv
//////////////////////////
var birdImage = "https://s22.postimg.org/9frj47rxt/TURTLE.png";
var topPipeImage = "https://s14.postimg.org/j8h6ck81t/image.png";
var bottomPipeImage = "https://s18.postimg.org/bdovoqi6h/image.png";
var backgroundImage = "https://s12.postimg.org/ednnufe71/image.jpg";

/***********
Game Methods
***********/
/***********
Initialize game and reset all variables
************/
function init() {
  clearInterval(thread);
  playing = false;
  if (highscore < score) {
  highscore = score;
  }
  score = 0;
  vel = 0;
  //initialize bird
  bird = new Bird();
  //initialize all the obstacles
  for (i = 0; i < numobstacles; i += 2) {
    //calculate x position of the pipe
    var x = (i * pipeDistance) + 500 + (pipeWidth*i/2);
    //random distance between top and bottom pipes
    var dist = Math.round(Math.random() * 100) + 100;
    //random height of top pipe
    var height = Math.ceil(Math.random() * 4) *...