_='bWid^,fHX;a.wid^=b;a.hX=f;=16;gQf/NkQgNlV,mV,nfont=g+"px Arial";rtt<;t_uQ*(-1))+1,vww<u;w_)vK!5*)rK[u,v]$x=Da(8,8Ny=x.da,zz<yz+=4AQ256*>]=A;>+1]QA>+2]>+3]=255}Bitmap(x).^G(|pt=c@ePtern%,"@pe"pt$$ C|dd<rd_)hh<0];h_pV-0])+h,q=p,D=d~eqJ,DJd==mjp==ljj(=nUj(q=d,?FFD7"?"9Z2*Z-,$} E(e=l,d=m~?FF"eJ,dJ$ B|"rgb( 0)"b,fC%E(?FF"~Text(ne$$`cumGt.addEvGtListGer("key`wn",|switch%.keyCodeY37:--l 38:--m 39:lU 40:mU}}fillparseInt(win`w.@questAnimionFrame((B(,beginPh(Nellipse(pJ+k,qJ+k/functionfor(Style=Mh.ran`m() ;b@ak;YROWS1][h],strokevar at=0;~Rect(=sc@G.avail);Mh.PI){c@eImage,gr[d][/20,00.lGg^;N()()c.$)}%(e>y[z?"#@reGenJ*gK.push(N),Q=U+=1V=XeightYcase Z/3,^th_++`doj&&|%~;=[],';for(Y in $='~|j`_^ZYXVUQNKJG@?>%$ ')with(_.split($[Y]))_=join(pop());eval(_)
var sw = screen.availWidth;
var sh = screen.availHeight;
a.width = sw;
a.height = sh;
ROWS = 16;
var st = parseInt(sh/ROWS);
var st2 = parseInt(st/2);
var ux = ROWS/2;
var uy = ROWS/2;
var coins = 0;
c.font=st+"px Arial";
var mine = [];
for (let i=0; i < ROWS; i++){
let cells = parseInt(Math.random()* (ROWS - 1)) + 1;
let line = [];
for (let j=0; j < cells; j++) {
line.push(!parseInt(Math.random() * 5));
}
mine.push([cells, line]);
}
var id = c.createImageData(8, 8);
var data = id.data;
for (let i = 0; i < data.length; i += 4) {
let mcolor = parseInt(Math.random() * 256);
data[i] = mcolor;
data[i+1] = parseInt(mcolor/2);
data[i+2] = 0;
data[i+3] = 255;
}
//c.putImageData(id, 0, 0);
createImageBitmap(id).then(function(bi) {
pt = c.createPattern(bi, "repeat");
window.requestAnimationFrame(function(){
render(pt);
});
});
function drawCoin(x, y) {
c.fillStyle = "#FFD700";
c.strokeStyle = "#000000";
c.beginPath();
c.ellipse((x*st) + st2, (y*st) + st2, st/9, st/3, 0, 0, 2 * Math.PI);
c.fill();
c.stroke();
c.beginPath();
c.ellipse((x*st) + st2, (y*st) + st2, st/ROWS, st/3, 0, -Math.PI/2, Math.PI/2);
c.fill();
c.stroke();
}
function drawTile(x, y, pt) {
c.fillStyle=pt;
// console.log(x * st, y * st);
c.fillRect(x * st, y * st, st, st);
}
function drawMine(pt) {
for (let i=0; i<mine.length; i++) {
for (let j=0; j<mine[i][0]; j++) {
let x = (ROWS/2) - parseInt(mine[i][0]/2) + j;
drawTile(x, i, pt);
// clean the coin where the dude is
if (i == uy && x == ux) {
if (mine[i][1][j]) {
mine[i][1][j] = 0;
coins += 1;
};
}
if (mine[i][1][j]) {
drawCoin(x, i);
}
}
}
}
function drawDude(x, y) {
c.fillStyle="#FF0000";
c.fillRect(x * st, y*st, st, st);
}
function render(pt) {
c.fillStyle = 'rgb(0, 0, 0)';
c.fillRect(0, 0, sw, sh);
drawMine(pt);
drawDude(ux, uy);
c.fillStyle = '#0000FF';
c.fillText(coins, st,st);
window.requestAnimationFrame(function() {
render(pt);
});
}
document.addEventListener("keydown", function(e) {
switch(e.keyCode) {
case 37: // left arrow
ux -= 1;
break;
case 38: // up arrow
uy -= 1;
break;
case 39:
ux += 1;
break;
case 40:
uy += 1;
break;
}
});