Slight minification of my previous version, but the same functionality. Also put into one-liner.
Code: Select all
function S()W,H=G.getDimensions()P,R,T,U,V={x=W/2,y=H-5,w=W/8,h=10},{x=W/2,y=H-18,w=16,h=16},1,0,0;B={[-1]=P,[0]=R}for x=W/20,W,W/10 do for y=10,100,20 do B[#B+1]={x=x,y=y,w=W/10,h=20}end end end;L,Z=love,math;G,K,a,m,M,r,L.resize=L.graphics,L.keyboard.isDown,Z.abs,Z.min,Z.max,Z.random,S;S()function L.draw()if K'a'then P.x=M(W/20,P.x-10)end;if K'd'then P.x=m(W-W/20,P.x+10)end;if K's'and T then T,V,U=nil,-r(4)-4,r(4)-2 end;R.x,R.y=T and P.x or R.x+U,R.y+V;for i=1,#B do b=B[i]X,Y=a(R.x-b.x)-8-b.w/2,a(R.y-b.y)-8-b.h/2;if Y<0 and X<0 then if X>Y then U=-U else V=-V end;B[i]=B[#B];B[#B]=nil;if #B<1 then S()end break end end if R.y>H-15 and a(R.x-P.x)<R.w/2+P.w/2 then V,U=-a(V),m(M(-8,U+r(2)-1),8)end if R.x<5 then U=a(U)elseif R.x>W then U=-a(U)end if R.y<0 then V=a(V)elseif R.y>H+9 then S()end for i=-1,#B do b=B[i]G.rectangle('fill',b.x-b.w/2,b.y-b.h/2,b.w,b.h)end end
Thanks undef for the catch on some extra space!