927 926 920 917 912 898
(only 3rd "Extra credit" though)
Code: Select all
L,m=love,math
n,N,a=m.min,m.max,m.abs
g,k=L.graphics,L.keyboard.isDown
R=g.rectangle
H,S,s,T,W=50,500,200,595,150
t=function(l,r,w,h)return not(x<l or x>l+w or y<r or y>r+h)end
w,h=50,20
v,u=1.19,1.95
F='fill'
function D()
X,B,x,y,d,e=325,{},410,500,1,-1
for i=45,750,60 do for j=50,300,30 do B[#B+1]={x=i,y=j}end end
end;D()
function L.update(q)
x,y=x+q*d*s,y+q*e*s
if x>800 or x<0 then d=d*-1;x=x+d*9 end
if y<0 then e=e*-1;y=y+e*9 elseif y>700 then D()end
if k'left'then X=N(X-q*S,0)end
if k'right'then X=n(X+q*S,650)end
if t(X,T,W,H) then e=e*-1; d=(d+(((x-X)/W-0.5)*2))/2; end
for i=#B,1,-1 do b=B[i];if t(b.x,b.y,w,h)then
A=m.atan2(x-b.x-w/2,y-b.y-h/2)
if -v>A and A>-u then d=-a(d)elseif v<A and A<u then d=a(d)else e=(a(A)<v and 1 or -1)*a(e)end
table.remove(B,i)
end end
if#B==0 then D()end
end
function L.draw()
R(F,x-4,y-4,8,8)
R(F,X,T,W,H)
for i=1,#B do R(F,B[i].x,B[i].y,w,h)end
end
resizable version:
972 968
Code: Select all
L,m=love,math
n,N,a=m.min,m.max,m.abs
g,k=L.graphics,L.keyboard.isDown
R=g.rectangle
H,S,s,T,W=50,500,200,595,150
t=function(l,r,w,h)return not(x<l or x>l+w or y<r or y>r+h)end
w,h=50,20
v,u=1.19,1.95
F='fill'
L.window.setMode(800,600,{resizable=0})function D()X,B,x,y,d,e=325,{},410,500,1,-1
for i=45,750,60 do for j=50,300,30 do B[#B+1]={x=i,y=j}end end
end;D()function L.update(q)x,y=x+q*d*s,y+q*e*s
if x>800 or x<0 then d=d*-1;x=x+d*9 end
if y<0 then e=e*-1;y=y+e*9 elseif y>700 then D()end
if k'left'then X=N(X-q*S,0)end
if k'right'then X=n(X+q*S,650)end
if t(X,T,W,H)then e=e*-1; d=(d+(((x-X)/W-0.5)*2))/2; end
for i=#B,1,-1 do b=B[i];if t(b.x,b.y,w,h)then
A=m.atan2(x-b.x-w/2,y-b.y-h/2)if -v>A and A>-u then d=-a(d)elseif v<A and A<u then d=a(d)else e=(a(A)<v and 1 or -1)*a(e)end
table.remove(B,i)end end
if#B==0 then D()end end
function L.draw()c,o=g.getDimensions()g.scale(c/800, o/600)R(F,x-4,y-4,8,8)R(F,X,T,W,H)for i=1,#B do R(F,B[i].x,B[i].y,w,h)end end