Fixed tracking issue after resize and added conditionals for IE.
This commit is contained in:
parent
8594fdebfa
commit
d55c1d339a
2 changed files with 111 additions and 61 deletions
67
river.js
67
river.js
|
@ -5,6 +5,18 @@ $(document).ready(function()
|
||||||
var cheater = false;
|
var cheater = false;
|
||||||
var pi2x = Math.PI * 2;
|
var pi2x = Math.PI * 2;
|
||||||
|
|
||||||
|
var userAgent = navigator.userAgent.toLowerCase();
|
||||||
|
|
||||||
|
var isIE = userAgent.indexOf('msie') != -1;
|
||||||
|
var isIphone = userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipad') != -1
|
||||||
|
var isAndroid = userAgent.indexOf('android') != -1;
|
||||||
|
|
||||||
|
if (!isIE)
|
||||||
|
{
|
||||||
|
canvas.css('-moz-border-radius', '20px');
|
||||||
|
canvas.css('-webkit-border-radius', '20px');
|
||||||
|
}
|
||||||
|
|
||||||
// In case you ever need to reset the score
|
// In case you ever need to reset the score
|
||||||
//localStorage.setItem('high', 0);
|
//localStorage.setItem('high', 0);
|
||||||
|
|
||||||
|
@ -23,7 +35,6 @@ $(document).ready(function()
|
||||||
var width = canvas.width();
|
var width = canvas.width();
|
||||||
var height = canvas.height();
|
var height = canvas.height();
|
||||||
var middle = 35;
|
var middle = 35;
|
||||||
var offset = canvas.attr('offsetLeft');
|
|
||||||
var prevX = (width / 2) - 6;
|
var prevX = (width / 2) - 6;
|
||||||
var wallLeftX = new Array();
|
var wallLeftX = new Array();
|
||||||
var wallLeftY = new Array();
|
var wallLeftY = new Array();
|
||||||
|
@ -35,13 +46,13 @@ $(document).ready(function()
|
||||||
var nextRight = rightX;
|
var nextRight = rightX;
|
||||||
var previousPaddle = 'left';
|
var previousPaddle = 'left';
|
||||||
var nextPaddle = 'center';
|
var nextPaddle = 'center';
|
||||||
var index = 0;
|
var direction = 'center';
|
||||||
|
var index;
|
||||||
|
var intervals;
|
||||||
var min;
|
var min;
|
||||||
var max;
|
var max;
|
||||||
var turn;
|
var turn;
|
||||||
var speed = 80;
|
var speed;
|
||||||
var intervals = 0;
|
|
||||||
var direction = 'center';
|
|
||||||
|
|
||||||
context.strokeStyle = '#000';
|
context.strokeStyle = '#000';
|
||||||
context.lineWidth = '2';
|
context.lineWidth = '2';
|
||||||
|
@ -61,6 +72,8 @@ $(document).ready(function()
|
||||||
{
|
{
|
||||||
if (started == false)
|
if (started == false)
|
||||||
{
|
{
|
||||||
|
canvas.css('cursor', 'none');
|
||||||
|
|
||||||
cheater = $('input:checked').length;
|
cheater = $('input:checked').length;
|
||||||
|
|
||||||
wallLeftX = new Array();
|
wallLeftX = new Array();
|
||||||
|
@ -115,10 +128,8 @@ $(document).ready(function()
|
||||||
{
|
{
|
||||||
if (started == true)
|
if (started == true)
|
||||||
{
|
{
|
||||||
canvas.css('cursor', 'move');
|
|
||||||
context.clearRect(prevX, middle, 49, 65);
|
context.clearRect(prevX, middle, 49, 65);
|
||||||
|
prevX = event.pageX - canvas.position().left - 25;
|
||||||
prevX = event.clientX - offset - 25;
|
|
||||||
drawKayak();
|
drawKayak();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -250,6 +261,8 @@ $(document).ready(function()
|
||||||
context.fillStyle = '#000';
|
context.fillStyle = '#000';
|
||||||
context.fillText('GAME OVER!', 145, 235);
|
context.fillText('GAME OVER!', 145, 235);
|
||||||
context.fillText('Click to Restart', 100, 255);
|
context.fillText('Click to Restart', 100, 255);
|
||||||
|
|
||||||
|
canvas.css('cursor', 'pointer');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,32 +360,70 @@ $(document).ready(function()
|
||||||
}
|
}
|
||||||
|
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
|
|
||||||
|
if (isIE)
|
||||||
|
{
|
||||||
|
context.moveTo(0, 500);
|
||||||
|
context.lineTo(0, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
context.moveTo(0, 485);
|
context.moveTo(0, 485);
|
||||||
context.lineTo(0, 15);
|
context.lineTo(0, 15);
|
||||||
context.arc(15, 15, 15, Math.PI, (Math.PI * 3) / 2, false);
|
context.arc(15, 15, 15, Math.PI, (Math.PI * 3) / 2, false);
|
||||||
context.moveTo(15, 0);
|
context.moveTo(15, 0);
|
||||||
|
}
|
||||||
|
|
||||||
context.lineTo(wallLeftX[0], wallLeftY[0]);
|
context.lineTo(wallLeftX[0], wallLeftY[0]);
|
||||||
for (var i in wallLeftX)
|
for (var i in wallLeftX)
|
||||||
{
|
{
|
||||||
context.lineTo(wallLeftX[i], wallLeftY[i]);
|
context.lineTo(wallLeftX[i], wallLeftY[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isIE)
|
||||||
|
{
|
||||||
|
context.lineTo(0, 500);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
context.lineTo(15, 500);
|
context.lineTo(15, 500);
|
||||||
context.arc(15, 485, 15, Math.PI / 2, Math.PI, false);
|
context.arc(15, 485, 15, Math.PI / 2, Math.PI, false);
|
||||||
|
}
|
||||||
|
|
||||||
context.fillStyle = '#090';
|
context.fillStyle = '#090';
|
||||||
context.fill();
|
context.fill();
|
||||||
|
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
|
|
||||||
|
if (isIE)
|
||||||
|
{
|
||||||
|
context.moveTo(400, 500);
|
||||||
|
context.lineTo(400, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
context.moveTo(400, 485);
|
context.moveTo(400, 485);
|
||||||
context.lineTo(400, 15);
|
context.lineTo(400, 15);
|
||||||
context.arc(385, 15, 15, pi2x, (Math.PI * 3) / 2, true);
|
context.arc(385, 15, 15, pi2x, (Math.PI * 3) / 2, true);
|
||||||
context.moveTo(385, 0);
|
context.moveTo(385, 0);
|
||||||
|
}
|
||||||
|
|
||||||
context.lineTo(wallRightX[0], wallRightY[0]);
|
context.lineTo(wallRightX[0], wallRightY[0]);
|
||||||
for (var i in wallRightX)
|
for (var i in wallRightX)
|
||||||
{
|
{
|
||||||
context.lineTo(wallRightX[i], wallRightY[i]);
|
context.lineTo(wallRightX[i], wallRightY[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isIE)
|
||||||
|
{
|
||||||
|
context.lineTo(400, 500);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
context.lineTo(385, 500);
|
context.lineTo(385, 500);
|
||||||
context.arc(385, 485, 15, Math.PI / 2, 0, true);
|
context.arc(385, 485, 15, Math.PI / 2, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
context.fill();
|
context.fill();
|
||||||
|
|
||||||
drawKayak();
|
drawKayak();
|
||||||
|
|
|
@ -65,7 +65,6 @@ canvas
|
||||||
{
|
{
|
||||||
background: #39f;
|
background: #39f;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
-moz-border-radius: 20px;
|
border: 4px solid #2d3a47;
|
||||||
-webkit-border-radius: 20px;
|
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue