-
Notifications
You must be signed in to change notification settings - Fork 0
/
LevelMVC_FacingDirection.js.html
121 lines (94 loc) · 3.07 KB
/
LevelMVC_FacingDirection.js.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Craft Source: LevelMVC/FacingDirection.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: LevelMVC/FacingDirection.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* Enum for facing directions and utilities.
* @namespace
* @property {number} North - Facing north.
* @property {number} East - Facing east.
* @property {number} South - Facing south.
* @property {number} West - Facing west.
*/
const FacingDirection = Object.freeze({
North: 0,
East: 1,
South: 2,
West: 3,
opposite: function (facing) {
switch (facing) {
case FacingDirection.North: return FacingDirection.South;
case FacingDirection.South: return FacingDirection.North;
case FacingDirection.East: return FacingDirection.West;
case FacingDirection.West: return FacingDirection.East;
}
},
left: function (facing) {
return this.turn(facing, "left");
},
right: function (facing) {
return this.turn(facing, "right");
},
turnDirection: function (from, to) {
switch (from) {
case FacingDirection.North: return to === FacingDirection.East ? "right" : "left";
case FacingDirection.South: return to === FacingDirection.West ? "right" : "left";
case FacingDirection.East: return to === FacingDirection.South ? "right" : "left";
case FacingDirection.West: return to === FacingDirection.North ? "right" : "left";
}
},
turn: function (facing, rotation) {
return (facing + 4 + (rotation === "right" ? 1 : -1)) % 4;
},
directionToOffset: function (direction) {
switch (direction) {
case FacingDirection.North: return [0, -1];
case FacingDirection.South: return [0, 1];
case FacingDirection.East: return [1, 0];
case FacingDirection.West: return [-1, 0];
}
},
directionToRelative(direction) {
switch (direction) {
case FacingDirection.North: return "Up";
case FacingDirection.South: return "Down";
case FacingDirection.East: return "Right";
case FacingDirection.West: return "Left";
}
}
});
const {
North,
South,
East,
West,
} = FacingDirection;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="EventType.html">EventType</a></li><li><a href="FacingDirection.html">FacingDirection</a></li></ul><h3>Classes</h3><ul><li><a href="CodeOrgAPI.html">CodeOrgAPI</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a>
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>