-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.js
57 lines (54 loc) · 1.55 KB
/
room.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
define([],
function() {
// Return an object representing the walls of this room.
// Its keys are 'north', 'south', 'east', and 'west'.
//
// Each of these contains an object with the position
// (perpendicular to the wall) and length and start coordinate
// (parallel) of that wall, plus the direction it runs from:
// 'east' for walls running east-west (keys 'north' and 'south',
// and 'north' for ralls running north-south).
// Walls also define 'perpendicularAxis' (used for 'position'),
// and 'parallelAxis' (used for 'start'); each one is either 'x' or 'y'.
//
// TODO: it's more general to represent directions as unit vectors rather than names, and avoids all this case-by-case stuff.
walls = function(room) {
return {
north : {
parallelAxis: 'x',
perpendicularAxis: 'y',
position: room.y,
start: room.x,
length: room.width,
runsFrom: 'west'
},
south : {
parallelAxis: 'x',
perpendicularAxis: 'y',
position: room.y + room.height,
start: room.x,
length: room.width,
runsFrom: 'west'
},
east : {
parallelAxis: 'y',
perpendicularAxis: 'x',
position: room.x + room.width,
start: room.y,
length: room.height,
runsFrom: 'north'
},
west : {
parallelAxis: 'y',
perpendicularAxis: 'x',
position: room.x,
start: room.y,
length: room.height,
runsFrom: 'north'
}
};
};
return {
walls: walls
};
});