# Asteroids under 1 kB

I have participated a challenge where the goal was to create an asteroids game under 1 kilobyte or less.

The 1K Asteroids Challenge was organised on the forums of the Love2D game engine, and it took place in December, 2016.

## Features & controls

• The entire game is only 663 bytes long
• Asteroids, the player ship and bullets
• Restarts when you destroy all the asteroids
• Bullets have a limited range
• Framerate independent movement
• Randomly generated asteroid shapes
• Use WASD to move, hold K key to shoot

I only provide the Love2D version of this minigame. In order to play it, you will need to install Love2D on your computer.

## Source code

I think it’s amazing how much the source code can be compressed in Lua. Lo and behold, this is the whole source code of the game:

```L=love;G=L.graphics;I=L.keyboard.isDown;Y=L.load;M=math;C=M.cos;S=M.sin;R=M.random;
T=M.pi;Z=pairs;E=20;K=70;Q=300;W,H=800,600;J=0;function L.draw()if J<1 then P={q=Q,
x=W/2,y=H/2,r=0,s=0,p={-5,-5,-5,5,9,0,-5,-5}}O={P}for a=2,K do p={-5,-9,5,-9,9,1,0,
9,-9,1}for a=1,#p do p[a]=p[a]-3+R(6)end;p,p=p,pO[a]={q=K,x=R(W),y=
R(H),r=R(T*2),s=R(K),p=p}end end;d,J=L.timer.getDelta(),0;for b,c in Z(O)do if c.q>
0 then if c.q==Q then O[#O+1]=R(E)<6 and I"k"and{q=1,x=P.x,y=P.y,r=P.r,s=Q,p={0,0,
9,0}}or nil;c.r=c.r+d*3*(I"d"and 1 or I"a"and-1 or 0)c.s=c.s+d*K*(I"w"and 1 or I"s"
and-3 or 0)c.s=M.max(0,M.min(Q,c.s))elseif c.q==K then J=(c.x-P.x)^2+(c.y-P.y)^2<
E^2 and-Q or J+1 else c.q=c.q-d;for b,e in Z(O)do e.q=e.q==K and(c.x-e.x)^2+(c.y-
e.y)^2<E^2 and 0 or e.q end end;c.x=(c.x+C(c.r)*c.s*d)%W;c.y=(c.y+S(c.r)*c.s*d)%H;
G.origin()G.translate(c.x,c.y)G.rotate(c.r)G.line(c.p)end end end```