Skip to content

Instantly share code, notes, and snippets.

@zanbaldwin
Last active March 15, 2017 13:22
Show Gist options
  • Save zanbaldwin/2f8f35935b5b7ef2413a to your computer and use it in GitHub Desktop.
Save zanbaldwin/2f8f35935b5b7ef2413a to your computer and use it in GitHub Desktop.
Space Invaders in 17 Lines of Nostalgic Code
p=389;$=l=t=0;c=" _ ";
onkeydown=function(e){
(k=e.which)==39?p++:k==37?p--:!l&&(l=p)
};
setInterval(function(){
_="<pre>";l&&(l-=20)<0&&(l=0);
for(i=0;i<400;i++){
if(i%20==0)_+="\n";
if(~b[n="indexOf"](l))b.splice(b[n](l),1),$+=25,l=0;
if(~b[n](p))p=n,b=[],c="xxx";
_+=i==p?"oIo":~b[n](i)?".#.":i==l&&l?" | ":c
}
document.body.innerHTML=_+="\nP "+$;
for(i in b)b[i]+=t^0&&t%5e3==0?20:t%2e3==0?1:t%1e3==0&&(-1);
t+=o
},o=50);
for(b=[],j=2;j<136;j+=2)b.push(j),j==14&&(j=41)||j==55&&(j=80)||j==94&&(j=121)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment