-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame-min.lua
2 lines (2 loc) · 1.31 KB
/
game-min.lua
1
2
-- 1318 bytes of fun!
M=math _=love c=_.graphics l=c.getDimensions y="fill"E=_.keyboard.isDown K=c.circle D=c.setColor z=1/60 o=0 q={o={0,0},N={0,0},f={0,0},v={0,0}}C=_.math.newRandomGenerator(42)function F(n)b={}for i=1,n do w=300 b[#b+1]={C:random(-w,w),C:random(-w,w)}end b.m=n return b end e=F(1)function j(v)return (v[1]^2+v[2]^2)^.5 end function u(v)x=j(v)if x==0 then return{0,0}end return{v[1]/x,v[2]/x}end function B(a,b)return{a[1]+b[1],a[2]+b[2]}end function v(a,s)return{a[1]*s,a[2]*s}end function _.update(t)o=o+t while o>=z do o=o-z a=v(q.f,.5)q.v=B(q.v,q.f)q.v=v(u(q.v),M.min(j(q.v),200))q.f={0,0}A=B(q.o,q.v)I,H=l()I,H=I/2-20,H/2-20 if A[1]>I or A[1]<-I then q.v[1]=-q.v[1]A=B(q.o,q.v)end if A[2]>H or A[2]<-H then q.v[2]=-q.v[2]A=B(q.o,q.v)end q.N=v(q.o,1)q.o=A G=j(q.v)*M.exp(-6*z)q.v=v(u(q.v),G)for i=#e,1,-1 do L=j{e[i][1]-q.o[1],e[i][2]-q.o[2]}if L<30 then table.remove(e,i)end end if #e<1 then e=F(M.ceil(e.m*1.5))end end x={E"right"and 1 or 0,E"down"and 1 or 0} if E"up"then x[2]=x[2]-1 end if E"left"then x[1]=x[1]-1 end x=u(x)q.f=B(q.f,v(x,50*t))end c.setBackgroundColor(.25,.25,.25)function _.draw()w,h=l()w,h=w/2,h/2 c.translate(w,h)for i=1,#e do d=e[i]D(0,.5,1)K(y,d[1],d[2],10)end k=o/z t=B(v(q.N,1-k),v(q.o,k))D(1,0,0)K(y,t[1],t[2],20)D(1,1,1)c.print(("(%d,%d)\n%d m/s"):format(q.v[1],q.v[2],j(q.v)),-w,-h)end