forked from AlexNisnevich/untrusted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08_intoTheWoods.jsx
123 lines (102 loc) · 3.51 KB
/
08_intoTheWoods.jsx
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
122
123
#BEGIN_PROPERTIES#
{
"version": "1.2",
"commandsIntroduced":
["map.getObjectTypeAt", "player.getX", "player.getY",
"map.refresh"],
"mapProperties": {
"allowOverwrite": true
},
"music": "Night Owl"
}
#END_PROPERTIES#
/*******************
* intoTheWoods.js *
*******************
*
* Ah, you're out of the woods now. Or into the woods, as the
* case may be.
*
* So take a deep breath, relax, and remember what you're here
* for in the first place.
*
* I've traced its signal and the Algorithm is nearby. You'll
* need to go through the forest and across the river, and
* you'll reach the fortress where it's kept. Their defences
* are light, and we should be able to catch them off-guard.
*/
function startLevel(map) {
#START_OF_START_LEVEL#
// NOTE: In this level alone, map.placeObject is allowed to
//overwrite existing objects.
map.displayChapter('Chapter 2\nRaiders of the Lost Algorithm');
map.placePlayer(2, map.getHeight() - 1);
var functionList = {};
functionList['fortresses'] = function () {
function genRandomValue(direction) {
if (direction === "height") {
return Math.floor(Math.random() * (map.getHeight()-3));
} else if (direction === "width") {
return Math.floor(Math.random() * (map.getWidth()+1));
}
}
var x = genRandomValue("width");
var y = genRandomValue("height");
for (var i = x-2; i < x+2; i++) {
map.placeObject(i,y-2, 'block');
}
for (var i = x-2; i < x+2; i++) {
map.placeObject(i,y+2, 'block');
}
for (var j = y-2; j < y+2; j++) {
map.placeObject(x-2,j, 'block');
}
for (var j = y-2; j < y+2; j++) {
map.placeObject(x+2,j, 'block');
}
};
functionList['generateForest'] = function () {
for (var i = 0; i < map.getWidth(); i++) {
for (var j = 0; j < map.getHeight(); j++) {
// initialize to empty if the square contains a forest already
if (map.getObjectTypeAt(i, j) === 'tree') {
// remove existing forest
map.placeObject(i,j, 'empty');
}
if (map.getPlayer().atLocation(i,j) ||
map.getObjectTypeAt(i, j) === 'block' ||
map.getObjectTypeAt(i, j) === 'exit') {
continue;
}
var rv = Math.random();
if (rv < 0.45) {
map.placeObject(i, j, 'tree');
}
}
}
map.refresh();
};
functionList['movePlayerToExit'] = function () {
map.writeStatus("Permission denied.");
}
functionList['pleaseMovePlayerToExit'] = function () {
map.writeStatus("I don't think so.");
}
functionList['movePlayerToExitDamnit'] = function () {
map.writeStatus("So, how 'bout them <LOCAL SPORTS TEAM>?");
}
// generate forest
functionList['generateForest']();
// generate fortresses
functionList['fortresses']();
functionList['fortresses']();
functionList['fortresses']();
functionList['fortresses']();
map.getPlayer().setPhoneCallback(functionList[#{#"movePlayerToExit"#}#]);
map.placeObject(map.getWidth()-1, map.getHeight()-1, 'exit');
#END_OF_START_LEVEL#
}
function validateLevel(map) {
map.validateAtLeastXObjects(100, 'tree');
map.validateExactlyXManyObjects(1, 'exit');
}