Permalink
Browse files

killing hardcoded flyarea height

  • Loading branch information...
1 parent c2ee301 commit 9bed4acacdd980541b181ebdc099aff89bd6f16e @mohamedpsx mohamedpsx committed Apr 17, 2016
Showing with 5 additions and 4 deletions.
  1. +5 −4 js/main.js
View
@@ -30,6 +30,7 @@ var velocity = 0;
var position = 180;
var rotation = 0;
var jump = -4.6;
+var flyArea = $("#flyarea").height();
var score = 0;
var highscore = 0;
@@ -352,7 +353,7 @@ function playerDead()
//drop the bird to the floor
var playerbottom = $("#player").position().top + $("#player").width(); //we use width because he'll be rotated 90 deg
- var floor = $("#flyarea").height();
+ var floor = flyArea;
var movey = Math.max(0, floor - playerbottom);
$("#player").transition({ y: movey + 'px', rotate: 90}, 1000, 'easeInOutCubic');
@@ -463,11 +464,11 @@ function updatePipes()
//Do any pipes need removal?
$(".pipe").filter(function() { return $(this).position().left <= -100; }).remove()
- //add a new pipe (top height + bottom height + pipeheight == 420) and put it in our tracker
+ //add a new pipe (top height + bottom height + pipeheight == flyArea) and put it in our tracker
var padding = 80;
- var constraint = 420 - pipeheight - (padding * 2); //double padding (for top and bottom)
+ var constraint = flyArea - pipeheight - (padding * 2); //double padding (for top and bottom)
var topheight = Math.floor((Math.random()*constraint) + padding); //add lower padding
- var bottomheight = (420 - pipeheight) - topheight;
+ var bottomheight = (flyArea - pipeheight) - topheight;
var newpipe = $('<div class="pipe animated"><div class="pipe_upper" style="height: ' + topheight + 'px;"></div><div class="pipe_lower" style="height: ' + bottomheight + 'px;"></div></div>');
$("#flyarea").append(newpipe);
pipes.push(newpipe);

0 comments on commit 9bed4ac

Please sign in to comment.