-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathcastleEntrance.js
162 lines (141 loc) · 7.9 KB
/
castleEntrance.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
var castleEntrance = {
// Variables
size : 30,
timeSpent : 0, // Time spent since the beginning of the quest
thereIsAMagicBall : false, // True if there's a magic ball right now
magicBallX : 0, // X position of the magic ball
magicBallY : 0, // Y position of the magic ball
// Functions
onload : function(){
land.addLand("Castle's entrance", this.size, 3, this.load.bind(this), this.getText.bind(this), this.move.bind(this));
},
move : function(){
// Make enemies go toward the left
for(var i = 0; i < quest.things.length; i++){
if(quest.things[i].type == "mob" && quest.things[i-1].type == "none"){
quest.things[i-1] = quest.things[i];
quest.things[i] = quest.makeNoneThing();
}
}
// We add ennemies
if(this.timeSpent < 1000){ // We must stop adding ennemies after a while, else the player could be blocked in certain conditions
if(this.timeSpent % 16 == 5){
// If there's nothing here, we add a knight
if(quest.things[29].type == "none") quest.things[29] = this.makeKnight();
}
else if(this.timeSpent % 30 == 29){
// If there's nothing here, we add a guard
if(quest.things[29].type == "none") quest.things[29] = this.makeGuard();
}
}
// We handle the magic ball if we spent at least four movements
if(this.timeSpent > 4){
// If there is already a magic ball
if(this.thereIsAMagicBall){
var index = quest.getCharacterIndex();
// If the magic ball just hit the player !
if(Math.abs(this.magicBallX - (index*3 + 1)) <= 1 && this.magicBallY == 19){
// No more magic ball
this.thereIsAMagicBall = false;
// We teleport the player
quest.things[0] = quest.things[index];
quest.things[index] = quest.makeNoneThing();
}
// Else
else{
// If the magic ball is at the right of the player or is above the steps (it mustn't be above the steps)
if(this.magicBallX > index*3 + 1 || this.magicBallX > 77){
this.magicBallX -= 1;
}
// Else, if it's at the left
else if(this.magicBallX < index*3 + 1){
this.magicBallX += 1;
}
// If the magic ball isn't already just above the lawn and we're not too far from the play horizontally
if(this.magicBallY < 19 && Math.abs(this.magicBallX - index*3) < (19 - this.magicBallY)*3){
this.magicBallY += 1;
}
}
}
// If there is not already a magic ball
else{
this.thereIsAMagicBall = true;
this.magicBallX = 83;
this.magicBallY = 1;
}
}
// We increment the time spent
this.timeSpent += 1;
},
load : function(){
// We add some guards on the lawn to slow down the player
quest.things[10] = this.makeGuard();
quest.things[12] = this.makeGuard();
quest.things[15] = this.makeGuard();
quest.things[17] = this.makeGuard();
// We reset the time spent
this.timeSpent = 0;
},
makeGuard : function(){
return land.createMob("GUA", 25, 25, "spear", "One of the castle's guards.", [drops.createDrop("candies", random.getRandomIntUpTo(40))]);
},
makeKnight : function(){
return land.createMob("KNI", 70, 70, "sharp sword", "A knight with a huge armor.", [drops.createDrop("candies", 230 + random.getRandomIntUpTo(70)), drops.createDrop("object", "plateArmour", random.oneChanceOutOf(10))]);
},
getText : function(){
var lines = [];
lines = this.text.slice(0); // It will store the lines of the castle entrance
// We add things to the lines (we use size - 1 to avoid drawing the last position, which is inside the castle)
for(var i = 0; i < this.size - 1; i++){
// If there's a thing
if(quest.things[i].type != "none"){
// Before the first step
if(i < 26){
lines[20] = lines[20].replaceAt(i*3, quest.things[i].text);
}
// On the first step
else if(i == 26){
lines[19] = lines[19].replaceAt(i*3, quest.things[i].text);
}
// On the second step
else if(i <= 28){
lines[18] = lines[18].replaceAt(i*3, quest.things[i].text);
}
}
}
// We add the magic ball
if(this.thereIsAMagicBall){
lines[this.magicBallY] = lines[this.magicBallY].replaceAt(this.magicBallX, "*");
}
// We return the lines
return lines.join("");
},
// Variables
text : [
" __\n",
" <*/\n",
" (}\n",
" |\\\n",
" ||| || || || |\n",
" |`\' `\' `\' `\'.|\n",
" : .:;\n",
" \\-..____..:/ _ _\n",
" :--------:_,\' || |\n",
" |] .:| `\' `\n",
" | ,-. .[| _\n",
" | | | .:|\'--\' _\n",
" | |_| .:| \'--\'\n",
" | \'=\' .:|\n",
" | __ .:|\n",
" |\'--\' .:| _\n",
" | .:| \'-\'\n",
" | \'-| _\n",
" ______| _ .:| _ \'--\'\n",
" ___||||||| \'-\' .:| \'-\'\n",
" ___|||||||||;._____.::-------\n",
"\' \" \'\' \" \"\' \"\' \' \" \' \"\' \'\" \' \'\" \"\' \' \'\" \" \' \' \'\" \' \' \'\" \' \'\" \'\" \'\' \' \'\" \" \' \'\" \' \' \" \'\" \" \" \' \'\" \"\' \n",
" \"\' \' \" \' \" \' \" \' \" \' \' \" \' \' \" \' \" \' \' \" \" \" \' \' \" \"\' \'\n",
" \'\" \' \" \' \" \' \" \' \" \' \" \" \' \" \' \" \' \n",
" \' \" \' \' \" \" \' \' \' \" \"\n"
]
};