Repository navigation
Expand file tree
/
Copy pathsketch.js
More file actions
2920 lines (2726 loc) · 116 KB
/
Copy pathsketch.js
File metadata and controls
2920 lines (2726 loc) · 116 KB
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
let menu = "loading" // main, game, night select, customNight, gameover, victory
let assetsLoaded = 0;
//all
let staticOverlay = null;
function setCameraOverlay(enabled) {
if (!staticOverlay) {
return;
}
staticOverlay.classList.toggle("fuzzy-overlay", enabled);
}
//main
let endCallButton;
let phoneCalling = false;
let level = "main"; // can be "main", "cameras"
let currentCam = 1;
let money = 45.00;
let camsDisabledTimer = 0;
let camFlipUpTimer = 0;
let camFlipDownTimer = 0;
let panelFlipUpTimer = 0;
let panelFlipDownTimer = 0;
let panelOpen = false;
let panelTurnOnTimer = 0;
let panelPage = "menu";
let camSwitchTimer = 0;
let characterMoveTimer = 0;
let numRects = 0;
let camButtons = [];
let seed = 0;
let moveQueue = [];
let internetUsage = 0;
let currentTranslate = 0;
let mainView;
let darrenInMainView = []
let evanInMainView = []
let seanInMainView = []
let ventOpen;
let michaelInOffice;
//buffers
let mainBuffer;
let cam2Buffer;
let cam9Buffer;
let camActivateBuffer;
let panelActivateBuffer;
//main images
let abdullahCam = []
let abdullahVentCam = []
let aidanCam = []
let alexCam = []
let alexHacker;
let darrenCam;
let darrenInDarrenCam = []
let evanInDarrenCam = []
let darrenVentCam = []
let evanCam = []
let hallwayCam;
let seanInHallwayCam = []
let evanInHallwayCam = []
let sahilCam = []
let jackCam = []
let seanCam = []
let jumpscares = []
let camUp = []
let camDown = []
let opaqueStatic = [];
let deathStatic = [];
let cameraMap;
let systemPanel;
let computerView;
let jumpscareQueue = "none";
let jumpscareTimer = 0;
let forceJumpscareTimer = 0;
let flickerTimer = 0;
//camera tool buttons
let ventLight;
let night = 1;
let time = 12;
let timeMS = 0;
//fps improvements
let mainNeedsRebuild = false;
let cam2NeedsRebuild = false;
let cam9NeedsRebuild = false;
let DEBUG = true;
let audioUnlocked = false;
let previousSeanPosition = 0;
let previousEvanPosition = 0;
let previousDarrenPosition = 0;
//main menu
let menuButtons = []
let newGameConfirm = false;
let menuCharacters = [[], [], []];
let char1Timer = 0;
let char2Timer = 0;
let char3Timer = 0;
let char1Twitching = 0;
let char2Twitching = 0;
let char3Twitching = 0;
let menuTransitionTimer = 0;
let newsPaper;
let newsPaperTransitionInTimer = 0;
let newsPaperTransitionOutTimer = 0;
let newsPaperTimer = 0;
let nightDescriptionTimer = 0;
let nightDescription = "NA"
let hasSeenNews = false;
//start screen
let nightStartSound;
//win screen
let winTimer = 0;
let winSound;
//dead screen
let abdullahJumpscare = [];
let aidanJumpscare = [];
let alexJumpscare = [];
let darrenJumpscare = [];
let evanJumpscare = [];
let jackJumpscare = [];
let seanJumpscare = [];
let scareTimer = 0;
let deadTimer = 0;
let jumpscareShakeTimer = 0;
let jumpscareBurstFired = false;
//all
let GAME_WIDTH = window.innerWidth;
let mainWidth = GAME_WIDTH * 1.2953125; // so max translate is 567 at 1080p
let GAME_HEIGHT = window.innerHeight;
let mainFont;
//characters
let sahil = {};
let abdullah = {};
let aidan = {};
let alex = {};
let darren = {};
let evan = {};
let jack = {};
let sean = {};
let michael = {};
let soundHolder = {}
sahil.active = 0;
sahil.position = 0;
sahil.timeSinceLastMoveAttempt = 0;
sahil.timeUntilNextPotentialMove = 30000;
sahil.ai = 1;
sahil.update = function() {
if (sahil.ai > 0 && sahil.active == 1) {
sahil.timeSinceLastMoveAttempt += deltaTime;
if (sahil.timeSinceLastMoveAttempt > sahil.timeUntilNextPotentialMove) {
if (random() < 0.5) {
sahil.position = 1;
debugLog("Sahil has moved to position " + sahil.position);
sahil.timeSinceLastMoveAttempt = 0;
sahil.timeUntilNextPotentialMove = random(40000 - sahil.ai * 1000, 40000);
if (sahil.isOnCam()) {
disableCams(2000)
}
}
}
}
}
sahil.isOnCam = function() {
if (level == "cameras" && currentCam == 1) {
return true;
}
return false;
}
// Abdullah
abdullah.active = 1;
abdullah.position = 0;
abdullah.attacking = 0;
abdullah.timeSinceLastMoveAttempt = 0;
abdullah.timeUntilNextMoveAttempt = 0;
abdullah.moveQueue = [];
abdullah.ai = 20;
// Call this once in a while
abdullah.tick = function() {
if (abdullah.active == 1) {
abdullah.timeSinceLastMoveAttempt += deltaTime;
if (abdullah.attacking == 0) {
if (abdullah.timeSinceLastMoveAttempt >= 10000) {
if (random() < abdullah.ai / 40) {
abdullah.attacking = 1;
abdullah.timeUntilNextMoveAttempt = random(15000 - abdullah.ai * 500, 15000);
} else {
abdullah.timeUntilNextMoveAttempt = random(5000 - abdullah.ai * 200, 5000);
}
abdullah.timeSinceLastMoveAttempt = 0;
}
} else {
if (abdullah.timeSinceLastMoveAttempt >= abdullah.timeUntilNextMoveAttempt) {
abdullah.timeSinceLastMoveAttempt = 0;
if (random() < abdullah.ai / 10) {
if (abdullah.isBeingLookedAtInVent()) {
//add abdullah's move to the move queue
debugLog("Abdullah is being looked at in the vent, so his move has been added to the move queue for position " + (abdullah.position + 1));
abdullah.active = 0; // this makes it so he doesn't move again until his move in the move queue is executed
moveQueue.push([abdullah, abdullah.position + 1]);
} else {
abdullah.position += 1;
debugLog("Abdullah has moved to position " + abdullah.position);
if (abdullah.isOnCam()) {
disableCams(2000)
}
}
if (abdullah.position == 5) {
if (!soundHolder.ventWalking.isPlaying()) {
soundHolder.ventWalking.play();
}
} else {
playWalkingSound();
}
}
if (abdullah.position == 6) {
jumpscareQueue = "abdullah";
abdullah.active = 0;
forceJumpscareTimer = random(5000, 10000); // if the jumpscare doesn't execute within 5 seconds, it will force execute
}
abdullah.timeUntilNextMoveAttempt = random(5000 - abdullah.ai * 200, 5000);
abdullah.timeSinceLastMoveAttempt = 0;
}
}
}
}
abdullah.isBeingLookedAtInVent = function() {
if (level == "cameras" && currentCam == 10 && abdullah.position >= 4 && abdullah.position <= 5 && mouseIsPressed) {
return true;
}
return false;
}
abdullah.isOnCam = function() {
//check if hes being seen on cam 7
if (level == "cameras" && currentCam == 7 && abdullah.position < 5 && camsDisabledTimer <= 0) {
return true;
}
return false;
}
// Aidan
aidan.active = 1;
aidan.position = 0;
aidan.attacking = 0;
aidan.timeSinceLastUpdate = 0;
aidan.ai = 20;
// Call this once in a while
aidan.tick = function() {
if (aidan.active == 1) {
aidan.timeSinceLastUpdate += deltaTime;
if (aidan.timeSinceLastUpdate >= 6000) {
aidan.timeSinceLastUpdate = 0;
if (aidan.attacking == 0) {
if (random() < aidan.ai / 40) {
aidan.position += 1;
debugLog("Aidan has moved to position " + aidan.position);
if (aidan.isOnCam()) {
disableCams(2000)
}
}
if (aidan.position == 6) {
aidan.attacking = 1;
debugLog("Aidan has started attacking");
// Play some audio queue (you can still save yourself)
}
} else {
// Aidan is attacking
aidan.position += 1;
debugLog("Aidan has moved to position " + aidan.position);
playWalkingSound();
if (aidan.isOnCam()) {
disableCams(2000)
}
if (aidan.position == 10) {
aidan.active = false;
jumpscareQueue = "aidan";
forceJumpscareTimer = random(5000, 10000); // if the jumpscare doesn't execute within 5 seconds, it will force execute
}
}
}
}
}
aidan.isOnCam = function() {
if (level == "cameras" && currentCam == 5 && camsDisabledTimer <= 0) {
return true;
}
return false;
}
// Alex
alex.position = 0;
alex.ai = 1;
alex.active = 1;
alex.target = "none"
alex.killTimer = 0;
alex.calmProgress = 0;
// Should call this every second
alex.tick = function() {
if (alex.ai > 0 && alex.active == 1) {
if (level == "cameras") {
alex.changeInternetUsage(deltaTime);
} else {
alex.changeInternetUsage(-deltaTime / (Math.max(alex.ai / 2, 1))); // internet usage decreases while not in cameras
}
} else if (alex.killTimer > 0) {
//alex has a target
alex.killTimer -= deltaTime;
if (alex.killTimer <= 0) {
jumpscareQueue = "alex";
forceJumpscareTimer = random(5000, 10000); // if the jumpscare doesn't execute within 5 seconds, it will force execute
alex.active = 0;
}
}
}
alex.changeInternetUsage = function(amount) {
if (alex.ai > 0 && alex.active == 1) {
internetUsage += amount;
internetUsage = max(0, internetUsage);
let oldPosition = alex.position;
if (internetUsage < 10000) {
alex.position = 0;
} else if (internetUsage < 20000) {
alex.position = 1;
} else if (internetUsage < 30000) {
alex.position = 2;
} else if (internetUsage < 40000) {
alex.position = 3;
} else if (internetUsage < 50000) {
alex.position = 4;
} else if (internetUsage < 60000) {
alex.position = 5;
//play some audio queue
} else {
alex.position = 6;
alex.active = 0;
alex.target = floor(random(1, 12)); // pick a random cam to hack
alex.calmProgress = 1000;
alex.killTimer = 20000 - alex.ai * 200;
}
if (oldPosition != alex.position) {
playWalkingSound();
debugLog("Alex has moved to position " + alex.position);
if (alex.isOnCam()) {
disableCams(2000)
}
}
}
}
alex.isOnCam = function() {
if (level == "cameras" && currentCam == 3 && camsDisabledTimer <= 0) {
return true;
}
return false;
}
// Darren
darren.active = 1;
darren.position = 0;
darren.timeSinceLastMoveAttempt = 0;
darren.name = "Darren";
darren.siphoning = false;
darren.timeSinceLastMoneySteal = 0;
darren.moveQueue = [];
darren.ai = 20;
// Call every second
darren.tick = function() {
if (darren.active == 1) {
if (!darren.siphoning) {
darren.timeSinceLastMoveAttempt += deltaTime;
if (darren.timeSinceLastMoveAttempt >= 7500) {
darren.timeSinceLastMoveAttempt = 0;
// darren is just always moving towards you, you can pause him (reset updatesSinceLastMove and set his position to 6) by flashing the light on him in his vent.
// I guess you could just keep pausing him but its kind of a waste of time so you have to balance it. Maybe the crazy hard nights where you get no money you basically have to keep him paused the entire time.
if (random() < darren.ai / 20) {
if (darren.isBeingLookedAt()) {
//add darren's move to the move queue
debugLog("Darren is being looked at in main, so his move has been added to the move queue for position " + (darren.position + 1));
darren.active = 0; // this makes it so he doesn't move again until his move in the move queue is executed
moveQueue.push([darren, darren.position + 1]);
} else if (darren.isBeingLookedAtInVent()) {
//add darren's move to the move queue
debugLog("Darren is being looked at in vent, so his move has been added to the move queue for position " + (darren.position + 1));
darren.active = 0; // this makes it so he doesn't move again until his move in the move queue is executed
darren.moveQueue.push([darren, darren.position + 1]);
} else {
darren.position += 1;
debugLog("Darren has moved to position " + darren.position);
if (darren.isOnCam()) {
disableCams(2000)
}
if (darren.position >= 3 && darren.position <= 6) {
mainNeedsRebuild = true;
}
}
if (darren.position == 7) {
if (!soundHolder.ventWalking.isPlaying()) {
soundHolder.ventWalking.play();
}
} else if (darren.position == 10) {
// play some audio queue
// darren steals some money
debugLog("Darren has started siphoning money");
darren.siphoning = true;
mainNeedsRebuild = true;
} else {
playWalkingSound();
}
}
darren.timeSinceLastMoveAttempt = 0;
}
} else {
// darren is stealing 10 cents per second, he has opened the vent and you need to close it.
// When he first appears, he immediately steals 5 dollars.
if (darren.timeSinceLastMoneySteal >= 1000) {
darren.timeSinceLastMoneySteal -= 1000;
money -= darren.ai / 10 + 0.5;
if (money <= 0) {
// darren kills you
darren.active = 0;
jumpscareQueue = "darren";
forceJumpscareTimer = random(5000, 10000); // if the jumpscare doesn't execute within 5 seconds, it will force execute
}
}
darren.timeSinceLastMoneySteal += deltaTime;
}
}
}
darren.isBeingLookedAt = function() {
//this only checks if hes being looked at in the main view
if (level == "main" && (darren.position >= 3 && darren.position <= 5) && currentTranslate < mainWidth - GAME_WIDTH) {
return true;
}
return false;
}
darren.isBeingLookedAtInVent = function() {
if (level == "cameras" && currentCam == 11 && darren.position >= 6 && darren.position <= 8 && mouseIsPressed && camsDisabledTimer <= 0 && ventLight.checkClicked()) {
return true;
}
return false;
}
darren.isOnCam = function() {
if (level == "cameras" && currentCam == 9 && darren.position <= 3 && camsDisabledTimer <= 0) {
return true;
}
return false;
}
// Evan
evan.active = 1;
evan.position = 0;
evan.target = "office"
evan.previousTarget = "office";
evan.name = "Evan";
evan.timeSinceLastMove = 0;
evan.ai = 20;
evan.tick = function() {
//this logic is really confusing
if (evan.active == 1) {
evan.timeSinceLastMove += deltaTime;
if (evan.timeSinceLastMove >= 4500) {
if (random() < evan.ai / 20) {
let isMoveQueued = false;
let oldPosition = evan.position;
if (evan.isOnCam()) {
disableCams(2000)
}
if (evan.isBeingLookedAt()) {
isMoveQueued = true;
}
switch (evan.target) {
case "office":
if (evan.position <= 6) {
evan.position += 1;
} else if (evan.position == 8 || evan.position == 9) {
evan.position += 1;
} else if (evan.position == 10) {
evan.position = 7; //hallway end of hall
} else if (evan.position == 7) {
evan.position = 11;
} else {
evan.active = 0;
jumpscareQueue = "evan";
forceJumpscareTimer = random(5000, 10000); // if the jumpscare doesn't execute within 5 seconds, it will force execute
}
break;
case "evansRoom":
if (evan.position >= 4 && evan.position <= 7) {
evan.position -= 1;
} else if (evan.position <= 3) {
evan.position = 0
evan.target = "office";
stopDanceMonkey();
// turn off the music
} else if (evan.position == 8 || evan.position == 9) {
evan.position += 1;
} else if (evan.position == 10 || evan.position == 11) {
evan.position = 7; //hallway end of hall
}
break;
case "darrensRoom":
if (evan.position <= 6) {
evan.position += 1;
} else if (evan.position <= 10) {
evan.position = 8; // made it to darrens room
evan.target = "office";
mainNeedsRebuild = true;
// turn off the music
stopDanceMonkey();
} else if (evan.position == 11) {
evan.position = 7; //hallway end of hall
}
break;
}
if (evan.isOnCam()) {
disableCams(2000)
}
if (evan.isBeingLookedAt()) {
isMoveQueued = true;
}
if (evan.isOnCam()) {
disableCams(2000)
}
if (isMoveQueued) {
//add evan's move to the move queue
moveQueue.push([evan, evan.position]);
evan.active = 0; // this makes it so he doesn't move again until his move in the move queue is executed
evan.position = oldPosition; // reset his position until the move queue executes his move
debugLog("Evan is being looked at, so his move has been added to the move queue for position " + evan.position);
} else if (evan.position == 7 || evan.position == 11 || evan.position == 7 || evan.position == 11) {
mainNeedsRebuild = true;
playWalkingSound();
debugLog("Evan has moved to position " + evan.position);
} else {
playWalkingSound();
debugLog("Evan has moved to position " + evan.position);
}
}
evan.timeSinceLastMove = 0;
}
}
}
evan.isBeingLookedAt = function() {
//only check main
if (level == "main" && (evan.position == 7 || evan.position == 11) && currentTranslate < mainWidth - GAME_WIDTH) {
return true;
}
return false;
}
evan.isOnCam = function() {
//check evan cam
if (level == "cameras" && currentCam == 4 && evan.position <= 2 && camsDisabledTimer <= 0) {
return true;
}
//check hallway cam
if (level == "cameras" && currentCam == 2 && evan.position >= 4 && evan.position <= 6 && camsDisabledTimer <= 0) {
return true;
}
//check darren cam
if (level == "cameras" && currentCam == 9 && evan.position >= 8 && evan.position <= 10 && camsDisabledTimer <= 0) {
return true;
}
return false;
}
// Jack
jack.position = 0;
jack.angerLevel = 0;
jack.timeSinceLastAngerIncreaseChance = 0;
jack.ai = 1;
jack.oldPosition = 0;
jack.active = 1;
jack.tick = function() {
if (jack.ai > 0) {
jack.timeSinceLastAngerIncreaseChance += deltaTime;
if (jack.timeSinceLastAngerIncreaseChance >= 10000) {
jack.timeSinceLastAngerIncreaseChance = 0;
if (random() < jack.ai / 20) {
jack.increaseAnger(1);
}
}
}
}
jack.increaseAnger = function(amount) {
if (jack.ai > 0 && jack.active == 1) {
let oldPosition = jack.position;
jack.angerLevel += amount;
if (jack.angerLevel < 10) {
jack.position = 0;
} else if (jack.angerLevel < 20) {
jack.position = 1;
} else if (jack.angerLevel < 30) {
jack.position = 2;
} else if (jack.angerLevel < 40) {
jack.position = 3;
} else if (jack.angerLevel < 50) {
jack.position = 4;
} else if (jack.angerLevel < 60) {
jack.position = 5;
} else {
jack.position = 6;
jack.active = 0;
jumpscareQueue = "jack";
forceJumpscareTimer = random(5000, 10000); // if the jumpscare doesn't execute within 5 seconds, it will force execute
}
if (jack.isOnCam() && camsDisabledTimer <= 0) {
disableCams(2000)
}
if (jack.position != oldPosition) {
playWalkingSound();
debugLog("Jack has moved to position " + jack.position);
}
jack.oldPosition = jack.position;
}
}
jack.isOnCam = function() {
if (level == "cameras" && currentCam == 8 && camsDisabledTimer <= 0) {
return true;
}
return false;
}
// Sean
sean.active = 1;
sean.position = 0;
sean.timeSinceLastMoveAttempt = 0;
sean.name = "Sean";
sean.ai = 20;
sean.killTimer = 0;
sean.attackQueued = false;
sean.attackPrevented = false;
sean.attackRecoveryTimer = 0;
sean.forceAttackTimer = 0;
sean.tick = function() {
if (sean.ai > 0 && sean.active == 1) {
if (sean.killTimer <= 0) {
sean.timeSinceLastMoveAttempt += deltaTime;
if (sean.isOnCam()) {
sean.timeSinceLastMoveAttempt = 0;
}
if (sean.timeSinceLastMoveAttempt > 6500) {
if (random() < sean.ai / 20) {
sean.timeSinceLastMoveAttempt = 0;
let oldPosition = sean.position;
let option = random();
let isMoveQueued = false
if (sean.isOnCam()) {
disableCams(2000)
}
if (sean.isBeingLookedAtInMainView()) {
isMoveQueued = true;
}
if (option < 0.1) {
debugLog("Sean has stayed in the same position");
// stay in the same position
//make a sound cue
} else if (option < 0.5) {
// teleport to random position
sean.position = floor(random(sean.position, 11)); // there are 10 positions he can be in on the cam/main view, from 0 to 10
debugLog("Sean has teleported to position " + sean.position);
//make a sound cue
} else if (option < 0.9) {
// move towards the player
if (sean.position < 11) {
sean.position += 1;
}
playWalkingSound();
debugLog("Sean has moved towards the player to position " + sean.position);
} else {
// move away from the player
if (sean.position > 0) {
sean.position -= 1;
}
playWalkingSound();
debugLog("Sean has moved away from the player to position " + sean.position);
}
if (sean.isOnCam()) {
disableCams(2000)
}
if (sean.isBeingLookedAtInMainView()) {
isMoveQueued = true;
}
if (isMoveQueued) {
//add sean's move to the move queue
moveQueue.push([sean, sean.position]);
sean.active = 0;
sean.position = oldPosition; // reset his position until the move queue executes his move
debugLog("Sean is being looked at in the main view, so his move has been added to the move queue for position " + sean.position);
} else if (sean.position != oldPosition && (((sean.position >= 7 && sean.position <= 9) || sean.position == 11) || ((oldPosition >= 7 && oldPosition <= 9) || oldPosition == 11))) {
mainNeedsRebuild = true;
}
if (sean.position == 11) {
// do the sean event where he appears in the main view and you have to do some quick time event to make him go away
// if you fail he kills you
if (level == "main") {
sean.attackPrevented = false;
sean.killTimer = 2000 - sean.ai * 50;
soundHolder.seanAppear.play();
} else {
sean.attackQueued = true;
sean.forceAttackTimer = random(4000, 10000);
}
}
}
}
} else {
//seans position is 11,
sean.killTimer -= deltaTime;
if (sean.killTimer <= 0) {
if (sean.attackPrevented) {
sean.position = floor(random(0, 3)); // 0, 1, or 2
} else {
sean.active = 0;
sean.position = 3; //position where hes nowhere to be seen on cams or main
}
sean.attackRecoveryTimer = 4000; //after sean attacks, the screen will fade back in for 2 seconds
soundHolder.seanAppear.stop();
mainNeedsRebuild = true;
disableCams(2000);
}
}
}
}
sean.isOnCam = function() {
if (level == "cameras" && ((currentCam == 6 && sean.position <= 2) || (currentCam == 2 && sean.position >= 4 && sean.position <= 6)) && camsDisabledTimer <= 0) {
return true;
}
return false;
}
sean.isBeingLookedAtInMainView = function() {
if (level == "main" && (sean.position >= 7 && sean.position <= 9) && currentTranslate < mainWidth - GAME_WIDTH) {
return true;
}
return false;
}
michael = {}
michael.ai = 1;
michael.position = 0;
michael.affectedCharacter = -1;
michael.timeSinceLastFlickerChance = 0;
michael.update = function() {
if (michael.position == 0) {
if (random() < michael.ai / 100) {
michael.position = 1;
//increase one random characters ai to 20
michael.affectedCharacter = floor(random(0, 7));
switch (michael.affectedCharacter) {
case 0:
if (abdullah.ai == 0) {
abdullah.position = 0;
}
abdullah.ai += 10;
break;
case 1:
if (aidan.ai == 0) {
aidan.position = 0;
}
aidan.ai += 10;
break;
case 2:
if (alex.ai == 0) {
alex.position = 0;
}
alex.ai += 10;
break;
case 3:
if (darren.ai == 0) {
darren.position = 0;
}
darren.ai += 10;
break;
case 4:
if (evan.ai == 0) {
evan.position = 0;
}
evan.ai += 10;
break;
case 5:
if (jack.ai == 0) {
jack.position = 0;
}
jack.ai += 10;
break;
case 6:
if (sean.ai == 0) {
sean.position = 0;
}
sean.ai += 10;
break;
}
mainNeedsRebuild = true;
}
} else {
if (random() < michael.ai / 40) {
michael.position = 0;
switch (michael.affectedCharacter) {
case 0:
abdullah.ai -= 5;
break;
case 1:
aidan.ai -= 5;
break;
case 2:
alex.ai -= 5;
break;
case 3:
darren.ai -= 5;
break;
case 4:
evan.ai -= 5;
break;
case 5:
jack.ai -= 5;
break;
case 6:
sean.ai -= 5;
break;
}
mainNeedsRebuild = true;
}
}
}
michael.tick = function() {
if (michael.ai == 20) {
michael.timeSinceLastFlickerChance += deltaTime;
if (michael.timeSinceLastFlickerChance >= 5000) {
michael.timeSinceLastFlickerChance = 0;
if (random() < michael.ai / 40) {
michael.update();
if (level == "main") {
flickerTimer = 500;
soundHolder.michaelFlicker.play();
let moveExecuted = false;
for (let i of moveQueue) {
i[0].position = i[1];
i[0].active = 1; // make the character active again after their move has been executed
debugLog("Executed a move in the move queue for " + i[0].name + ", their new position is " + i[1]);
moveExecuted = true;
}
if (moveExecuted) {
mainNeedsRebuild = true;
cam2NeedsRebuild = true;
cam9NeedsRebuild = true;
playWalkingSound();
}
moveQueue = [];
}
}
}
}
}
class CamButton {
constructor(xPos, yPos, camNum) {
this.xPos = xPos;
this.yPos = yPos;
this.camNum = camNum;
this.disabled = false;
this.activeClock = 0;
}
draw() {
push();
if (currentCam == this.camNum) {
this.activeClock += deltaTime;
if (this.activeClock > 2000) {
this.activeClock = 0;
}
if (this.activeClock > 1000) {
fill(96, 150, 96, 180);
} else {
fill(96, 96, 96, 180);
}
} else {
fill(96, 96, 96, 180);
}
stroke(255);
strokeWeight(GAME_WIDTH * 0.0025);
rect(this.xPos * GAME_WIDTH, this.yPos * GAME_HEIGHT, 0.06 * GAME_WIDTH, 0.06 * GAME_HEIGHT);
pop();
push();
textSize(0.018 * GAME_WIDTH);
textFont(mainFont);
fill(255);
text("Cam" + (this.camNum).toString().padStart(2, '0'), this.xPos * GAME_WIDTH + 0.003 * GAME_WIDTH, this.yPos * GAME_HEIGHT + 0.055 * GAME_HEIGHT);
pop();
}
checkClicked() {
if (mouseX > this.xPos * GAME_WIDTH && mouseX < (this.xPos + 0.06) * GAME_WIDTH && mouseY > this.yPos * GAME_HEIGHT && mouseY < (this.yPos + 0.06) * GAME_HEIGHT) {
return true;
}
return false;
}
}
class CamTool {
constructor(xPos, yPos, text) {
this.xPos = xPos;
this.yPos = yPos;
this.GAME_WIDTH = 0.15;
this.GAME_HEIGHT = 0.1;
this.text = text;
}
draw() {
push();
fill(96, 96, 96, 180);
stroke(255);
strokeWeight(5);
rect(this.xPos * GAME_WIDTH, this.yPos * GAME_HEIGHT, this.GAME_WIDTH * GAME_WIDTH, this.GAME_HEIGHT * GAME_HEIGHT);
pop();
push();
textSize(0.03 * GAME_WIDTH);
textFont(mainFont);
fill(255);
textLeading(0.04 * GAME_HEIGHT);
text(this.text, this.xPos * GAME_WIDTH + 0.003 * GAME_WIDTH, this.yPos * GAME_HEIGHT + 0.05 * GAME_HEIGHT);
pop();
}
checkClicked() {
if (mouseX > this.xPos * GAME_WIDTH && mouseX < (this.xPos + this.GAME_WIDTH) * GAME_WIDTH && mouseY > this.yPos * GAME_HEIGHT && mouseY < (this.yPos + this.GAME_HEIGHT) * GAME_HEIGHT) {
return true;
}
return false;
}
}
class PanelButton {
constructor(text, row) {
this.text = text;
this.row = row;
this.offset = GAME_HEIGHT * 0.05 * row;
this.bbox = mainFont.textBounds(this.text, 0.55 * GAME_WIDTH, 0.4 * GAME_HEIGHT + this.offset, 0.018 * GAME_WIDTH);
this.actionTimer = 0;
}
draw() {
push();
textSize(0.018 * GAME_WIDTH);
textFont(mainFont);
fill(255);
let addition = " ";
if (this.actionTimer > 0) {
let numDots = 3 - floor(this.actionTimer / 333) % 3;
for (let i = 0; i < numDots; i++) {
addition += ".";
}
}
text(this.text + addition, 0.55 * GAME_WIDTH, 0.4 * GAME_HEIGHT + this.offset);
pop();
}
checkClicked() {
if (mouseX > this.bbox.x && mouseX < this.bbox.x + this.bbox.w && mouseY > this.bbox.y && mouseY < this.bbox.y + this.bbox.h) {
return true;
}
return false;
}
tick() {
if (this.actionTimer > 0) {
this.actionTimer = max(0, this.actionTimer - deltaTime);
}
}
}
class MenuButton {
constructor(text, xPos, yPos) {
this.text = text;
this.xPos = xPos;
this.yPos = yPos;
this.visible = true;
this.bbox = mainFont.textBounds(this.text, this.xPos * GAME_WIDTH, this.yPos * GAME_HEIGHT, 0.03 * GAME_WIDTH);
}
draw() {
if (!this.visible) {
return;
}
push();
textSize(0.03 * GAME_WIDTH);
if (this.checkClicked()) {
fill(200);
} else {
fill(255);