for(_='32~~*kZ=[]Y640X||W++)V>l;lVU=max(TRect(HJSON.G+~F,0Efor(D>k;kVD);=v+.1c.fill*=.98;[k][l]()=>{C1024&&16J[w.keyCode]=w=>{=(hh=0),gg=0))O[N][r]O[m][n]b.onkey=-1;1>=random()J[3 .push(=0;,,Xmin(l64UHStyle="#Y;Dk96d=e=f=g=hJY;A=I=3072;OOmY),m(.5>W0==lW87<kW63==l)XDm2>m;mV{y=Gparse(Gstringify(O)Dk=1;95l=1;63U{rDnn;nVDpp;pVr+=!!O[k+n][l+p];y=(4<r)**5+(r-1)*(4<r4>rd=t=~*l,e=u=Z)}O=y}};A(downW!w.repeat};up0};setInterval(++;c.clearH0Ey0<OX>abs(Z-e)y[~*l,Z,k,l]t+=g;u+=h;h+=.15;hgr=vD[k,l,m,n]of y)p=E<p~1",c.globalAlpha=1,.6+.05*p),k-d,l-e,33,33)),t>k-t<kFu>l-u<lFu+-l,l-uF)>t+-k,k-tF)?(8<t-k?(t=kFE>:(t=k-E<,[N,r]=[m,n]):8<u-l?(u=lFE>--):(u=l-E<f=9,v=1.5,g*=.5)0<f-- 8] 8]=f=0,h-=6 7]g- 9]g+( 7]W 9])rT0,-.5)dTt-512Ed=d,e=u-~0,24~I=I-.1-C//~,uF0x=I-9*sin(C/~080";t-d,u-e,,f40";0,x-eif(0>uWu+>x)return A()},20)';G=/[^ -CI-S[-}]/.exec(_);)with(_.split(G))_=join(shift());with(Math)eval(_)
// Lava Mine by fishtastic for js1k2019
// Compressed with closure compile + regpack js
// http://siorki.github.io/regPack.html
// aA a canvas
// bB body. B board of blocks as a 2D arr
// cC c canvas context,
// dD D, copied board as an array of [x,y,i,j]
// eE
// fF F frame counter
// gG
// hH H viewport height
// iI i temp variable, I = init
// jJ j temp variable, J = jump allowed
// kK k temp variable, K key input
// lL l temp variable, L = lava height;
// mM m temp variable
// nN n temp variable
// oO o temp variable
// pP p player on top of platform, P = player radius
// qQ
// rR R radius of block
// sS S start the main loop
// tT
// uU
// vV v lava height (temp)
// wW W width (in number of blocks)
// xX x playerX, X velocityX
// yY y playerY, Y velocityY
// zZ z camera x, camera y
// This is just for closure compiler.
var z,Z,J,X,Y,i,j,k,l,g,m,n,o,x,y,p,v,D,G,B,I,L,F,K;
z=Z=J=X=Y=0;
K = [];
const W = 64;
const H = 32*3;
// Block radius in pixels
const R = 32; // blocks radius
const P = R/2; // player block radius
I = () => {
F = 0;
L = H*R;
B=[];
for (i=0;i<H;i++) {
B.push(k=[]);
for(j=0;j<W;j++)
k.push((Math.random()<.5 || j==0 || i>H-9 || j==W-1)&&640);
}
for (k=0;k<2;k++) {
D=JSON.parse(JSON.stringify(B));
for (i=1;i<H-1;i++) {
for (j=1;j<W-1;j++) {
o=0;
for (l=-1;l<=1;l++) {
for (m=-1;m<=1;m++) {
o+=!!B[i+l][j+m];
}
}
// Add opacity to generated blocks
D[i][j]=(o>4)*Math.random()*5+(o-1)*(o>4);
if (o<4) {
z=x=j*R;
Z=y=i*R;
}
}
}
B=D;
}
}
I();
b.onkeydown=e=>{
K[e.keyCode]=K[e.keyCode]||!e.repeat;
};
b.onkeyup=e=>{
K[e.keyCode]=0;
};
setInterval(() => {
F++;
c.clearRect(0,0,1024,640);
D=[];
for (i=0;i<H;i++)
for(j=0;j<W;j++)
if (B[i][j]>0 && Math.abs(i*R-Z)<640) // optimization to not render off screen stuff
D.push([j*R,i*R,i,j]);
x+=X;
y+=Y;
// Gravity
Y+=.15;
// Air resistance/friction
Y*=.98;
X*=.98;
// Player on a platform/friction bonus
p=0;
// Okay to dig left/right
o=0;
// Main logic loop
for ([i,j,k,l] of D) {
m=B[k][l];
if (m>0) {
c.fillStyle = "#321";
c.globalAlpha = Math.min(1,.6+m*.05);
c.fillRect(i-z,j-Z,R+1,R+1);
}
// Has collision
if (x>i-P && x<i+R && y>j-P && y<j+R) {
// Resolve collision.
if (Math.min(y+P-j, j-y+R) > Math.min(x+P-i, i-x+R)) {
if (x-i > R/2-P/2) {
// Right side
x = i+R;
if (X<0) X = 0;
} else {
// Left
x = i-P;
if (X>0) X = 0;
}
[n,o]=[k,l];
} else {
if (y-j > R/2-P/2) {
// Bottom
y = j+R;
if (Y<0) Y = 0;
B[k][l]--; // bumping on block from the bottom digs it little a bit
} else {
// Top
y = j-P;
if (Y>0) Y = 0;
J=9;
p=1.5;
X*=.5; // Friction
}
}
}
}
// Jump
if(J-->0 && K[38]) {
K[38]=J=0;
Y-=6;
}
if(K[37]) { // left
X-=p+0.1;
}
if (K[39]) { // right
X+=p+0.1;
}
if ((K[37] || K[39]) && o) {
// dig
B[n][o] = Math.max(0, B[n][o]-.5);
}
// Camera
z=Math.max(x-1024/2,0);
z=Math.min(z,W*R-1024);
Z=Math.min(y-640/2,H*R-640);
// Lava
L = Math.min(L-.1-F/1024/32, y+320);
v = L - Math.sin(F/32)*9;
c.fillStyle = "#080";
c.fillRect(x-z,y-Z,P,P);
c.fillStyle = "#f40";
c.fillRect(0,v-Z,1024,640);
if (y<0 || y+P>v) return I(); // dead or win from lava
},20);