forked from MasterIV/ggj2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
71 lines (61 loc) · 1.41 KB
/
map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
*
* @param mapData
* @param objectData
* @returns {boolean}
*/
function renderMap(mapData, objectData)
{
var map = "";
var tiles = getTilesPosition(mapData);
var blockers = getTileIDsForBlockers(objectData);
var i = 0;
var blocker;
tiles.forEach(function (tile) {
blocker = false;
blockers.forEach(function(id){
if (id == i)
{
blocker = true;
}
});
map = map + "<div data-blocker='"+ blocker +"' style='background-position: -"+ (tile['left'] - 32) +"px -"+ tile['top'] +"px'></div>";
i++;
});
$('#map').append(map);
}
/**
*
* @param objectData
*/
function getTileIDsForBlockers(objectData)
{
var tileIDs = [];
var i = 0;
objectData.forEach(function (object) {
if(object != 0) {
tileIDs.push(i);
}
i++;
});
return tileIDs;
}
/**
* @returns {Array} waypointsWithPosition
* @param tiles
*/
function getTilesPosition(tiles)
{
var tileHeight = 32;
var tileWidth = 32;
var tilesWithPosition = [];
tiles.forEach(function(tile) {
var multiplikator = Math.floor((tile / 20));
var positions = [];
positions['id'] = tile;
positions['top'] = tileHeight * multiplikator;
positions['left'] = tile%20 * tileWidth;
tilesWithPosition.push(positions);
});
return tilesWithPosition;
}