1 line
961 B
JavaScript
1 line
961 B
JavaScript
function generateCollisionGrid(){var e=0;mapData.grid=[];for(var t,n=0;n<mapData.height;n++){mapData.grid[n]=[];for(t=0;t<mapData.width;t++)mapData.grid[n][t]=0}_.each(mapData.collisions,function(e){var t=tileIndexToGridPosition(e+1);mapData.grid[t.y][t.x]=1}),_.each(mapData.blocking,function(e){var t=tileIndexToGridPosition(e+1);mapData.grid[t.y]!==undefined&&(mapData.grid[t.y][t.x]=1)})}function generatePlateauGrid(){var e=0;mapData.plateauGrid=[];for(var t,n=0;n<mapData.height;n++){mapData.plateauGrid[n]=[];for(t=0;t<mapData.width;t++)_.include(mapData.plateau,e)?mapData.plateauGrid[n][t]=1:mapData.plateauGrid[n][t]=0,e+=1}}function tileIndexToGridPosition(e){var t=0,n=0,r=function(e,t){return e==0?0:e%t==0?t-1:e%t-1};return e-=1,t=r(e+1,mapData.width),n=Math.floor(e/mapData.width),{x:t,y:n}}importScripts("../maps/world_client.js","lib/underscore.min.js"),onmessage=function(e){generateCollisionGrid(),generatePlateauGrid(),postMessage(mapData)}; |