-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutionTemp.js
336 lines (325 loc) · 13.6 KB
/
executionTemp.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//Area in which key events are captured and defined
//Purpose: used for getting the correct painting entry orientation
// Options: left, right, up, down
let previousWalkingDirection = null;
//Purpose: describes the spriteSheet
const animationInformation =
{
walkUp: {totalFrame: 7, spriteRow: 8},
walkLeft:{totalFrame: 7, spriteRow: 9},
walkDown:{totalFrame: 7, spriteRow: 10},
walkRight: {totalFrame: 7, spriteRow: 11},
crouch: {},
punchUp: {},
punchDown: {},
punchLeft: {},
punchRight: {}
}
//Purpose: holds all click events
document.addEventListener("keydown", async function (e){
userSprite.getPreviousXandY();
userSprite.animateBoolean = true;
let spriteHeight = userSprite.height;
let spriteSpeed = userSprite.speed;
if(e.key === "a" || e.key == "ArrowLeft")
{
//update the walking direction that exists for correct q movement through a painting
previousWalkingDirection = "left"
//find the correct sprite row
userSprite.srcY = animationInformation.walkLeft.spriteRow * spriteHeight;
//will not let you move off the screen
if (userSprite.xCoord > 0 )
{
userSprite.xCoord = userSprite.xCoord - spriteSpeed;
}
}
else if(e.key === "d" || e.key == "ArrowRight")
{
//update the walking direction that exists for correct q movement through a painting
previousWalkingDirection = "right"
//get the correct sprite row
userSprite.srcY = animationInformation.walkRight.spriteRow * spriteHeight;
//dont allow it to leave the end of the screen (some custom wiggle room to let it slightly leave)
if (userSprite.xCoord < (playerAreaCanvas.width - userSprite.width/1.5))
{
userSprite.xCoord = userSprite.xCoord + spriteSpeed;
}
}
else if (e.key == "s" || e.key == "ArrowDown")
{
//update the walking direction that exists for correct q movement through a painting
userSprite.srcY = animationInformation.walkDown.spriteRow * spriteHeight;
//get the correct sprite row
previousWalkingDirection = "down"
//some custom detection for the bottom
if (userSprite.yCoord < 427)//(playerAreaCanvas.height + userSprite.height/7))
{
userSprite.yCoord = userSprite.yCoord + spriteSpeed;
}
}
else if (e.key == "w" || e.key == "ArrowUp" )
{
previousWalkingDirection = "up"
userSprite.srcY = animationInformation.walkUp.spriteRow * spriteHeight;
if (userSprite.yCoord > - 20)
{
userSprite.yCoord = userSprite.yCoord - spriteSpeed;
}
}
else if (e.key == "q" )
{
if (userSprite.byDoor)
{
userSprite.srcY = 14 * spriteHeight; // 14: arching animation but looks like grabbing
userSprite.totalFrames = 7;
//immediately turn off by door so no more q's register
//note: not perfect by any means
userSprite.byDoor = false;
// removes the ability to bypass collision after 1 sec
userSprite.moveThroughPainting();
TextCanvas.rewriteText('returnToText');
//set a delay for turning off collision detection so you can travel through
//cant just stop the animation and redraw because you would exponentially call it with the requestAnimation frame
const awaitTimeout = delay =>
new Promise(resolve => setTimeout(resolve, delay));
awaitTimeout(200).then(function()
{
userSprite.usingDoor = false;
});
}
else if (userSprite.byStair)
{
//Get correct user sprite location
if (playerAreaCanvas.floor == "secondFloor" && playerAreaCanvas.transitionFloor == "firstFloor")
{
userSprite.xCoord = 301;
userSprite.yCoord = 316;
}
else if (playerAreaCanvas.floor == "basement" && playerAreaCanvas.transitionFloor == "firstFloor")
{
userSprite.xCoord = 784;
userSprite.yCoord = 316;
}
else if (playerAreaCanvas.floor == "firstFloor" && playerAreaCanvas.transitionFloor == "basement")
{
userSprite.xCoord = 784;
userSprite.yCoord = 316;
}
else if (playerAreaCanvas.floor = "firstFloor" && playerAreaCanvas.transitionFloor == "secondFloor")
{
userSprite.xCoord = 273;
userSprite.yCoord = 246;
}
stairSoundElement.play();
playerAreaCanvas.floor = "transition"
TextCanvas.rewriteText('returnToText');
//TODO set all NPCs to their starting poistions
}
else
{
//puts you back in default resting position
userSprite.animateBoolean = false;
}
}
//Used for rummaging a drawer or picking up an item
else if (e.key == "e")
{
if (userSprite.Furnitureby == stereo)
{
//complete the quest and turn on the stereo
//update your progress bar
//bookquest
if (stereo.hasCompleted == false)
{
statsCanvas.progressCounter++;
statsCanvas.updateProgressBar();
TextCanvas.currentTextKey = "dollQuest";
// -1 not 0 to make the rewriteText work correctly
TextCanvas.currentTextArrayIndex = -1;
TextCanvas.totalArrayIndex = allTexts[TextCanvas.currentTextKey].length;
//to make rewriting the text work
TextCanvas.previousText = allTexts[TextCanvas.currentTextKey][0];
//reset the button
button.status = "progress";
TextCanvas.rewriteText();
stereo.hasCompleted = true
}
stereoSoundElement.play();
}
else if (userSprite.Furnitureby == breakerBox)
{
if (!breakerBox.hasCompleted)
{
//move on to spray paint
statsCanvas.progressCounter++;
statsCanvas.updateProgressBar();
//bookquest
TextCanvas.currentTextKey = "whisperQuest";
// -1 not 0 to make the rewriteText work correctly
TextCanvas.currentTextArrayIndex = -1;
TextCanvas.totalArrayIndex = allTexts[TextCanvas.currentTextKey].length;
//to make rewriting the text work
TextCanvas.previousText = allTexts[TextCanvas.currentTextKey][0];
//reset the button
button.status = "progress";
TextCanvas.rewriteText();
questCompleteSoundElement.play();
basementBackground.inFlickerState = true;
this.hasCompleted = true;
}
}
else if (userSprite.byFurniture)
{
if(userSprite.Furnitureby.isOpenable)
{
TextCanvas.rewriteText("rummageDrawers")
}
else if (userSprite.Furnitureby.isPickupItem)
{
statsCanvas.addInventoryItem(userSprite.Furnitureby)
}
else if (userSprite.Furnitureby.isBreakable)
{
if (userSprite.hasWeapon && !userSprite.Furnitureby.isBroken)
{
//make a breaking noise
breakingSoundElement.play();
userSprite.Furnitureby.isBroken = true;
if (userSprite.Furnitureby == mirror)
{
//move on to flickering lights
statsCanvas.progressCounter++;
statsCanvas.updateProgressBar();
TextCanvas.currentTextKey = "breakerBoxQuest";
// -1 not 0 to make the rewriteText work correctly
TextCanvas.currentTextArrayIndex = -1;
TextCanvas.totalArrayIndex = allTexts[TextCanvas.currentTextKey].length;
//to make rewriting the text work
TextCanvas.previousText = allTexts[TextCanvas.currentTextKey][0];
//reset the button
button.status = "progress";
TextCanvas.rewriteText();
questCompleteSoundElement.play();
}
else if (userSprite.Furnitureby == toilet)
{
//move on to spray paint
statsCanvas.progressCounter++;
statsCanvas.updateProgressBar();
//bookquest
TextCanvas.currentTextKey = "sleepingQuest";
// -1 not 0 to make the rewriteText work correctly
TextCanvas.currentTextArrayIndex = -1;
TextCanvas.totalArrayIndex = allTexts[TextCanvas.currentTextKey].length;
//to make rewriting the text work
TextCanvas.previousText = allTexts[TextCanvas.currentTextKey][0];
//reset the button
button.status = "progress";
TextCanvas.rewriteText();
questCompleteSoundElement.play();
}
}
}
}
}
else if (e.key == "r" )
{ //check if near a draggable item or youre holding a draggable item
if (userSprite.byFurniture && userSprite.Furnitureby.isDraggable
|| userSprite.furnitureHolding !== null)
{
//Youre dropping
if (userSprite.furnitureHolding)
{
userSprite.furnitureHolding.endingX = userSprite.xCoord -20;
userSprite.furnitureHolding.endingY = userSprite.yCoord +5;
userSprite.furnitureHolding.xCoord = userSprite.xCoord -20;
userSprite.furnitureHolding.yCoord = userSprite.yCoord +5;
userSprite.furnitureHolding.isBeingDragged = false;
userSprite.furnitureHolding.checkIfDraggedFurnitureFarAway();
userSprite.furnitureHolding = null;
}
else // Youre picking up
{
//if youre picking up for the first time, register its starting position
if (userSprite.Furnitureby.dragCount == 0)
{
userSprite.Furnitureby.startingX = userSprite.Furnitureby.xCoord;
userSprite.Furnitureby.startingY = userSprite.Furnitureby.yCoord;
}
userSprite.Furnitureby.isBeingDragged = true;
userSprite.Furnitureby.dragCount++;
//need to pass in the furnitureby because it could theoretically change if you get close to another
userSprite.furnitureHolding = userSprite.Furnitureby;
}
}
}
else if (e.key == "z")
{
//check if near the vent
if (userSprite.Furnitureby == whisperVent)
{
//check if the child sprite is close (you paused it at the desired coords to make it easier for the player)
if (childNPCSprite.xCoord == 224 && childNPCSprite.yCoord == 182)
{
whisperSoundElement.play();
if (!whisperVent.hasCompleted)
{
statsCanvas.progressCounter++;
statsCanvas.updateProgressBar();
TextCanvas.currentTextKey = "toiletBreakQuest";
// -1 not 0 to make the rewriteText work correctly
TextCanvas.currentTextArrayIndex = -1;
TextCanvas.totalArrayIndex = allTexts[TextCanvas.currentTextKey].length;
//to make rewriting the text work
TextCanvas.previousText = allTexts[TextCanvas.currentTextKey][0];
//reset the button
button.status = "progress";
TextCanvas.rewriteText();
whisperVent.hasCompleted = true;
questCompleteSoundElement.play();
}
}
}
else if (userSprite.bySleeper)
{
whisperSoundElement.play();
if (!userSprite.hasCompleteSleepQuest)
{
statsCanvas.progressCounter++;
statsCanvas.updateProgressBar();
TextCanvas.currentTextKey = "sprayPaintQuest";
// -1 not 0 to make the rewriteText work correctly
TextCanvas.currentTextArrayIndex = -1;
TextCanvas.totalArrayIndex = allTexts[TextCanvas.currentTextKey].length;
//to make rewriting the text work
TextCanvas.previousText = allTexts[TextCanvas.currentTextKey][0];
//reset the button
button.status = "progress";
TextCanvas.rewriteText();
userSprite.hasCompleteSleepQuest = true
questCompleteSoundElement.play();
}
}
if (TextCanvas.hasbeenRewritten)
{
TextCanvas.rewriteText('returnToText');
TextCanvas.hasbeenRewritten = false;
}
}
else
{
console.log('not a valid key');
userSprite.animateBoolean = false;
}
});
document.addEventListener("keyup", e =>
{
userSprite.animateBoolean = false;
})
window.onload = () =>
{
//create the stats area
updatePlayerArea();
updateStatsArea();
updateTextArea();
}