-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
61 lines (59 loc) · 1.08 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
let map = {
walls: [
{
x: 0,
y: 0,
width: 10,
height: 110
},
{
x: 100,
y: 0,
width: 10,
height: 110
},
{
x: 0,
y: 0,
width: 110,
height: 10
},
{
x: 0,
y: 100,
width: 110,
height: 10
},
{
x: 25,
y: 40,
width: 20,
height: 45
}
],
draw: function(scale = 1, xshift = 0, yshift = 0) {
ctx.fillStyle = "gray";
for (var i = 0; i < map.walls.length; i++) {
ctx.fillRect(
map.walls[i].x*scale+xshift,
map.walls[i].y*scale+yshift,
map.walls[i].width*scale,
map.walls[i].height*scale
);
ctx.fillStyle = "yellow";
ctx.fillRect(
player.x*scale+xshift,
player.y*scale+yshift,
5*scale, 5*scale
);
}
},
touchingWalls(object) {
for (var i = 0; i < map.walls.length; i++) {
if (isTouching(object, map.walls[i])) {
return true;
}
}
return false;
}
};