eval(eval('\'k=c.width=1e3,l=c.height=600,h=100,n=y=b=x=w=u=t=A=y=x=0,G={},starList=[],o=[],v="#fff",U("mousemove",Je){nVX-25,bVY-10},0),U("click",J){o.length<2&&o.push({x:x+25,y:y+5})},0),R=Jv){return F*(v-30)+15},B=Jc,x,y,s,f){DStyle=c,DRect(x,y,s,f?f:s)},a.font="normal 2em s",a.t=DText,C=set_(J){B("#000",0,0,k,l),Z500)Q||(Q={s:F*3,x:R(k+l),y:R(l)}),B("#fcc",Q.x-=Q.s*3,Q.y,Q.s),Q.x<-h?Q.x=k+F*h:1,i++;x+=(n-x)/20,y+=(b-y)/5,B(v,x,y+4,40,5),B(v,x,y,8),A<t++/h&&(A++,G[d=w++]={x:k+F*h,y:R(l),d:d});for(e in G)p=G[e],x+40>Nx&x<Nx+17&y+4>Ny&y<Ny+17&&(clear_(C),a.t("game over",430,315)),B("#0ff",Nx-=15,Ny,17),Nx<-h&&(HG[Nd],A--);j=[],Zo.length){p=o[i++],B("#f00",Nx+=20,Ny,50,2);if(Nx<k+h){g=u;for(e in G)s=G[e],Nx>s.x-60&Nx<s.x+17&Ny>s.y-1&Ny<s.y+17&&(HG[e],A--,u++);g==u&&j.push(p)}}o=j,DStyle="#ff0",a.t(u,20,40)},31)\'!Da\.fillI!Jfunction\(I!FMath\.random\(\)I!_IntervalI!V=e\.clientI!Uc.addEventListenerI!QstarList\[i\]I!GevilsI!Np\.I!Hdelete I!Zi=0;while\(i<I'.replace(/!(.)(.+?)I/g, ".replace(/$1/g,'$2')")))
/********************************************************************************************************
* spacegame.js
* Author: Camilo Tapia (@camilotapia, http://www.onezerozeroone.com)
*
* A simple space game with parallax stars, starship, enemies and lasers. Simply put,
* everything that is needed for a game in space.
*
* Compressed with uglifyjs and custom compressor (http://www.onezerozeroone.com/js1k/js/compressor.js)
* Damn hard to get it to fit in 1024 bytes.
********************************************************************************************************/
k = c.width = 1000,
l = c.height = 600,
h = 100,
N = y = B = x = W = U = T = currentEvils = y = x = 0,
evils = {},
starList = [],
o = [],
I = "#fff";
// bind the mouse events for movement
c.addEventListener("mousemove",
function(e)
{
N = e.clientX - 25;
B = e.clientY - 10;
}, 0
);
// bind the mouse event for shoting
c.addEventListener("click",
function()
{
if (o.length < 2) o.push({x:x + 25, y:y + 5})
}, 0
);
// random function with some extras to get coordinates insie the screen
R = function(v)
{
return Math.random() * (v - 30) + 15
}
// draw function
draw = function(C, X, Y, S, A)
{
a.fillStyle = C;
a.fillRect(X ,Y, S, A?A:S);
}
// set the font style
a.font = 'normal 2em s';
a.t = a.fillText;
// render everything
renderInterval = setInterval(function()
{
draw("#000", 0, 0, k, l);
// start createing and drawing the stars
i = 0;
while(i < 500)
{
if (!starList[i])
{
starList[i] = {
s: Math.random() * 3,
x: R(k+l),
y: R(l)
}
}
draw("#fcc", starList[i].x -= starList[i].s * 3, starList[i].y, starList[i].s);
starList[i].x < -h ? starList[i].x = k + Math.random() * h:1;
i++;
}
// take crae of the ship
x += (N - x) / 20;
y += (B - y) / 5;
draw(I,x,y+4,40,5);
draw(I,x,y,8);
// create evil ships
if (currentEvils < T++ / h)
{
currentEvils++;
evils[d = W++] =
{
x: k + Math.random() * h,
y: R(l),
d: d
}
}
// have the evil ships killed us?
// also, let's draw evil ships
for (e in evils)
{
p = evils[e];
if (x + 40 > p.x & x < p.x + 17 & y + 4 > p.y & y < p.y + 17)
{
clearInterval(renderInterval);
a.t("GAME OVER", 410, 315);
}
draw(I, p.x -= 15, p.y, 17);
if (p.x < -h)
{
delete evils[p.d];
currentEvils--;
}
}
// draw lasers
j = [];
i = 0;
while(i < o.length)
{
p = o[i++];
draw("#f00",p.x += 20, p.y, 50, 2);
if (p.x < k + h)
{
G = U;
for (e in evils)
{
P = evils[e];
if (p.x > P.x - 60 & p.x < P.x + 17 & p.y > P.y - 1 & p.y < P.y + 17)
{
delete evils[e];
currentEvils--;
U++;
}
}
if (G == U) j.push(p);
}
}
o = j;
// end ship section
// show the counter
a.fillStyle = "#ff0";
a.t(U, 20, 40);
}
, 31);