- Author:
- Gabor Nagy
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/792
- Shortlink:
- https://js1k.com/792
- Blog post:
- please update here!
- Bytes:
- 1021
- Chars:
- 1021
- Submission
u=document;c=u.getElementById("c");M=Math;W=H=c.width=c.height=420;A=35;B=25;I=[];F=[];v=1;t=U=Z=l=k=o=0;
window.setInterval(function(){with(s=c.getContext("2d")){s.E=fillRect;s.T=fillText;fillStyle="#000";E(0,0,W,H);fillStyle="#fff";T("L:"+l,0,8);if(k)T("GAME OVER",W/2-A,H/2);else if(I.length){J=0;K=W;E(t,H-8,A,8);E(t+15,H-12,5,5);for(j=F.length;j--;)with(F[j])y>0?E(x,y-=5,3,7):F.splice(j,1);fillStyle="#15f";Z<H&&U>0?E(U-=10*M.cos(U),Z+=3,5,5):U=Z=0;for(i=I.length;i--;)with(I[i]){w=y+o;for(z=0;z++<A;)"00111111111010110100011001010011111".charAt(z)|0&&E(x+5*(z%7),w+5*(z%5),5,5);x+=v*(M.log(l+1)+1/I.length);
if(w+B>H-13||Z==H&&U>t&&U<t+A)k=1;for(j=F.length;j--;)if(F[j].x>x&&F[j].x<x+A&&F[j].y>w&&F[j].y<w+B){F.splice(j,1);I.splice(i,1);if(U==0)U=t+9}if(x>J)J=x;if(x<K)K=x}if(J>W-A||K<0){v=-v;o+=4}}else{for(j=56;j--;)I.push({x:60*(j%7),y:A*(j%8)+9});o=0;l++}}},1);u.onkeydown=function(a){switch(a.keyCode){case 37:t-=A;break;case 39:t+=A;break;case 32:F.length<4&&F.push({x:t+17,y:H});break;case 38:l++;break}};
- Description
- Space Invaders Game v0.3
The aliens are trying to invade the Earth. Don't let them reach You. Shoot them all and go to the next level where the invasion is faster.
LEFT/RIGHT ARROW: Move left/right
SPACE: Fire
UP ARROW: Next level (more SPEED)
Features
- Groovy drop bomb
- Invaders speed up
- Multiple shots
- 'Game Over'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KUs9eH1pZihKPlctQXx8SzwwKXt2PS12O28rPTR9fWVsc2V7Zm9yKGo9NTY7ai0tOylJLnB1c2goe3g6NjAqKGolNykseTpBKihqJTgpKzl9KTtvPTA7bCsrfX19LDEpO3Uub25rZXlkb3duPWZ1bmN0aW9uKGEpe3N3aXRjaChhLmtleUNvZGUpe2Nhc2UgMzc6dC09QTticmVhaztjYXNlIDM5OnQrPUE7YnJlYWs7Y2FzZSAzMjpGLmxlbmd0aDw0JiZGLnB1c2goe3g6dCsxNyx5Okh9KTticmVhaztjYXNlIDM4OmwrKzticmVha319Ow==
- Original source
// 1k Space Invaders
// A JS1k entry by Gabor Nagy
// email: nagy.gabor.i@gmail.com
// Some random init stuff
u = document;
c = u.getElementById('c');
M = Math;
W = H = c.width = c.height = 420;
A = 35;
B = 25;
I = [];
F = [];
v = 1;
t = U = Z = l = k = o = 0;
window.setInterval(function() {
with(s = c.getContext('2d')) {
s.E = fillRect;
s.T = fillText;
// clearscreen
fillStyle = '#000';
E(0,0,W,H);
fillStyle = '#fff';
// draw level indicator
T('L:'+l,0,8);
// if we are not dead
if (!k){
// and have some invaders
if (I.length) {
// reset max and min x;
J = 0;
K = W;
// draw turet
E(t,H-8,A,8);
E(t+15,H-12,5,5);
// draw fire
j = F.length;
while (j--)
with (F[j])
(y>0) ? E(x,y-=5,3,7) : F.splice(j,1);
// draw bomb
fillStyle = '#15f';
(Z<H && U>0) ? E(U -= 5*M.cos(U),Z+=3,5,5) : U=Z=0 ;
// move invaders
i = I.length;
while (i--)
with (I[i]) {
// draw
w = y+o;
// invaders
// 01110001001011000101001011111111100 v1
// 01010101100111011111001110111111111 v2
// 00110111111010110100011001010011111 v3
z=0;
while(z++<A) {
if ('00111111111010110100011001010011111'.charAt(z)|0) E(x+5*(z%7),w+5*(z%5),5,5);
}
// update position
x += v*(M.log(l+1)+1/I.length);
// player dies when invaders reach earth or turet gots hit by bomb
if ((w+B>H-13) || (Z==H && U>t && U<t+A)) k = 1;
// colission with fire
j = F.length;
while (j--)
if ((F[j].x>x && F[j].x<x+A) && (F[j].y>w && F[j].y<w+B)) {
F.splice(j,1);
I.splice(i,1);
if (U==0) U = t+9;
}
if (x>J) J=x;
if (x<K) K=x;
}
// pingpong invaders
if (J>W-A || K<0) {
v = -v;
o += 4;
}
}
// if there are no invaders
else {
// create invaders
j = 56;
while(j--)
I.push({x:60*(j%7),y:A*(j%8)+9});
// start from the top
o = 0;
// on a faster level
l++;
}
}
// if we are dead
else {
// game over :)
T('GAME OVER',W/2-A,H/2);
}
}
},1);
// Controlls
u.onkeydown = function(event) {
switch (event.keyCode) {
// arrow left -> move turet left
case 37:
t -= A;
break;
// arrow right -> move turet right
case 39:
t += A;
break;
// space -> fire
case 32:
(F.length<4) && F.push({x:t+17,y:H});
break;
// arrow up -> more speed
case 38:
l++;
break;
}
}
// a wicked tune for playing a fast game: http://www.youtube.com/watch?v=GSR_g3thb24