1K Breakout challenge

Show off your games, demos and other (playable) creations.
User avatar
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

Re: 1K Breakout challenge

Post by bakpakin » Fri May 20, 2016 4:41 am

Attempt 2: 887 876 bytes

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
As a side note, I wonder if anybody is able to implement some sort of continuous collision detection in the their entry. That would be really cool and make the games more playable (no weird bounces).

Thanks undef for the catch on some extra space!
Last edited by bakpakin on Fri May 20, 2016 8:35 am, edited 1 time in total.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()

User avatar
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin

Re: 1K Breakout challenge

Post by undef » Fri May 20, 2016 7:04 am

Below 900 bytes, you forgot to delete some spaces next to braces though!
twitter | steam | indieDB

Check out quadrant on Steam!

User avatar
Posts: 51
Joined: Thu Jun 18, 2015 9:02 am

Re: 1K Breakout challenge

Post by 0x72 » Fri May 20, 2016 10:08 am

V2 (aka shamelessly stealing ideas from others :P)

- no dt
- update merged into draw
- drawing and updating bricks in one loop
- only resizable with conf.lua
- inline one a few variables
- controlled with A and D instead of arrows
- more interesting map :)
- remove newline from the last line (does it counts?)

count: 845 805 (without conf.lua)

Code: Select all

R,t=g.rectangle,function(l,r,w,h)return x>l and x<l+w and y>r and y<r+h end
function D()X,B,x,d,e=325,{},420,1,-1;y=x
for i=45,7500,60 do B[#B+1]={x=i%750,y=m.floor(i/750+1)*30}end
end;D()function L.draw()x,y=x+d*3,y+e*3
if x>800 or x<0 then d=d*-1 end
if y<0 then e=e*-1 elseif y>700 then D()end
if k'a'then X=m.max(X-8,0)end
if k'd'then X=m.min(X+8,650)end
if t(X,592,150,50)then e=e*-1;d=(d+(((x-X)/150-0.5)*2))/2;end
c,o=g.getDimensions()g.scale(c/800,o/600)for i=#B,1,-1 do b=B[i]
R(F,b.x,b.y,50,20)if t(b.x,b.y,50,20)then
A=m.atan2(x-b.x-25,y-b.y-10)if -v>A and A>-1.9 then d=-a(d)elseif v<A and A<1.9 then d=a(d)else e=(a(A)<v and 1 or-1)*a(e)end
end;if#B==0 then D()end
conf.lua (+45)

Code: Select all

function love.conf(t)t.window.resizable=1 end

Posts: 67
Joined: Fri Mar 07, 2014 8:16 pm

Re: 1K Breakout challenge

Post by WetDesertRock » Fri May 20, 2016 7:41 pm

Alright, I stripped down my version.

Extra credit done:
  • should scale and be playable on different resolutions (with a conf.lua not included in the script)
  • locals
Non minified (1165):

Code: Select all

local l,lk,objheight,m,s,dx,dy, b,p,sx,sy,G, t,temp = love,love.keyboard.isDown,.05, math, 0.4, -1,-1

function l.load()
  G = {{x=.5,y=.9, .15},{x=.5,y=.8, .05}}

  b = G[2]
  p = G[1]

  function b.c(a,o)
    return a.x + a[1] > o.x and a.x < o.x + o[1] and m.abs(a.y - o.y) < objheight

  for x=0,9 do
    for y=0,3 do
      table.insert(G, {x=x*.1,y=(y*(objheight+.01)) + .05, .09})

function l.draw()
  -- Update
  t = 0.017

  b.x = b.x + dx*t * s
  b.y = b.y + dy*t * s

  if b.x < 0 then
    dx = m.abs(dx)
  elseif b.x > 0.95 then
    dx = -m.abs(dx)

  if b.y < 0 then
    dy = 1
  elseif b.y > 1 then
    l.load() -- reset

  t = 0
  if lk'a' then
    t = -0.01
  elseif lk'd' then
    t = 0.01
  p.x = m.min(m.max(p.x+t,-.1),.9)

  if b:c(p) then
    t = ((b.x + .02) - (p.x + .07))/.2
    dx = t*2
    dy = -1

  for i=#G,3,-1 do
    if b:c(G[i]) then
      dy = 1

      if #G == 2 then
  sx,sy=love.window.getMode( )

  -- Draw
  for _,v in pairs(G) do
    love.graphics.rectangle('fill', v.x*sx,v.y*sy, v[1]*sx, objheight*sy)

Luamin (796):

Code: Select all

local a,b,c,d,e,f,g,h,i,j,k,l,m,n=love,love.keyboard.isDown,.05,math,0.4,-1,-1;function a.load()l={{x=.5,y=.9,.15},{x=.5,y=.8,.05}}h=l[2]i=l[1]function h.c(o,p)return o.x+o[1]>p.x and o.x<p.x+p[1]and d.abs(o.y-p.y)<c end;for q=0,9 do for r=0,3 do table.insert(l,{x=q*.1,y=r*(c+.01)+.05,.09})end end end;function a.draw()m=0.017;h.x=h.x+f*m*e;h.y=h.y+g*m*e;if h.x<0 then f=d.abs(f)elseif h.x>0.95 then f=-d.abs(f)end;if h.y<0 then g=1 elseif h.y>1 then a.load()end;m=0;if b'a'then m=-0.01 elseif b'd'then m=0.01 end;i.x=d.min(d.max(i.x+m,-.1),.9)if h:c(i)then m=(h.x+.02-(i.x+.07))/.2;f=m*2;g=-1 end;for s=#l,3,-1 do if h:c(l[s])then g=1;table.remove(l,s)if#l==2 then a.load()end end end;j,k=love.window.getMode()for t,u in pairs(l)do love.graphics.rectangle('fill',u.x*j,u.y*k,u[1]*j,c*k)end end

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 5 guests