var e=0,f=80,g=120,h=0,i=Math,k=i.random,l=-1,m=50,n=0;c.width=400;c.height=400;function o(b,d){a.lineTo(b,d)}function p(){a.beginPath()}onkeydown=onkeyup=function(b){var d=b.type[5]?1:-1;b=b.keyCode;l=b^32?l:d};
function q(){a.fillStyle="gray";a.fillRect(0,0,400,400);e+=2;n-=l/3;g+=n;a.fillStyle="white";p();a.arc(f,g,10,0,i.PI*2,1);a.fill();for(var b=0;b<r;b++){var d=s[b]+400+k()-0.5;d%=16E4;s[b]=d;a.fillRect((d-e)%400,d/400,1,1)}a.fillStyle="lightblue";for(b=0;b<4;b++){d=(400-e%400+t[b])%400-m;var j=400-d-160;p();o(d,j);o(d+10,j+3);o(d+5,j+70);o(d,j);if(a.isPointInPath(90,g))h=1;a.fill()}p();o(0,0);if(e%m==0){u();v++}for(b=0;b<10;b++){d=b*m-e%m;o(d,w[b+v])}o(400,0);o(0,0);for(b=0;b<10;b++){d=b*m-e%m;o(d,
250+w[b+v])}o(400,400);o(0,400);if(a.isPointInPath(90,g))h=1;a.fill();a.fillStyle="red";a.font="50px arial";h?a.fillText("GAME OVER",m,200):setTimeout(q,30)}for(var t=[50,150,250,350],v=0,w=[],x=0;x<10;x++)u();function u(){w.push(i.floor(k()*110+5))}for(var r=978,s=[],y=0;y<r;y++)s.push(164*y+k()*100);q()
var counter = 0;
/** @const */ var width = 400;
/** @const */ var height = width;
/** @const */ var white = 'white';
var snowballX = 80;
var snowballY = 120;
var gameOver = 0;
var M = Math;
var rand = M.random;
var up = -1;
var fifty = 50;
var yVel = 0;
c.width = width;
c.height = height;
function lineTo(x,y) {
a.lineTo(x,y);
}
function beginPath() {
a.beginPath();
}
window['lineTo'] = lineTo;
window['beginPath'] = beginPath;
onkeydown=onkeyup=function(e){
// if this is a keydown event, new_val gets the value 4, otherwise 0
var new_val=e.type[5]?1:-1;
e=e.keyCode;
// if space pressed, up is truthy (credit where credit's due:
// this is adapted from Legend of the Bouncing Beholder
// http://js1k.com/2010-first/demo/635)
up=e^32?up:new_val;
}
function gameloop() {
a.fillStyle = 'gray';
a.fillRect(0,0,width,height);
counter += 2;
moveSnowball();
//as long as these happen in the right order, only need to set a.fillStyle = white once
a.fillStyle = white;
snowball();
snow();
a.fillStyle = "lightblue";//"rgb(190,230,255)";
icicles();
walls();
a.fillStyle = "red";
a.font = "50px arial";
if(!gameOver) {
setTimeout(gameloop, 30);
}
else {
a.fillText('GAME OVER', fifty, 200);
}
}
function moveSnowball() {
yVel -= up/3;
snowballY += yVel;
}
function detectCollision() {
if (a.isPointInPath(90, snowballY)) { //front middle point
gameOver = 1;
}
}
var icicleArray = [50, 150, 250, 350];
function icicles() {
for (var i = 0; i < 4; i++) {
var x = (width - (counter%width) + icicleArray[i]) % width - fifty;
var y = height - x - 160;
beginPath();
lineTo(x, y);
lineTo(x + 10, y + 3);
lineTo(x + 5, y + 70);
lineTo(x, y);
detectCollision();
a.fill();
}
}
var firstWallPoint = 0;
var wallPoints = [];
for(var i = 0; i < 10; i++) {
newWallPoint();
}
function newWallPoint() {
wallPoints.push(M.floor(rand() * 110 + 5));
}
function walls() {
beginPath();
lineTo(0,0);
if (counter % fifty == 0) {
newWallPoint();
firstWallPoint++;
}
for (var i = 0; i < 10; i++) {
var xpos = i * fifty - (counter % fifty);
lineTo(xpos, wallPoints[i + firstWallPoint]);
}
lineTo(width, 0);
lineTo(0, 0);
for (var i = 0; i < 10; i++) {
var xpos = i * fifty - (counter % fifty);
lineTo(xpos, 250 + wallPoints[i + firstWallPoint]);
}
lineTo(width, height);
lineTo(0, height);
detectCollision();
a.fill();
}
function snowball() {
beginPath();
a.arc(snowballX, snowballY, 10, 0, M.PI*2, 1);
a.fill();
}
var flakes = 978;
var snowArray = [];
for(var j = 0; j < flakes; j++) {
snowArray.push(164 * j + rand() * 100); //164 = (width*height) / flakes
}
function snow() {
for(var j = 0; j < flakes; j++) {
var s = snowArray[j] + width + rand() - 0.5;// + M.sin(counter/2) / 4;
s %= width*height;
snowArray[j] = s;
var x = (s - counter) % width;
var y = s / width;
a.fillRect(x, y, 1, 1);
}
}
gameloop();