|
<!DOCTYPE html><html><head><style>#g{background:black;margin:auto;display:block;}</style></head><body><canvas id="g" width="640px" height="480px"></canvas></body><script>const area_w=640,area_h=480,tile_sz=32,area_tile_w=area_w/tile_sz,area_tile_h=area_h/tile_sz,padding=tile_sz/4,food_padding=tile_sz/8,max_snake=area_tile_w*area_tile_h,D_UP=38,D_DOWN=40,D_LEFT=37,D_RIGHT=39;var canvas=document.getElementById("g"),ctx=canvas.getContext("2d"),phys_timer=null,dir=0,started=!1,pos=[{x:Math.round(area_tile_w/2),y:Math.round(area_tile_h/2)}],food=null,ctrl_stack=[],forgive=!1;function pos_equal(e,a){return e.x==a.x&&e.y==a.y}function place_food(){var e;do{food={x:Math.floor(Math.random()*area_tile_w),y:Math.floor(Math.random()*area_tile_h)},e=!1;for(var a=0;a<pos.length;a++)if(pos_equal(pos[a],food)){e=!0;break}}while(e)}function draw_internal(){if(ctx.clearRect(0,0,area_w,area_h),ctx.fillStyle="white",pos.length>1)for(var e=1;e<pos.length;e++){var a=pos[e],t=pos[e-1],i=Math.min(a.x,t.x),_=Math.max(a.x,t.x),o=Math. |