Skip to content

Instantly share code, notes, and snippets.

@halfbyte
Created April 11, 2011 22:07
Show Gist options
  • Save halfbyte/914477 to your computer and use it in GitHub Desktop.
Save halfbyte/914477 to your computer and use it in GitHub Desktop.
my contribution to js1k#3
<!doctype html>
<html>
<head>
<title>JS1k, 1k demo submission [ID]</title>
<meta charset="utf-8" />
</head>
<body>
<canvas id="c"></canvas>
<script>
var b = document.body;
var c = document.getElementsByTagName('canvas')[0];
var a = c.getContext('2d');
document.body.clientWidth; // fix bug in webkit: http://qfox.nl/weblog/218
</script>
<script>
// start of submission //
for($ in a)a[$[0]+($[6]||$[2])]=a[$];
c.style.background="#ccc";
s=c.width=c.height=320;
C='#FA07#8407#8C97#000'.split(7);
p=[];fa=false;l=3;sc=0;t=2;z=10;
a.font="20px serif"
function f() {
if(p.length==5 && ((p[4] & (1 << t)) > 0)) {
l--;p=[];
if(l<=0) g();
} else {
sc+=10;
}
sc%500==0?z--:z;
p.unshift(Math.round(Math.random()*14));
if(p.length>5)p.pop();
}
c=0;
function g() {
a.fx("GAME OVER", 100,20);
l=3;sc=0;z=11;
clearTimeout(k);
setTimeout(d, 2000);
}
function d() {
with(a) {
sv();
ce(0,0,s,s);
ta(0,120);
// field
ba();fillStyle=C[0];
mv(180,0);ln(319,199);ln(0,199);ln(140,0);ca();fl();
fillStyle=C[1];
ll=p.length;for(i=0;i<ll;i++){
y=(7*i*i);
for(x=0;x<4;x++ ) {
if((p[i] & (1 << x)) > 0) a.fillRect(x*(10*i + 5) + (160 - (i*20)),y + 40,i*5+1,i*2+2);
}
}
r = 0.37-(t/4);
ta(70+(t*60),160);
rt(r);
strokeStyle=C[2];
lineWidth=5;
ba();
ac(0,-10,12,-4,1, fa);
sr();
fillStyle=C[1];
fc(-12,-8,24,16);
fc(-18,0,5,20);
fc(13,0,5,20);
re();
fillStyle=C[3];
fx(sc, 280, 40);
fx(l, 20,40);
}
k=setTimeout(d,50);
c++;
if(c%z==0) f();
}
window.onkeydown = function(e) {
k=e.keyCode||e.which;if(k == 37)t--;if(k == 39)t++;t=t<0?0:(t>3?3:t);
};
d();
// end of submission //
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment