-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameindex.js
1685 lines (1618 loc) · 71.6 KB
/
gameindex.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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Purpose : create a canvas HTML element. This also includes functionality for displaying transition animations, such as stair movements or win/lsoe animations
// Instantiations: PlayerAreaCanvas
// ChildClasses : ClickableCanvas,InventoryCanvas
class Canvas
{
constructor(canvasID, width, height, floor)
{
this.width = width;
this.height = height;
this.canvasID = canvasID;
//used once you instantiate the canvas
this.canvasElement = null;
//used once you instantiate the canvas
this.ctx = null;
//used for switching playerarea canvas floor displays and transition/win/lose states
this.floor = floor;
this.tileSize = 32;
//used in the actual creation of preset animations
//sets the timer tracker for filling in the
this.transitionCount = 0;
this.transitionWidth = 32;
this.transitionHeight = 32;
this.transitionFloor = null;
}
//Purpose: grab the canvas element from HTML is js and create a parametre for the context
getCanvasMade()
{
this.canvasElement = document.getElementById(this.canvasID);
this.ctx = this.canvasElement.getContext('2d');
this.canvasElement.width = this.width;
this.canvasElement.height = this.height;
}
//Purpose: creating the actual animation used when transitioning between floors
//Note : this is basic, could be improved
transition()
{
//get correct floor to show
let backgroundImage = null;
switch (playerAreaCanvas.transitionFloor)
{
case "firstFloor":
//Turn off the stereo just in case
stereoSoundElement.pause();
backgroundImage = firstFloorBackground.imageElement;
break;
case "secondFloor":
stereoSoundElement.pause();
backgroundImage = secondFloorBackground.imageElement;
break;
case "basement":
stereoSoundElement.pause();
backgroundImage = basementBackground.imageElement;
break;
case "won":
stereoSoundElement.pause();
backgroundMusicElement.pause();
backgroundImage = winBackground.imageElement;
TextCanvas.currentTextKey = "sigilQuest";
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();
winSound.play();
break;
case "lost":
stereoSoundElement.pause();
backgroundMusicElement.pause();
backgroundImage = loseBackground.imageElement;
TextCanvas.currentTextKey = "lost";
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();
loseSound.play();
break;
}
if (this.transitionWidth > fullAreaWidth && this.transitionHeight > fullAreaHeight)
{
this.transitionWidth = 32;
this.transitionHeight = 32;
this.transitionCount = 0;
this.floor = this.transitionFloor;
this.transitionFloor = null;
}
else
{
//every ten counts increase the width
if (this.transitionCount > 1)
{
this.transitionWidth = this.transitionWidth + 32;
this.transitionHeight = this.transitionHeight + 16;
this.transitionCount = 0;
}
this.ctx.fillStyle = "rgba(0,0,0,0.7)"
this.ctx.drawImage(backgroundImage, 0, 0, this.transitionWidth, this.transitionHeight, 0, 0, this.transitionWidth, this.transitionHeight);
this.ctx.fillRect(0,0,this.transitionWidth,this.transitionHeight);
this.transitionCount++
}
}
}
// Purpose : The most basic Image class. All items drawn onto any canvas are included in this base class.
// Instantiations : startledDialog, warningDialog, candle,candy,mace,paint,statsBackground, textBackground (I know confusing name, this one is static bacgkround class isnt), halfbar,fullbar,fullheart,heartcover
// ChildClasses : InteractableItem, MoveableImage,Background,ButtonClass
class ImageClass
{
constructor (src, xCoord, yCoord, height, width, canvasID )
{
this.src = src;
this.yCoord = yCoord;
this.xCoord = xCoord;
this.canvasID = canvasID;
this.height = height;
this.width = width;
this.imageElement = null;
this.tileSize = 32; //cahnge if tile size cahnges
}
// Purpose: creates a new image element and appliesit to the canvas
createImageElement()
{
let image = new Image();
image.src = this.src;
this.imageElement = image;
}
drawImage()
{
if (this.imageElement === null)
{
console.warn('you are trying to work with an image element you have not created. run classInstanceName.createImageElement() and/or check your promise All.')
}
//in information stats we repeat pictures
if (this.xCoord.length > 0)
{
for (let i=0; i< this.xCoord.length; i++)
{
document.getElementById(this.canvasID).getContext('2d').drawImage(this.imageElement,this.xCoord[i], this.yCoord[i]);
}
}
else
{
document.getElementById(this.canvasID).getContext('2d').drawImage(this.imageElement,this.xCoord, this.yCoord);
}
}
}
// Purpose : Holds all the items that are pickupable, searchable, breakable, and a few other more unique features (flicker lights and turn on radio)
// Instantiations : stove, fridge, bookshelfleft, bookshelfright,vanity,dresserleft,dresserright, toilet,book,doll,dressersecond,mirror,breakerbox,shelves1,shelves2,shelves3,
// ChildClasses : DraggableItem, DualInteractableItem (Note: this ideally should be extended but has not been due to time constraints/not the best plannign (extended to a breakable, and then pickup/isopenable should be together)
class InteractableItem extends ImageClass
{
constructor (src, xCoord, yCoord, height, width,isBreakable,isOpenable,isPickupItem,itemsInside,brokenSrc)
{
super(src,xCoord,yCoord,height, width);
//used to load in the broken furniture image that displays on breaking
this.brokenSrc = brokenSrc;
this.BrokenImageElement = null;
this.isBroken = false;
//there are different typres of furnitures with different functionalities that are
//turned on and off with booleans
this.isBreakable = isBreakable;
//these are items on the floor that you can pick up and add to inventory
this.isPickupItem = isPickupItem;
//these are desks/drawers you can rummage through
this.isOpenable = isOpenable;
//THIS APPLIES to both isPickupItem and isOpenable. this is an array of the item itself/ the items inside.
// Note: this will reset each time you reload a floor except for pickup items and quest items
this.itemsInside = itemsInside;
//For some you need to keep track if they have already been interacted with so the completion doesnt fire twice
this.hasCompleted = false;
}
createBrokenImageElement()
{
let image = new Image();
image.src = this.brokenSrc;
this.BrokenImageElement = image;
}
drawFurniture()
{
if(this.BrokenImageElement !== null)
{
if (this.isBroken)
{
playerAreaCanvas.ctx.drawImage(this.BrokenImageElement, this.xCoord, this.yCoord);
}
else
{
playerAreaCanvas.ctx.drawImage(this.imageElement, this.xCoord, this.yCoord);
}
}
else
{
playerAreaCanvas.ctx.drawImage(this.imageElement, this.xCoord, this.yCoord);
}
}
isClose()
{
//Purpose: writing out all the text dialogue options because it is used both at the initial hitting and colliding back
function selectCorrectDialogue(furniture)
{
if (furniture.isOpenable)
{
TextCanvas.rewriteText('openingFurniture');
}
else if (furniture.isPickupItem)
{
TextCanvas.rewriteText('pickingUpItem');
}
//Specifically for the breaker box and stereo, they have custom messages. Ideally I would have changed the class system to compensate
else if (furniture == stereo)
{
TextCanvas.rewriteText("stereo")
}
else if (furniture == breakerBox)
{
TextCanvas.rewriteText("breakerBox")
}
else if (furniture.isBreakable)
{
if (userSprite.hasWeapon && furniture.isBroken == false)
{
TextCanvas.rewriteText("breakingItem");
}
else if (furniture.isBroken == false)
{
TextCanvas.rewriteText("noWeapon")
}
}
}
//use the proper hitbox dimensions
let playerDimensions = userSprite.getProperHitboxDimensions();
if (
this.xCoord < playerDimensions.xCoord + playerDimensions.width &&
this.xCoord + this.width > playerDimensions.xCoord &&
this.yCoord < playerDimensions.yCoord + playerDimensions.height &&
this.yCoord + this.height > playerDimensions.yCoord
)
{
userSprite.placeholderCoordx = userSprite.xCoord;
userSprite.placeholderCoordy = userSprite.yCoord;
userSprite.xCoord = userSprite.previousXCoord;
userSprite.yCoord = userSprite.previousYCoord;
TextCanvas.hasbeenRewritten = true;
userSprite.byFurniture = true;
userSprite.Furnitureby = this;
selectCorrectDialogue(this);
}
else if (
userSprite.yCoord == userSprite.previousYCoord && userSprite.xCoord == userSprite.previousXCoord &&
this.xCoord < userSprite.placeholderCoordx + (playerDimensions.width) &&
this.xCoord + this.width > userSprite.placeholderCoordx &&
this.yCoord < userSprite.placeholderCoordy + (userSprite.height) &&
this.yCoord + this.height > (userSprite.placeholderCoordy)
)
{
userSprite.byFurniture = true;
userSprite.Furnitureby = this;
this.changeColorWhenPlayerClose();
TextCanvas.hasbeenRewritten = true;
//so that on pressing e it doesnt reset
if (TextCanvas.currentText == allPlayerOptions.openingFurniture)
{
selectCorrectDialogue(this);
}
}
else if(
(userSprite.Furnitureby == this && userSprite.yCoord !== userSprite.previousYCoord) ||
(userSprite.Furnitureby == this && userSprite.xCoord !== userSprite.previousXCoord)
)
{
userSprite.byFurniture = false;
userSprite.Furnitureby = null;
userSprite.placeholderCoordx = null;
userSprite.placeholderCoordy = null;
if (TextCanvas.hasbeenRewritten)
{
TextCanvas.rewriteText('returnToText');
TextCanvas.hasbeenRewritten = false;
}
}
}
changeColorWhenPlayerClose()
{
//TODO change color based on what you can do with it
//TODO change the heights and widths of the furniture in loadinimages to make more accurate
playerAreaCanvas.ctx.fillStyle = 'rgba(245,152,39,0.5)';
playerAreaCanvas.ctx.fillRect(this.xCoord +5 ,this.yCoord + 5,this.width,this.height);
}
}
//Purpose : Creates items that can be dragged by the player and dropped by pressing R
//Instantiations : doll, chairRightDown, chairRightUp
//ChildClasses : none
class DraggableItem extends InteractableItem
{
constructor(src, xCoord, yCoord, height, width)
{
super(src,xCoord,yCoord,height, width)
//this is always true, its for keypress event recognition because other item types also use
// userSprite.FurnitureBy and userSprite.byFurniture
this.isDraggable = true;
this.isBeingDragged = false;
this.startingX = null;
this.startingY = null;
this.endingX = null;
this.endingY = null;
this.dragCount = 0;
this.hasCompleted = false;
}
//theres enough changes where it makes sense to rewrite is close
//Purpose: trigger the correct textbox and option to pickup furniture
isNearby(player)
{
let playerDimensions = player.getProperHitboxDimensions();
if (
this.xCoord < playerDimensions.xCoord + playerDimensions.width &&
this.xCoord + this.width > playerDimensions.xCoord &&
this.yCoord < playerDimensions.yCoord + playerDimensions.height &&
this.yCoord + this.height > playerDimensions.yCoord
)
{
player.placeholderCoordx = player.xCoord;
player.placeholderCoordy = player.yCoord;
player.xCoord = player.previousXCoord;
player.yCoord = player.previousYCoord;
TextCanvas.hasbeenRewritten = 'true';
player.byFurniture = true;
player.Furnitureby = this;
TextCanvas.rewriteText('dragItem');
this.changeColorWhenPlayerClose();
}
else if (
player.yCoord == player.previousYCoord && player.xCoord == player.previousXCoord &&
this.xCoord < player.placeholderCoordx + (playerDimensions.width) &&
this.xCoord + this.width > player.placeholderCoordx &&
this.yCoord < player.placeholderCoordy + (playerDimensions.height) &&
this.yCoord + this.height > (player.placeholderCoordy)
)
{
player.byFurniture = true;
player.Furnitureby = this;
this.changeColorWhenPlayerClose();
TextCanvas.hasbeenRewritten = true;
player.byFurniture = true;
player.Furnitureby = this;
TextCanvas.rewriteText('dragItem');
}
else if
(
(player.byFurniture && player.yCoord !== player.previousYCoord)
||
(player.byFurniture && player.xCoord !== player.previousXCoord)
)
{
player.byFurniture = false;
player.Furnitureby = null;
player.placeholderCoordx = null;
player.placeholderCoordy = null;
TextCanvas.rewriteText('returnToText');
}
}
//Purpose: put the furniture in the correct
drawDraggableFurniture()
{
if (this.isBeingDragged == true)
{
//draw it like 30 pixels away from the user
playerAreaCanvas.ctx.drawImage(this.imageElement, (userSprite.xCoord -20 ), userSprite.yCoord);
}
else if (this.isBeingDragged == false)
{
this.drawFurniture();
this.isNearby(userSprite);
}
}
//Purpose: for the sake of quest completion check if the player dragged the element far enough away
checkIfDraggedFurnitureFarAway()
{
//first apply a boolean to the moved furniture itself if it has moved far enough
let xDifference = Math.abs(this.startingX - this.endingX);
let yDifference = Math.abs(this.startingY - this.endingY);
if (xDifference + yDifference > 100 && this.hasCompleted == false)
{
this.hasCompleted = true;
}
//Now check if they have done enough to complete a quest, and also check if they have already completed it
if (chairRightDown.hasCompleted && chairRightUp.hasCompleted)
{
if (!statsCanvas.completedDraggingQuestCount.includes("chairQuest"))
{
//add one to completion
questCompleteSoundElement.play();
//update your progress bar
statsCanvas.progressCounter++;
statsCanvas.updateProgressBar();
//they have completed the test and can move on
TextCanvas.currentTextKey = "turnOnRadioQuest";
// -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];
button.status = "progress";
//setTimeout(questCompleteSoundElement.play(),1000);
TextCanvas.rewriteText();
statsCanvas.completedDraggingQuestCount.push("chairQuest");
}
}
//the else if helps with quest progression
//check specifically if the doll has been moved
if (doll.hasCompleted)
{
if (!statsCanvas.completedDraggingQuestCount.includes('dollQuest'))
{
//add one to completion
questCompleteSoundElement.play();
//update your progress bar
statsCanvas.progressCounter++;
statsCanvas.updateProgressBar();
//they have completed the test and can move on
TextCanvas.currentTextKey = "maceQuest";
// -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];
button.status = "progress";
//setTimeout(questCompleteSoundElement.play(),1000);
TextCanvas.rewriteText();
statsCanvas.completedDraggingQuestCount.push("dollQuest");
}
}
//check if youve dragged the item far enough away
//if they have
}
}
//Purpose : Creates an item that can trigger a progression iff the player and the NPC of that floor are close to the item
//Instantiations : whisperVent
//ChildClasses : none
class DualInteractableItem extends InteractableItem
{
constructor (src, xCoord, yCoord, height, width, behindWall)
{
super(src,xCoord,yCoord,height, width)
// userSprite.FurnitureBy and userSprite.byFurniture
this.playerNearby = null;
this.NPCNearby = null;
// If the quest wants you behind the wall, it will check that you are
this.behindWall = behindWall;
this.hasCompleted = false;
}
isPlayerClose()
{
//helper function:
//Purpose: writing out all the text dialogue options because it is used both at the initial hitting and colliding back
//TODO helper function for the dialogue selection
//use the proper hitbox dimensions
let playerDimensions = userSprite.getProperHitboxDimensions();
if (
this.xCoord < playerDimensions.xCoord + playerDimensions.width &&
this.xCoord + this.width > playerDimensions.xCoord &&
(this.yCoord - 20) < playerDimensions.yCoord + playerDimensions.height &&
(this.yCoord + this.height - 20) > playerDimensions.yCoord
)
{
TextCanvas.hasbeenRewritten = true;
userSprite.byFurniture = true;
userSprite.Furnitureby = this;
TextCanvas.rewriteText('whisper');
}
else if(userSprite.Furnitureby == this)
{
userSprite.byFurniture = false;
userSprite.Furnitureby = null;
if (TextCanvas.hasbeenRewritten)
{
TextCanvas.rewriteText('returnToText');
TextCanvas.hasbeenRewritten = false;
}
}
}
}
//Purpose : Creates image element that are able to be moved using animations
//Instantiations : userSprite
//ChildClasses : nonPlayableCharacter (ideally it should also have a PlayableCharacter child and userSprite should be defined there)
//TODO there should be a user and a nonplayable child class child, with them being sisters
class MoveableImage extends ImageClass
{
constructor (src,xCoord, yCoord,srcX,srcY,height,width,canvasID,speed)
{
super (src, xCoord, yCoord,height,width,canvasID);
//adding in the sprite sheet for when youre holding a weapon
this.weaponImageElement = null;
//basic booleans
this.speed = speed;
this.hasWeapon = false;
this.hasCandle = false;
this.hasBook = false;
//used for spritesheet selection
this.srcX = srcX;
this.srcY = srcY;
//used for proper animation
this.animateBoolean = false;
this.framesDrawn = 0;
this.totalFrames = 7;
this.currentFrame = 0;
//used for collision detection
this.previousXCoord = null;
this.previousYCoord = null;
this.heightAndWidthAllowance = 30;
//for door detection
this.placeholderCoordx = null;
this.placeholderCoordy = null;
//used for displaying the correct movement options
this.byDoor = false;
this.byFurniture = false;
this.byStair = false;
//gives the object name you are by for interacting purposes
this.Furnitureby = null;
//Used in keeping track of the item you're dragging
this.furnitureHolding = null;
//turns off collision door detection when going through
this.usingDoor = null;
//turns off NPC sprite detection
this.insideWall = null;
//in the penultimate quest, used to determine when the player steps away from the sleeping man and if it was completed
this.bySleeper = false;
this.hasCompleteSleepQuest = false;
}
createWeaponImageElement()
{
let image = new Image();
image.src = "assets/spriteSheets/playerSpriteSheetMace.png";
this.weaponImageElement = image;
}
//Purpose: Move through the sprite sheet of your character to animate movement correctly
// Variable information: 1.animateBoolean is periodically turned off in timeouts to prevent the infinite loop animations from going wild
// or when an NPC pauses
// 2.makeMeScared is defined for an NPC when they encounter a player
// 3. The frames drawn counter slows down the sprite sheet progression rate, so 15 refreshes before it goes to the next
//
animate()
{
if (this == userSprite)
{
if (this.hasWeapon)
{
var src = this.weaponImageElement;
}
else
{
var src = this.imageElement;
}
}
else
{
var src = this.imageElement;
}
if (this.animateBoolean)
{
//Keep track of the number of animation frames to choose the correct sprite
this.currentFrame = this.currentFrame % this.totalFrames;
this.srcX = this.currentFrame * this.width; //Src position is updated to show the new sprite image
}
else
{
//this is the default standing still, facing the player frame
this.srcY = 10 * this.height; //tenth row is the facing down
this.currentFrame = 0;
}
//used specifically for npc sprites to get them stuck in the 4th sprite row of "hurt" for the set timeout
// you can see by looking at when this.currentPathTrack == "scared" there will be a boolean that will time this out appropriately
//if (this.srcX = "makeMeScared")
//{
// this.srcX = 4 * this.width; // pauses them as cowering down
//}
//image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight
playerAreaCanvas.ctx.drawImage(src, this.srcX, this.srcY, this.width, this.height, this.xCoord, this.yCoord, this.width, this.height);
this.framesDrawn++;
//Note: I left this here but this explains the actual collision detection, turn this one to see where you are actually looking for collisions
//playerAreaCanvas.ctx.fillRect((this.xCoord + 16), (this.yCoord +10), 30, 58);
if(this.framesDrawn >= 10)
{
this.currentFrame++;
this.framesDrawn = 0;
}
}
//Purpose: height and width are for sprite sheet selection and because of the nature of the canvas drawing,
// the hitbox will not be accurate if you use collision detection doing the actual Xcoord, ycoord, width and height
// therefore we are making a function that fixes these coordinates and returns the proper ones
// Returns: Object of hitbox dimensions
//NOTE: this is specific to the LPC universal character sprite generator which is in the attributes for all future sprites
getProperHitboxDimensions()
{
let properDimensions =
{
"xCoord" : this.xCoord + 16,
"yCoord" : this.yCoord + 10,
"height" : 58,
"width" : 30
}
return properDimensions;
}
//Purpose: As the player moves, keep track of their previous location for the purpose of collision detection
// As in, if a collision happens, push them back to the coords before collision, and this is continously called in the requestAnimationFrame
getPreviousXandY()
{
this.previousXCoord = this.xCoord;
this.previousYCoord = this.yCoord;
}
//Purpose: Move through paintings on a q click
//
//TODO there are bugs here in the entirety of this functionality
moveThroughPainting()
{
//you can use direction to determine which way they are facing wrt the painting. There are never left or right facing paintings
// but they can still press q if they are facing left or right because of the collision detection
// TODO maybe prevent that dialogue firing if they are facing left or right?
let direction = previousWalkingDirection;
//set this, which is then changed as a timeout in a different function. this is done to turn off collision detection as your player walks through
this.usingDoor = true;
moveThroughPaintingSoundElement.play();
switch (direction)
{
case 'up' :
this.yCoord = this.yCoord - 100;
break;
case 'down' :
this.yCoord = this.yCoord + 120;
break;
}
}
// Purpose: called on the second floor to make sure that the text rewriting to the by sleeper option turns off if the npc wakes up before you move
makeSureBySleeperUpdates()
{
if ( manNPCSprite.xCoord !== 672 && manNPCSprite.yCoord !== 87)
{
if (this.bySleeper)
{
TextCanvas.rewriteText('returnToText');
TextCanvas.hasbeenRewritten = false;
userSprite.bySleeper = false;
}
}
}
}
// Purpose : Holds all functions and parametres associated with any NPC.
// Instantiations : ladyNPCSprite,manNPCSprite,childNPCSprite
// ChildClasses : None
class NonPlayableCharacter extends MoveableImage
{
constructor (src,xCoord,yCoord,srcX,srcY,height,width,canvasID,currentPathName,currentPathTrack,floor)
{
super (src,xCoord,yCoord,srcX,srcY,height,width,canvasID);
//to have pathing work this needs to be easily added to 1, for example 0.5,0.25,etc, because the switches need to be hit exactly
//in pathing and hihger speeds could skip over them
this.speed = 1;
//firstFloor,basement,secondFloor
this.floor = floor;
//used for spritesheet selection
this.srcX = srcX;
this.srcY = srcY;
//used for proper animation
this.animateBoolean = false;
this.framesDrawn = 0;
this.totalFrames = 7;
this.currentFrame = 0;
//used for pathing
//there are two different paths that are randomly selected once they finish
this.currentPathName = null;
//each path has individual tracks
this.currentPathTrack = null;
//how many seconds they have been on the path track
this.currentPathName = currentPathName;
this.currentPathTrack = currentPathTrack;
//used to take the NPC out of cower mode when the player moves far enough away
this.previousTrack = null;
this.scaredState = false;
//used for determining when the NPC gets back up post scare
this.Scaredcount = 0;
//used for collision detection
this.previousXCoord = null;
this.previousYCoord = null;
this.heightAndWidthAllowance = 30;
//used for the sleeper on the second floor
this.sleepingCount = 0;
}
path()
{
//Purpose: Helper function in changing path directions
//Note: not working for some reason
function changeDirection(direction,sprite)
{
switch(direction)
{
case "up":
sprite.srcY = animationInformation.walkUp.spriteRow * sprite.height;
sprite.yCoord = sprite.yCoord - sprite.speed;
case "down":
sprite.srcY = animationInformation.walkDown.spriteRow * sprite.height;
sprite.yCoord = sprite.yCoord + sprite.speed;
case "right" :
sprite.srcY = animationInformation.walkRight.spriteRow * sprite.height;
sprite.xCoord = sprite.xCoord + sprite.speed;
case "left" :
sprite.srcY = animationInformation.walkLeft.spriteRow * sprite.height;
sprite.xCoord = sprite.xCoord + sprite.speed;
}
}
//activate animation
this.animateBoolean = true;
// For each character (defined by their floor locations here), they will have designated paths
// at the starting location for each, there will be a chance to switch paths
// Note: because of the switches and how path movement works, rn it will only work if their speed is set to 1 or lower that will still hit everything (like 0.5,0.25,etc.. for instance)
// there will be x many paths, where each one is a walk direction and a certain amount of steps, defined by
//going through path one
switch (this.floor)
{
case "firstFloor":
switch (this.currentPathName)
{
case "pathOne":
if
(
(this.xCoord == 322 && this.yCoord == 113)
)
{
this.currentPathTrack = "down";
}
else if
(
(this.xCoord == 560 && this.yCoord == 316)||
(this.xCoord == 252 && this.yCoord == 197) ||
(this.xCoord == 497 && this.yCoord == 218)
)
{
this.currentPathTrack = "up";
}
else if
(
(this.xCoord == 721 && this.yCoord == 316)||
(this.xCoord == 560 && this.yCoord == 197)
)
{
this.currentPathTrack = "left"
}
else if
(
(this.xCoord == 252 && this.yCoord == 113)||
(this.xCoord == 322 && this.yCoord == 218) ||
(this.xCoord == 497 && this.yCoord == 211)
)
{
this.currentPathTrack = "right"
}
//adding in pausing if shes by a kitchen appliance
else if
( this.xCoord == 623 && this.yCoord == 211)
{
if (Math.random() > 0.007)
{
this.currentPathTrack = "paused"
}
else
{
this.currentPathTrack = "right"
}
}
//see if it switches to path two or not
else if (this.xCoord == 721 && this.yCoord == 211)
{
if (Math.random() > 0.5)
{
this.currentPathTrack = "down"
}
else
{
this.currentPathTrack = "down"
this.yCoord++;
this.currentPathName = "pathTwo"
}
}
break;
case "pathTwo" :
if
(
(this.xCoord == 984 && this.yCoord == 253) ||
(this.xCoord == 691 && this.yCoord == 78) ||
(this.xCoord == 785 && this.yCoord == 82)
)
{
this.currentPathTrack = "down";
}
else if
(
(this.xCoord == 784 && this.yCoord == 253)||
(this.xCoord == 720 && this.yCoord == 317)
)
{
this.currentPathTrack = "up";
}
else if
(
(this.xCoord == 784 && this.yCoord == 78) ||
(this.xCoord == 785 && this.yCoord == 317)
)
{
this.currentPathTrack = "left"
}
else if
(
(this.xCoord == 721 && this.yCoord == 253)||
(this.xCoord == 691 && this.yCoord == 82) ||
(this.xCoord == 720 && this.yCoord == 211)
)
{
this.currentPathTrack = "right"
}
//adding in pausing if shes by the toiler appliance
else if
( this.xCoord == 784 && this.yCoord == 80 )
{
if (Math.random() > 0.007)
{
this.currentPathTrack = "paused"
}
else
{
this.currentPathTrack = "up"
}
}
//see if it switches to path two or not
else if (this.xCoord == 721 && this.yCoord == 211)
{
if (Math.random() > 0.7)
{
this.currentPathTrack = "down"
}
else
{
this.currentPathName = "pathOne"
this.currentPathTrack = "down"
this.yCoord++;
}
}
break;
}
break;
case "secondFloor":
switch (this.currentPathName)
{
case "pathOne":
if
(
(this.xCoord == 749 && this.yCoord == 183) ||
(this.xCoord == 525 && this.yCoord == 197)
)
{
this.currentPathTrack = "down";
}
else if
(
(this.xCoord == 623 && this.yCoord == 218) ||
(this.xCoord == 721 && this.yCoord == 309)
)
{
this.currentPathTrack = "up";
}
else if
(
(this.xCoord == 749 && this.yCoord == 309) ||
(this.xCoord == 721 && this.yCoord == 197)
)
{
this.currentPathTrack = "left"
}
else if
(
(this.xCoord == 623 && this.yCoord == 127) ||
(this.xCoord == 672 && this.yCoord == 183) ||
(this.xCoord == 462 && this.yCoord == 218)
)
{
this.currentPathTrack = "right"
}
else if (this.xCoord == 672 && this.yCoord == 127)
{
if (this.sleepingCount > 700)
{
this.currentPathTrack = "down";
this.sleepingCount = 0;
}
else if (Math.random() > 0.005)
{
this.currentPathTrack = "paused"
this.yCoord = this.yCoord - 40;
}
else
{
this.currentPathTrack = "down"
}
}
else if (this.xCoord == 672 && this.yCoord == 87)
{
this.sleepingCount++
if (this.sleepingCount > 700)
{
this.currentPathTrack = "down"
}
else
{
this.currentPathTrack = "paused"
}
}
//see if it switches to path two or not
else if (this.xCoord == 525 && this.yCoord == 218)
{
if (Math.random() > 0.99)
{
this.currentPathTrack = "right"
}
else
{
this.currentPathTrack = "left"
this.xCoord--;
this.currentPathName = "pathTwo"
}
}
break;
case "pathTwo" :
if
(
(this.xCoord == 301 && this.yCoord == 120) ||
(this.xCoord == 147 && this.yCoord == 183 ) ||
(this.xCoord == 210 && this.yCoord == 246 )
)
{
this.currentPathTrack = "down";
}
else if
(
(this.xCoord == 406 && this.yCoord == 218 ) ||
(this.xCoord == 462 && this.yCoord == 316 ) ||
(this.xCoord == 525 && this.yCoord == 274)
)
{
this.currentPathTrack = "up";
}
else if
(
(this.xCoord == 406 && this.yCoord == 120) ||
(this.xCoord == 301 && this.yCoord == 183)
)
{
this.currentPathTrack = "left"
}
else if
(
(this.xCoord == 147 && this.yCoord == 246 ) ||