I'm happy to have something to submit to the JS1024 2024 competition. I just found out about the competition and realized that I have something to submit even if it's not aligned with the theme. I'm pretty sure I started and finished the project during the competition. See my submission here.
Title: 🏗 Stacking Game
Short Description: Press Space or tap on mobile! See how high you can go in this stacking game!
<canvas id=c><script>K=c.width=c.height=1e3,e=c.getContext`2d`,n=0,x=0,Z=100,i=0,w=0,h=0,l=!0,s=[],d={},f=0,y=_=>{h=!1,s=[{x:(c.width-700)/2,y:c.height-Z,w:700}],d={x:-s[0].w,y:c.height-200,w:700}},a=(t,n,x=Z)=>{e.fillStyle=t.c,e.fillRect(t.x,n||t.y,t.w,x)},r=_=>{if(h)return void y();const t=s[0],e=s.length;d.x<=t.x&&d.x+d.w>=t.x?(d.w=t.w-(t.x-d.x),s.unshift({...d,x:t.x}),e<=5&&(d.y-=Z)):d.x>t.x&&d.x<t.x+t.w?(d.w=t.x+t.w-d.x,s.unshift({...d}),e<=5&&(d.y-=Z)):h=!0,e-1>f&&(f=e-1),d.x=Math.random()>.5?K:-d.w;};ontouchstart=r;onkeydown=t=>" "===t.key&&r(),y();g=t=>{const n=s.length;c.width|=0,(t=>{let e,n=Z,x=d.y;t&&(x=300,t>8&&(n=800/t));for(t=0;t<s.length;t++)e=x+n*(t+1),a(s[t],e,n)})(h&&n),a(d),e.font="1in'",e.fillText("Score: "+(n-1)+", Best: "+f,Z,Z),w=t-i,h||(d.x>c.width?l=!1:d.x<-d.w&&(l=!0),d.x+=K*(l?1:-1)*w),i=t},u=e=>{requestAnimationFrame(u),e<x-2||(x=Math.max(x+K/60,e),t=n/60,60*t|0!=n++&&(t+=1e-6),g(t))};u()</script><style>html,body{height:100%;margin:0}#c{max-height:100%;max-width:100%}
data:text/html,<canvas id=c><script>K=c.width=c.height=1e3,e=c.getContext`2d`,n=0,x=0,Z=100,i=0,w=0,h=0,l=!0,s=[],d={},f=0,y=_=>{h=!1,s=[{x:(c.width-700)/2,y:c.height-Z,w:700}],d={x:-s[0].w,y:c.height-200,w:700}},a=(t,n,x=Z)=>{e.fillStyle=t.c,e.fillRect(t.x,n||t.y,t.w,x)},r=_=>{if(h)return void y();const t=s[0],e=s.length;d.x<=t.x&&d.x+d.w>=t.x?(d.w=t.w-(t.x-d.x),s.unshift({...d,x:t.x}),e<=5&&(d.y-=Z)):d.x>t.x&&d.x<t.x+t.w?(d.w=t.x+t.w-d.x,s.unshift({...d}),e<=5&&(d.y-=Z)):h=!0,e-1>f&&(f=e-1),d.x=Math.random()>.5?K:-d.w;};ontouchstart=r;onkeydown=t=>" "===t.key&&r(),y();g=t=>{const n=s.length;c.width|=0,(t=>{let e,n=Z,x=d.y;t&&(x=300,t>8&&(n=800/t));for(t=0;t<s.length;t++)e=x+n*(t+1),a(s[t],e,n)})(h&&n),a(d),e.font="1in'",e.fillText("Score: "+(n-1)+", Best: "+f,Z,Z),w=t-i,h||(d.x>c.width?l=!1:d.x<-d.w&&(l=!0),d.x+=K*(l?1:-1)*w),i=t},u=e=>{requestAnimationFrame(u),e<x-2||(x=Math.max(x+K/60,e),t=n/60,60*t|0!=n++&&(t+=1e-6),g(t))};u()</script><style>html,body{height:100%;margin:0}%23c{max-height:100%25;max-width:100%25}
The readable code is what I started with and then used [link]https://xem.github.io/terser-online/[/link] to make my initial compression. Then started refactoring the code and removing features to make it all fit within 1024 bytes.
So my "readable code" has more features such as colors and a random direction in which the bar will float from.
Follow me: [link] https://x.com/lewdev[/link]
My projects: [link]https://lewdev.github.io[/link]
I'm happy to have something to submit this year. I just found out about the competition and realized that I have something to submit even if it's not aligned with the theme.
- Xem's Terser Online This helped a lot
- Terser REPL (I just discovered this and I'm leaving it here for reference)
- nekoground Free anonymous HTML hosting service