-
Notifications
You must be signed in to change notification settings - Fork 9
/
annotated.html
74 lines (63 loc) · 2.91 KB
/
annotated.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
<pre id=p><script>
l = "";
for (i in L = [
a = 8191, // #############
b = 4161, // # # #
c = 5981, // # ### # ### #
d = 5125, // # # # #
5493, // # # # ### # #
5397, // # # # # # #
5589, // # # ### # # #
d, // # # # #
c, // # ### # ### #
b, // # # #
a // #############
]
) l += L[i]
.toString(2) // convert to binary
+ 3; // placeholder for \n
l = l.split(""),
x = 76, // players x position
X = 48, // ghost x position
d = // player direction
k = // last keycode
D = // ghost direction
setInterval(onkeydown = function(a) {
k = a ? a.which - 38 : k; // get key code
if (
!a && // skip on key press
x ^ X // check ghost and player collission
) for (
l[x] = 2, // reset cell
l[
x += d = k + 1 >> 2 || 9 & l[ // update player direction
x + ( // update player position
o = // calculate offset
k % 2 ? // horizontal or vertical movement
k : // = horizontal
k * 14 - 14 // = vertical
)
] ? 9 & l[x + d] ? 0 : d : o // detect wall collision
] = 4, // set player at new position
l[X] &= 7, // remove ghost first
b = D % 4,
b = b % 2 ? b - 2 : b * 14 - 14, // calculate walking direction
1 & l[X + b] // if walking into a wall
? D++ // rotate ghost by 90 degree
: X += b // else walk
,
l[X] |= 8, // place ghost
h = i = 0;
153 > i;
)
h += ".# \no" // 0 = . = gold
// 1 = # = wall
// 2 = = empty
// 4 = o = player
// 8 = x = ghost
// 3 = \n placeholder
[l[++i]] // get character
|| "x" // or place ghost
p.innerHTML = h
}, 250)
</script>