_='d=document;W=a.width/3;H=a.height/3;scaJ(3,3kg=L3BA";r=LE54";N=DPe.nowR=MPrandom;sv=5;x=T=10;y=H/2;t=Text;eZbZfsfStyJ=fddVfs(hRecXx,y,nwVw)ll<h;l$m=h[l];9xGxx<x^yGyy<y^) l,1s+=n,!0} !1nrV ObjecX?fW+150*R()hR()*H,i:0,w:nTV:l})k<T;)e)k$;keglrequestAnimPionFrame(gl00},L666",W,H91>v)fs(rX"sre: "+s%%else{D=(N()-pN)/10055},gv%%515},rs%,200!40=y+738=y-732=bx,y,5)kK)0>y(yKy+T>H(y=H-Tf=?xy,w:T(Qe,0)v--;QgIe_h=e@;y-7*MPs(i*DY-7;i$;90>Y(Ub,1))e@=nr(Ur)}Ib_)h=b@,Y+7,Y>Wb.Q1ULFD6")}gl(downfk=keyCodeupkK=function();.Jngth=k(?nsoJ.log(f.fill returnQUnh.for(var ){K;,y:.push(nr(,5,5X};&&),=m.dd(splice(d.onkey||co;pN=N(c.$++%,T7=39if(?{x:@[f]G+w>Iff<JleK=0L"#PatQf,Uh,V,lXt(YxZ=[];^+m.w_;f$';for(Y in $='_^ZYXVUQPLKJIG@?97%$ ')with(_.split($[Y]))_=join(pop());eval(_)
// TAKE OVER THAT CANVAS
// c = canvas context
d = document;
// ZOOM FACTOR
// Z=3;
// STEP SIZE && ZOOM FACTOR
// z = 3;
W = a.width / 3;
H = a.height / 3;
c.scale(3,3);
// KEY PRESSED
k = 0;
//MMM.. COLORS
//JUNGLE GREEN 2ABB9B
g = '#3BA';
// YELLOW F5C959
// ITS GONNA BE USED DIRECTLY
// w = '#FD6';
// CINNABAR E74C3C
r = '#E54';
// DELTATIMES
N = Date.now;
pN = N();
// RANDOMMMMM!
R = Math.random;
// SCORE
s=0;
// LIVES
v=5;
// CONSTANTS
T=10;
// INIT
x=T, y=H/2;
// fillText shortcut
c.t = c.fillText;
// ENEMIES
e = new Array();
// BULLETS
b = new Array();
// context.fillStyle function
fs=function(l){c.fillStyle=l;}
// DRAW RECTANGLE
dd=function(o,l, w,h) {
fs(l);
c.fillRect(o.x, o.y, w||o.w, h||o.w);
};
// COLLITION
co=function(o,d,Q){
for (var i=0;i<d.length;i++) {
var m = d[i];
if ( (o.x+o.w >= m.x) &&
(o.x <= m.x+m.w) &&
(o.y+o.w >= m.y) &&
(o.y <= m.y+m.w))
{ d.splice(i,1);
// another nasty lenghtsaver
// send a true 3rd param to increment the score
s+=Q;
return true; }
}
return false;
}
// CREATE RECTANGLE
nr=function(x,y,w,l){
return new Object ({x:x || W+R()*150,
y:y || R()*H,
i:0,
w:w || T,
l:0 || l
});
}
// nasty reuse of key to be the index in the loop to fill enemies
while(k<T) {
e.push(nr());
k++;
}
console.log(k);
console.log(e.length);
// GAMELOOP
gl=function() {
requestAnimationFrame(gl);
dd(({x:0,y:0}),'#666',W,H);
if (v<1) {
fs(r);
c.t("score: "+s, T, T);
return
}
// DELTA TIME
D = (N()-pN) / 100;
pN = N();
// SCORE
// fs(g);
dd(({x:5,y:5}), g, 5,5);
c.t(v, T, T);
// fs(r);
dd(({x:5,y:15}), r, 5,5);
c.t(s, T, 20);
// PLAYER
if (k!=0){
if (k==40) y += 3;
if (k==38) y -= 3;
// to shoot: create bullet and reset keypressed
if (k==32) { b.push(nr(x,y,5)); k=0;}
}
// PLAYER BOUNCE WITH THE UPPER/LOWER LIMITS
if (y<0) y=0;
if (y+T>H) y=H-T;
// collition between player and enemies group
var P = ({x:x,y:y,w:T});
if (co(P,e,0)) v--;
dd(P, g);
// ENEMIES
for (var i=0; i<e.length; i++) {
var m = e[i];
m.y -= 3*Math.cos(m.i*D);
m.x -= 3;
m.i++;
// if enemy passed behind or it collides with a bullet, reneweit
if (m.x<0 || co(m,b,1))
e[i]=nr();
dd(m, r);
}
// BULLETS
for (var i=0; i<b.length; i++) {
var m = b[i];
m.x += 3;
// if a bullet passed away, removeit
if (m.x>W) b.splice(i,1);
dd(m, '#FD6');
}
};
gl();
//KEYBOARD HOOKS
d.onkeydown = function(e) {
k = e.keyCode;
}
d.onkeyup = function() {
k = 0;
}