-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.html
1830 lines (1475 loc) · 100 KB
/
game.html
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
<!DOCTYPE html>
<html>
<head>
<title>RogueLike DungeonCrawler</title>
<style type="text/css">
#gameCanvas {
background-color: black ;
display: block ;
}
</style>
</head>
<body style="background-color: black ;">
<canvas id="gameCanvas" width ="1520" height = "740" style="cursor: none;" onmousemove="setMouseAimPosition(event)" onclick="setMouseAimClickPosition(event)"></canvas>
<script type="text/javascript">
// to avoid typos
'use strict'
var gameStatus , stopRequestingAnimationFrame = false , coinsCollected = 0 ;
// thsese variables are for testing purpose
var displayDungeonVision = true , displayDoorKey = false , protagonistCollisionOn = true , levelTimer = true ;
// canvas and context for drawing
var canvas = document.getElementById("gameCanvas") , context = canvas.getContext("2d") , This ;
// all constructors name will be of UpperCamelCase and all its objects name will be of lowerCamelCase
function MouseAim () {
this.x ;
this.y ;
this.clickAtX ;
this.clickAtY ;
this.height = 50 ;
this.width = 50 ;
}
var mouseAim = new MouseAim() ;
// setting mouse target image's position when moved over canvas
function setMouseAimPosition (e) {
mouseAim.x = e.clientX - canvas.offsetLeft ;
mouseAim.y = e.clientY - canvas.offsetTop ;
}
// setting the click co-ordinates of mouse when clicked on canvas
function setMouseAimClickPosition (e) {
mouseAim.clickAtX = e.clientX - canvas.offsetLeft ;
mouseAim.clickAtY = e.clientY - canvas.offsetTop ;
controls.throwProjectile = true ;
}
// this class is to enable player to configure the keys according to their wish, default values are as follows
function CustomisedControlsKeyCode () {
this.navigation = {"north" : "w".charCodeAt(0) , "south" : "s".charCodeAt(0) , "west" : "a".charCodeAt(0) , "east" : "d".charCodeAt(0)} ;
this.others = {"goBack" : 27 , "interact" : "e".charCodeAt(0) , "placeMine" : "f".charCodeAt(0)} ; // 27 is the keyCode for 'esc' key
this.weapon = {"stone" : "z".charCodeAt(0) , "grenade" : "x".charCodeAt(0) , "flashbang" : "c".charCodeAt(0) , "mine" : "v".charCodeAt(0)} ;
this.transformation = {"professor" : "1".charCodeAt(0) , "combatant" : "2".charCodeAt(0) , "escapist" : "3".charCodeAt(0) , "eagle" : "4".charCodeAt(0)} ;
}
var customisedControlsKeyCode = new CustomisedControlsKeyCode() ;
// if the keys corresponding to that in object 'customisedControlsKeyCode' are pressed, corresponding properties of object 'controls' will be set to 'true' to be executed later
function Controls () {
this.navigation = {"north" : false , "south" : false , "west" : false , "east" : false} ;
this.others = {"goBack" : false , "interact" : false , "placeMine" : false} ;
this.weapon = {"stone" : false , "grenade" : false , "flashbang" : false , "mine" : false} ;
this.transformation = {"professor" : false , "combatant" : false , "escapist" : false , "eagle" : false} ;
}
var controls = new Controls() ;
document.addEventListener("keydown",listenerForKeyDown) ;
// the function that gets executed when keydown occurs
function listenerForKeyDown (e) {
var x ;
for (x in customisedControlsKeyCode.navigation) {
if (e.keyCode == customisedControlsKeyCode.navigation[x])
{controls.navigation[x] = true ;}
else
{controls.navigation[x] = false ;}
if (e.key.charCodeAt(0) == customisedControlsKeyCode.navigation[x])
{controls.navigation[x] = true ;}
else
{controls.navigation[x] = false ;}
}
for (x in customisedControlsKeyCode.weapon) {
if (e.keyCode == customisedControlsKeyCode.weapon[x])
{controls.weapon[x] = true ;}
if (e.key.charCodeAt(0) == customisedControlsKeyCode.weapon[x])
{controls.weapon[x] = true ;}
}
for (x in customisedControlsKeyCode.transformation) {
if (e.keyCode == customisedControlsKeyCode.transformation[x])
{controls.transformation[x] = true ;}
if (e.key.charCodeAt(0) == customisedControlsKeyCode.transformation[x])
{controls.transformation[x] = true ;}
}
for (x in customisedControlsKeyCode.others) {
if (e.keyCode == customisedControlsKeyCode.others[x])
{controls.others[x] = true ;}
if (e.key.charCodeAt(0) == customisedControlsKeyCode.others[x])
{controls.others[x] = true ;}
}
}
document.addEventListener("keyup",listenerForKeyUp) ;
// the function that gets executed when keyup occurs
function listenerForKeyUp (e) {
var x ;
for (x in customisedControlsKeyCode.navigation) {
if (e.keyCode == customisedControlsKeyCode.navigation[x])
{controls.navigation[x] = false ;}
if (e.key.charCodeAt(0) == customisedControlsKeyCode.navigation[x])
{controls.navigation[x] = false ;}
}
for (x in customisedControlsKeyCode.transformation) {
if (e.keyCode == customisedControlsKeyCode.transformation[x])
{controls.transformation[x] = false ;}
if (e.key.charCodeAt(0) == customisedControlsKeyCode.transformation[x])
{controls.transformation[x] = false ;}
}
for (x in customisedControlsKeyCode.others) {
if (e.keyCode == customisedControlsKeyCode.others[x])
{controls.others[x] = false ;}
if (e.key.charCodeAt(0) == customisedControlsKeyCode.others[x])
{controls.others[x] = false ;}
}
}
// dungeon vision for each character is already loaded as loading them when switching between characters will cause blinking effect in the game
function DungeonVision () {
this.professor = document.createElement("IMG") ;
this.professor.src = "images/professor dungeon vision.png" ;
this.combatant = document.createElement("IMG") ;
this.combatant.src = "images/combatant dungeon vision.png" ;
this.escapist = document.createElement("IMG") ;
this.escapist.src = "images/escapist dungeon vision.png" ;
this.eagle = document.createElement("IMG") ;
this.eagle.src = "images/eagle dungeon vision.png" ;
}
// all images and sprite sheets for a seperate class resp, and a global object from each class is created which will be used in the game
function Images () {
this.dungeonVision = new DungeonVision() ;
this.dungeonBasicLayout = document.createElement("IMG") ;
this.dungeonBasicLayout.src = "images/dungeon_basic_layout.png" ;
this.wallWithShadow = document.createElement("IMG") ;
this.wallWithShadow.src = "images/wall_with_shadow.png" ;
this.damagedWallWithShadow = document.createElement("IMG") ;
this.damagedWallWithShadow.src = "images/damaged wall_with_shadow.png" ;
this.wallWithoutShadow = document.createElement("IMG") ;
this.wallWithoutShadow.src = "images/wall_without_shadow.png" ;
this.damagedWallWithoutShadow = document.createElement("IMG") ;
this.damagedWallWithoutShadow.src = "images/damaged wall_without_shadow.png" ;
this.dungeonFloorTile = document.createElement("IMG") ;
this.dungeonFloorTile.src = "images/dungeon_floor_tile.png" ;
this.mouseAim = document.createElement("IMG") ;
this.mouseAim.src = "images/mouse_aim.png" ;
this.exitDoorKey = document.createElement("IMG") ;
this.exitDoorKey.src = "images/exit_door_key.png" ;
this.instructions = document.createElement("IMG") ;
this.instructions.src = "images/Instructions.png" ;
this.readInstructions = document.createElement("IMG") ;
this.readInstructions.src = "images/read instructions tip.png" ;
this.mine = document.createElement("IMG") ;
this.mine.src = "images/mine.png" ;
}
// global image object which contains all images to be used in the game
var images = new Images () ;
// this is similar to dungeon vision constructor, the sprite sheet for each protagonist character is already loaded
function ProtagonistMovementSpriteSheets () {
this.professor = document.createElement("IMG") ;
this.professor.src = "sprite_sheets/professor_movement_sprite.png" ;
this.combatant = document.createElement("IMG") ;
this.combatant.src = "sprite_sheets/combatant_movement_sprite.png" ;
this.escapist = document.createElement("IMG") ;
this.escapist.src = "sprite_sheets/escapist_movement_sprite.png" ;
this.eagle = document.createElement("IMG") ;
this.eagle.src = "sprite_sheets/eagle_movement_sprite.png" ;
}
function SpriteSheets () {
this.protagonistMovement = new ProtagonistMovementSpriteSheets () ;
this.coinRotation = document.createElement("IMG") ;
this.coinRotation.src = "sprite_sheets/rotating_coin_sprite.png" ;
this.exitDoorOpening = document.createElement("IMG") ;
this.exitDoorOpening.src = "sprite_sheets/exit_door_opening.png" ;
this.characterTransformation = document.createElement("IMG") ;
this.characterTransformation.src = "sprite_sheets/transformation sprite sheet.png";
this.numbersFrom0To9 = document.createElement("IMG") ;
this.numbersFrom0To9.src = "sprite_sheets/numbers.png" ;
this.vulnerableProfessor = document.createElement("IMG") ;
this.vulnerableProfessor.src = "sprite_sheets/vulnerable professor.png";
this.burningTree = document.createElement("IMG") ;
this.burningTree.src = "sprite_sheets/burning tree sprite.png";
this.angel = document.createElement("IMG") ;
this.angel.src = "sprite_sheets/Sprite_old_woman_walk.png";
this.stone = document.createElement("IMG") ;
this.stone.src = "sprite_sheets/pebble sprite.png";
this.grenade = document.createElement("IMG") ;
this.grenade.src = "sprite_sheets/grenade sprite.png";
this.flashbang = document.createElement("IMG") ;
this.flashbang.src = "sprite_sheets/flashbang sprite.png";
this.projectileTarget = document.createElement("IMG") ;
this.projectileTarget.src = "sprite_sheets/projectile target.png";
this.grenadeExplosion = document.createElement("IMG") ;
this.grenadeExplosion.src = "sprite_sheets/grenade explosion sprite.png";
this.smokeGrenadeExplosion = document.createElement("IMG") ;
this.smokeGrenadeExplosion.src = "sprite_sheets/smoke explosion sprite.png";
this.postExplosionSmoke = document.createElement("IMG") ;
this.postExplosionSmoke.src = "sprite_sheets/post explosion sprite.png";
}
// global sprite sheet object, which contains all animatable sprite sheets
var spriteSheets = new SpriteSheets () ;
function AudioFiles () {
this.levelCompleted = document.createElement("AUDIO") ;
this.levelCompleted.src = "audio files/azumanga_on_finishing_level.mp3" ;
this.levelCompleted.volume = 0.5 ;
this.gameOver = document.createElement("AUDIO") ;
this.gameOver.src = "audio files/time out air horn.mp3" ;
this.gameOver.volume = 0.2 ;
this.minuteReminder = document.createElement("AUDIO") ;
this.minuteReminder.src = "audio files/metal gong sound.mp3" ;
this.minuteReminder.volume = 0.04 ;
this.lastFewSeconds = document.createElement("AUDIO") ;
this.lastFewSeconds.src = "audio files/last few seconds countdown sound.mp3" ;
this.lastFewSeconds.volume = 0.03 ;
this.keyCollection = document.createElement("AUDIO") ;
this.keyCollection.src = "audio files/magic_chime_on_collecting_the_keys.mp3" ;
this.keyCollection.volume = 0.5 ;
this.coinCollection = document.createElement("AUDIO") ;
this.coinCollection.src = "audio files/magic_chime_on_collecting_coin.mp3" ;
this.coinCollection.volume = 0.02 ;
this.protagonistIntro = document.createElement("AUDIO") ;
this.protagonistIntro.src = "audio files/power up sound effect.mp3" ;
this.protagonistIntro.volume = 0.02 ;
this.clue = document.createElement("AUDIO") ;
this.clue.src = "audio files/main_boss_door_key_sound_clue.mp3" ;
this.clue.volume = 1.0 ;
// the src of the file will change upon changing the character
this.protagonistMovementSound = document.createElement("AUDIO") ;
this.protagonistMovementSound.src = "audio files/professor movement sound.mp3" ;
this.protagonistMovementSound.volume = 0.1 ;
this.burningTreeSound = document.createElement("AUDIO") ;
this.burningTreeSound.src = "audio files/burning tree sound.mp3" ;
this.burningTreeSound.volume = 0.1 ;
this.projectileSound = [] ;
}
var audioFiles = new AudioFiles () ;
// objects that are common to all level ends here
// many intervals are used to animate sprite sheets in the game, all these form a seperate class as clearing these intervals once the level gets over will be easy
function TimeIntervals () {
this.protagonistMovement = false ;
this.levelCountdown = false ;
this.coinRotation = false ;
this.exitDoorOpening = false ;
this.levelCutScene = false ; // when level intro and ending
this.characterTransformation = false ; // while switching between diff characters
this.burningTree = false ;
this.angel = false ;
this.projectileAnimation = false ;
this.projectileTargetAnimation = false ;
this.grenadeExplosion = false ;
this.smokeGrenadeExplosion = false ;
this.postExplosionSmoke = false ;
}
// a new timeInterval object will be created as a property of level object.
// dungeon pillars and walls come under this category
function Obstacle (X,Y) {
this.x = X ;
this.y = Y ;
// height and width of obstacle are 100 px
this.shadowed = true; // this is true by default because all pillars are by default shadowed in the basic layout
this.type = null ; // type is only for walls and not for pillars
this.damage = false ;
this.getBoundary = function () {
if (this.shadowed) {
return {"north":this.y-100/2 , "east":this.x+100/2 , "west":this.x-100/2 , "south":this.y+100/2-35 } ;
} else {
return {"north":this.y-100/2 , "east":this.x+100/2 , "west":this.x-100/2 , "south":this.y+100/2 } ;
}
}
}
// all common animatables come under this category
function Animatable (X,Y,w,h,tAF) {
this.x = X ;
this.y = Y ;
this.height = h ;
this.width = w ;
this.totalAnimationFrames = tAF ;
this.currentHorizontalAnimationFrameIndex = 0 ;
this.hidden = false ;
this.getBoundary = function () {
if (this.x && this.y) {
return { "north":this.y-this.height/2 , "east":this.x+this.width/2 , "west":this.x-this.width/2 , "south":this.y+this.height/2 } ;
}
}
}
// example transformation animation , door openening ainimation etc...
function CountdownAnimatable (m,s) {
this.width = 534/10 ;
this.height = 75 ;
this.minutes = m ;
this.seconds = s ;
}
// this object gives the AI the choices of direction that are available at that point for the AI to turn
function TurnPosition (X,Y) {
this.x = X ;
this.y = Y ;
this.availableTurnDirections = ["north" , "south" , "east" , "west"] ;
this.unexploredDirections = [] ;
}
function Projectile (sX,sY,dX,dY,type,projectionAngle,owner) {
this.owner = owner ;
this.type = type ;
this.strikeRadius = (type == "stone" ? 100 : type == "flashbang" ? 160 : 150) ;
this.animation = new Animatable(sX,sY,10,10,8) ;
this.targetAnimation = new Animatable(undefined,undefined,50,25,6) ;
this.destination = { x : dX , y : dY } ;
this.range = Math.sqrt( Math.pow((dX-sX),2) + Math.pow((dY-sY),2) ) ;
this.projectionAngle = projectionAngle ;
this.gravity = 0.05 ;
this.speed = Math.sqrt(this.range*this.gravity/Math.sin(2*this.projectionAngle)) ;
this.clickAngle ;
this.velocity ;
this.acceleration ;
//depending upon speed , gravity , angle of projection the time taken for the projectile to reach the destination varies
this.initialize = function () {
if (dX >= sX && dY >= sY) {
// 4th quadrant
this.clickAngle = Math.atan( Math.abs( (dX-sX)/(dY-sY) ) ) ;
this.velocity = { x : this.speed*Math.sin(this.projectionAngle + this.clickAngle) , y : this.speed*Math.cos(this.projectionAngle + this.clickAngle) } ;
this.acceleration = { x : -1*this.gravity*Math.cos(this.clickAngle) , y : this.gravity*Math.sin(this.clickAngle) } ;
} else if (dX >= sX && dY <= sY) {
// 4th quadrant
this.clickAngle = Math.atan( Math.abs( (dY-sY)/(dX-sX) ) ) ;
this.velocity = { x : this.speed*Math.cos(this.projectionAngle + this.clickAngle) , y : -1*this.speed*Math.sin(this.projectionAngle + this.clickAngle) } ;
this.acceleration = { x : this.gravity*Math.sin(this.clickAngle) , y : this.gravity*Math.cos(this.clickAngle) } ;
} else if (dX <= sX && dY >= sY) {
// 4th quadrant
this.clickAngle = Math.atan( Math.abs( (dX-sX)/(dY-sY) ) ) ;
this.velocity = { x : -1*this.speed*Math.sin(this.projectionAngle + this.clickAngle) , y : this.speed*Math.cos(this.projectionAngle + this.clickAngle) } ;
this.acceleration = { x : this.gravity*Math.cos(this.clickAngle) , y : this.gravity*Math.sin(this.clickAngle) } ;
} else if (dX <= sX && dY <= sY) {
// 4th quadrant
this.clickAngle = Math.atan( Math.abs( (dY-sY)/(dX-sX) ) ) ;
this.velocity = { x : -1*this.speed*Math.cos(this.projectionAngle + this.clickAngle) , y : -1*this.speed*Math.sin(this.projectionAngle + this.clickAngle) } ;
this.acceleration = { x : -1*this.gravity*Math.sin(this.clickAngle) , y : this.gravity*Math.cos(this.clickAngle) } ;
}
}
this.update = function () {
this.velocity.x += this.acceleration.x ;
this.velocity.y += this.acceleration.y ;
this.animation.x += this.velocity.x ;
this.animation.y += this.velocity.y ;
}
this.getBoundary = function () {
return { "north":this.destination.y-5 , "east":this.destination.x+5 , "west":this.destination.x-5 , "south":this.destination.y+5 } ;
}
}
function Protagonist () {
this.x = 760 ;
this.y = 370 ;
this.character = "professor" ;
this.direction = "south" ;
this.navigationParameter = {"south" : {x:0,y:-1} , "north" : {x:0,y:1} ,"east" : {x:-1,y:0} ,"west" : {x:1,y:0}} ;
this.totalAnimationFrames = {"professor" : 9 , "combatant" : 8 , "escapist" : 8 , "eagle" : 4} ;
this.currentHorizontalAnimationFrameIndex = 0 ;
this.verticalAnimationFrameIndexFor = {"south" : 0 , "north" : 3 ,"east" : 2 ,"west" : 1} ;
this.height = 50;
this.width = 50 ;
this.speed = {"professor" : 2 , "combatant" : 3 , "escapist" : 6 , "eagle" : 4} ;
this.animationTimeGap = {"professor" : 100 , "combatant" : 100 , "escapist" : 80 , "eagle" : 80} ;
this.collision = {"south" : false , "north" : false ,"east" : false ,"west" : false} ;
this.exitDoorKeyCollected = false ;
this.weaponSelected = "stone" ;
this.getBoundary = function () {
return { "north":370-50/2 , "east":760+50/2 , "west":760-50/2 , "south":370+50/2 } ;
}
}
function OtherCharacter (X,Y,N,tAF,H,W,S) {
this.x = X ;
this.y =Y ;
this.name = N ;
this.direction = "north" ;
this.navigationParameter = {"south" : {x:0,y:+1} , "north" : {x:0,y:-1} ,"east" : {x:+1,y:0} ,"west" : {x:-1,y:0}} ;
this.totalAnimationFrames = tAF ;
this.currentHorizontalAnimationFrameIndex = 0 ;
this.verticalAnimationFrameIndexFor = {"south" : 0 , "north" : 3 ,"east" : 2 ,"west" : 1} ;
this.height = H ;
this.width = W ;
this.speed = S ;
this.collision = {"south" : false , "north" : false ,"east" : false ,"west" : false} ;
this.turnPositions = [] ;
this.getBoundary = function () {
return { "north":this.y-this.height/2 , "east":this.x+this.width/2 , "west":this.x-this.width/2 , "south":this.y+this.height/2 } ;
}
}
function Level () {
this.initialize = function () {
This = this ; // keyword "this" cannot be used inside window or document object's methods cuz "this" refer to the object which in those cases is window or document , so we need to store the level constructor's reference in a variable.
//---------------------------------------------------------------------------properties of objects of type Level----------------------------------------------------------------------------
this.i , this.j , this.rand ; // used in the for loops
this.cutSceneAnimationRadius = 425 , this.cutSceneAnimationThickness = 850 ; // for level intro and ending
this.oppositeDirection = {"north" : "south" , "south" : "north" , "east" : "west" , "west" : "east" } ;
this.protagonist = new Protagonist() ;
// camera is fixed to the protagonist, so his movement is made obvious by orienting the surroundings accordingly and this is done using this object.
this.overallDisplacement = { x : 0 , y : 0 } ;
// this is for returning to the professor's position when changing from eagle
this.previousOverallDisplacement = { x : 0 , y : 0 } ;
this.dungeonBoundary = { "north":320-35 , "east":3210 , "west":710 , "south":1820 } ;
this.dungeonPillars = [] , this.dungeonWalls = [] ;
this.timeIntervals = new TimeIntervals ;
this.transformationAnimation = new Animatable (undefined,undefined,284/7,50,7) ;
// refer the constructor for function signature
this.coundownAnimation = new CountdownAnimatable (3,30) ;
this.coins = [] ;
this.exitDoorKey ;
this.exitDoor ;
this.otherCharacters = [] ;
this.projectiles = [] ; // array of projectiles
this.mines =[] ; // array of placed mines
this.grenadeExplosions = [] ;
this.smokeGrenadeExplosions = [] ;
this.postExplosionSmokes = [] ;
this.timeIntervals.projectileAnimation = setInterval( function () {
for (This.i = 0 ; This.i < This.projectiles.length ; This.i++) {
if (This.projectiles[This.i].animation.currentHorizontalAnimationFrameIndex == This.projectiles[This.i].animation.totalAnimationFrames - 1) {
This.projectiles[This.i].animation.currentHorizontalAnimationFrameIndex = 0 ;
} else {
This.projectiles[This.i].animation.currentHorizontalAnimationFrameIndex ++ ;
}
}
} , 50 ) ;
this.timeIntervals.projectileTargetAnimation = setInterval( function () {
for (This.i = 0 ; This.i < This.projectiles.length ; This.i++) {
if (This.projectiles[This.i].targetAnimation.currentHorizontalAnimationFrameIndex == This.projectiles[This.i].targetAnimation.totalAnimationFrames - 1) {
This.projectiles[This.i].targetAnimation.currentHorizontalAnimationFrameIndex = 0 ;
} else {
This.projectiles[This.i].targetAnimation.currentHorizontalAnimationFrameIndex ++ ;
}
}
} , 70 ) ;
this.timeIntervals.grenadeExplosion = setInterval( function () {
for (This.i = 0 ; This.i < This.grenadeExplosions.length ; This.i++) {
if (This.grenadeExplosions[This.i].currentHorizontalAnimationFrameIndex == This.grenadeExplosions[This.i].totalAnimationFrames - 1) {
This.grenadeExplosions.splice(This.i,1) ;
This.i-- ;
} else {
This.grenadeExplosions[This.i].currentHorizontalAnimationFrameIndex ++ ;
}
}
} , 100 ) ;
this.timeIntervals.smokeGrenadeExplosion = setInterval( function () {
for (This.i = 0 ; This.i < This.smokeGrenadeExplosions.length ; This.i++) {
if (This.smokeGrenadeExplosions[This.i].currentHorizontalAnimationFrameIndex == This.smokeGrenadeExplosions[This.i].totalAnimationFrames - 1) {
This.smokeGrenadeExplosions.splice(This.i,1) ;
This.i-- ;
} else {
This.smokeGrenadeExplosions[This.i].currentHorizontalAnimationFrameIndex ++ ;
}
}
} , 80 ) ;
this.timeIntervals.postExplosionSmoke = setInterval( function () {
for (This.i = 0 ; This.i < This.postExplosionSmokes.length ; This.i++) {
if (This.postExplosionSmokes[This.i].currentHorizontalAnimationFrameIndex == This.postExplosionSmokes[This.i].totalAnimationFrames - 1) {
This.postExplosionSmokes[This.i].currentHorizontalAnimationFrameIndex = 0 ;
} else {
This.postExplosionSmokes[This.i].currentHorizontalAnimationFrameIndex ++ ;
}
}
} , 70 ) ;
//----------------------------------------------------------creating pillar objects in the basic layout and coins associated with them-------------------------------------------------------
// creating the pillars that are alread in the basic layout
for (this.i = 0; this.i < 7; this.i++) {
for (this.j = 0 , this.rand ; this.j < 12; this.j++) {
this.dungeonPillars[12*this.i+this.j] = new Obstacle(this.protagonist.x+100+this.j*200,this.protagonist.y+100+this.i*200 ) ;
// creating the burning tree, it is always present in the middle of the dungeon
if (12*this.i+this.j == 41) {
this.burningTree = new Animatable(this.dungeonPillars[12*this.i+this.j].x+100,this.dungeonPillars[12*this.i+this.j].y,100,100,6) ;
}
// each pillar contains either 1 or 2 coin(s)
// 1 coin will definitely be in 1 of the 4 directions
// 0 -> east , 1 -> south , 2 -> west , 3 -> north .
this.rand = Math.floor(100*Math.random()/25) ;
if (this.rand == 0) {
this.coins[12*this.i+this.j] = new Animatable(this.dungeonPillars[12*this.i+this.j].x,this.dungeonPillars[12*this.i+this.j].y+100,30,30,10) ;
} else if (this.rand == 1) {
this.coins[12*this.i+this.j] = new Animatable(this.dungeonPillars[12*this.i+this.j].x+100,this.dungeonPillars[12*this.i+this.j].y,30,30,10) ;
} else if (this.rand == 2) {
this.coins[12*this.i+this.j] = new Animatable(this.dungeonPillars[12*this.i+this.j].x,this.dungeonPillars[12*this.i+this.j].y-100,30,30,10) ;
} else if (this.rand == 3) {
this.coins[12*this.i+this.j] = new Animatable(this.dungeonPillars[12*this.i+this.j].x-100,this.dungeonPillars[12*this.i+this.j].y,30,30,10) ;
}
}
}
for (this.i = 0 , this.j = this.coins.length ; this.i < this.dungeonPillars.length ; this.i++ , this.j++) {
// 2nd coin of the pillar can either exist or not
// 2nd coin doesnt exist if rand=2 or if it overlaps with one of the -11th pillar's coin
// 0 -> north-east , 1 -> south-west , 2-> no coin
this.rand = Math.floor(100*Math.random()/(100/3)) ;
if (this.rand == 0) {
this.coins[this.j] = new Animatable(this.dungeonPillars[this.i].x+100,this.dungeonPillars[this.i].y-100,30,30,10) ;
} else if (this.rand == 1) {
this.coins[this.j] = new Animatable(this.dungeonPillars[this.i].x-100,this.dungeonPillars[this.i].y+100,30,30,10) ;
} else {
this.j -- ;
}
if (this.rand == 0 && this.i > 11 && this.coins[this.j].x == this.coins[this.j-11].x && this.coins[this.j].y == this.coins[this.j-11].y) {
this.coins.pop() ;
this.j -- ;
}
}
// setting an interval for coin rotation
this.timeIntervals.coinRotation = setInterval (function () {
for (This.i = 0 ; This.i < This.coins.length ; This.i ++) {
if (This.coins[This.i].currentHorizontalAnimationFrameIndex == This.coins[This.i].totalAnimationFrames - 1) {
This.coins[This.i].currentHorizontalAnimationFrameIndex = 0 ;
} else {
This.coins[This.i].currentHorizontalAnimationFrameIndex ++ ;
}
}
} , 70 ) ;
// setting burning tree animation
this.timeIntervals.burningTree = setInterval (function () {
if (This.burningTree.currentHorizontalAnimationFrameIndex == This.burningTree.totalAnimationFrames - 1) {
This.burningTree.currentHorizontalAnimationFrameIndex = 0 ;
} else {
This.burningTree.currentHorizontalAnimationFrameIndex ++ ;
}
} , 180 ) ;
//---------------------------------------------------------------------------------generating random walls----------------------------------------------------------------------------------
// creating wall for each pillar
for (this.i = 0; this.i < this.dungeonPillars.length; this.i++) {
// each pillar has a wall in 1 of the 4 directions
// 0 -> east , 1 -> south , 2 -> west , 3 -> north .
this.rand = Math.floor(100*Math.random()/25) ;
// initially i create the walls assuming there is no restriction
if (this.rand == 0) {
this.dungeonWalls[this.i] = new Obstacle(this.dungeonPillars[this.i].x+100,this.dungeonPillars[this.i].y) ;
} else if (this.rand == 1) {
this.dungeonWalls[this.i] = new Obstacle(this.dungeonPillars[this.i].x,this.dungeonPillars[this.i].y+100) ;
this.dungeonWalls[this.i].shadowed = false ;
} else if (this.rand == 2) {
this.dungeonWalls[this.i] = new Obstacle(this.dungeonPillars[this.i].x-100,this.dungeonPillars[this.i].y) ;
} else if (this.rand == 3) {
this.dungeonWalls[this.i] = new Obstacle(this.dungeonPillars[this.i].x,this.dungeonPillars[this.i].y-100) ;
this.dungeonWalls[this.i].shadowed = false ;
}
this.dungeonWalls[this.i].type = this.rand ;
// ------------------------------------------------------------------------criteria 1 : wall overlap------------------------------------------------------------------
// checking if walls overlap, this happens only if type is 2 or 3
if (this.rand == 3 && this.i>11 && this.dungeonWalls[this.i].x == this.dungeonWalls[this.i-12].x && this.dungeonWalls[this.i].y == this.dungeonWalls[this.i-12].y) {
this.i -- ;
continue ;
}
if (this.rand == 2 && this.i>0 && this.dungeonWalls[this.i].x == this.dungeonWalls[this.i-1].x && this.dungeonWalls[this.i].y == this.dungeonWalls[this.i-1].y) {
this.i -- ;
continue ;
}
// wall should not overlap with burning tree
if ((this.i == 41 && this.rand == 0) || (this.i == 42 && this.rand == 2)) {
this.i-- ;
continue ;
}
//-------------------------------------------------------------------------criteria 2 : 1x1 square boxes formation--------------------------------------------------
// now im checking for 1x1 boxes that will be formed
// anti-clockwise formation and in the else part it is clockwise
if (this.i > 12 && this.rand == 3 && this.dungeonWalls[this.i-12].type == 2 && this.dungeonWalls[this.i-12-1].type == 1 && this.dungeonWalls[this.i-1].type == 0) {
this.i -- ;
continue ;
}else if (this.i > 12 && this.rand == 2 && this.dungeonWalls[this.i-1].type == 3 && this.dungeonWalls[this.i-12-1].type == 0 && this.dungeonWalls[this.i-12].type == 1) {
this.i -- ;
continue ;
}
// only 1x1 boxes are controllable , large boxes can still be formed
//---------------------------------------------------------------creating an angel once all walls are created------------------------------------------------------
if (this.i == 83) {
this.otherCharacters[this.otherCharacters.length] = new OtherCharacter(this.dungeonPillars[this.i].x+100,this.dungeonPillars[this.i].y+100,"angel",6,50,25,1) ;
// creating turn positions for this character
this.setAndUpdateTurnPositions(this.otherCharacters.length-1) ;
// i'm doing this because the fn setAnd UpdateTurnPositions uses this.i
this.i = 83 ;
// orienting it according to wall's position
if (this.dungeonWalls[this.i].type == 0) {
this.otherCharacters[this.otherCharacters.length - 1].direction = "west" ;
}else if (this.dungeonWalls[this.i].type == 1) {
this.otherCharacters[this.otherCharacters.length - 1].direction = "north" ;
}
// setting its movement animation
this.setIntervalForOtherCharacters(this.otherCharacters.length - 1 , 150) ;
}
// im hiding the coins that overlap with dungeon wall
for (this.j = 0 ; this.j < this.coins.length ; this.j++) {
if (this.coins[this.j].x == this.dungeonWalls[this.i].x && this.coins[this.j].y == this.dungeonWalls[this.i].y) {
this.coins[this.j].hidden = true ;
}
}
// now i need to unshadow few pillars cuz all pillars by default are shadowed
if (this.dungeonWalls[this.i].type == 1) {
this.dungeonPillars[this.i].shadowed = false ;
}else if (this.i>11 && this.dungeonWalls[this.i].type == 3) {
this.dungeonPillars[this.i-12].shadowed = false ;
}
}// creating wall for pillar ends here
//---------------------------------------------------------------------------------------creating random exit door key------------------------------------------------------------------------
// key should not exist in near the 1st 4x4 pillars, i.e 0,1,2,3,12,13,14,15,24,25,26,27,36,37,38,39. cuz that would be easy
for( this.rand = 4+Math.floor(100*Math.random()/(100/80)) ; ; this.rand = 4+Math.floor(100*Math.random()/(100/80)) ) {
if ( (this.rand >=12 && this.rand <=15) || (this.rand >=24 && this.rand <=27) || (this.rand >=36 && this.rand <=39) ) {
continue ;
}else if (this.rand == 41 || this.rand == 42 || this.rand == 29 || this.rand == 30 || this.rand == 53 || this.rand == 54) {
// key should not be close to the tree too
continue ;
}
break ;
}
// a pillar is now selected around which the key will be generated
this.i = this.rand ;
// 0 -> east , 1 -> south , 2 -> west , 3 -> north .
// 4 -> north-east , 5 -> south-west .
for( this.rand = Math.floor(100*Math.random()/(100/6)) ; ; this.rand = Math.floor(100*Math.random()/(100/6)) ) {
this.exitDoorKey = new Animatable(this.dungeonPillars[this.i].x,this.dungeonPillars[this.i].y,100,100,1) ;
if (this.rand == 0) {
this.exitDoorKey.x += 100 ;
} else if (this.rand == 1) {
this.exitDoorKey.y += 100 ;
} else if (this.rand == 2) {
this.exitDoorKey.x -= 100 ;
} else if (this.rand == 3) {
this.exitDoorKey.y -= 100 ;
} else if (this.rand == 4) {
this.exitDoorKey.y -= 100 ;
this.exitDoorKey.x += 100 ;
} else {
this.exitDoorKey.y += 100 ;
this.exitDoorKey.x -= 100 ;
}
// checking if the key overlaps with any of the walls
if (this.rand != 4 && this.rand != 5) {
if ( this.i > 12 && this.exitDoorKey.x == this.dungeonWalls[this.i-12].x && this.exitDoorKey.y == this.dungeonWalls[this.i-12].y) {
// checking if it overlaps with wall of the vertically preceeding pillar
continue ;
} else if (this.exitDoorKey.x == this.dungeonWalls[this.i-1].x && this.exitDoorKey.y == this.dungeonWalls[this.i-1].y) {
// this.i cannot be 0 so this.i is not checked again whether it is > 0 or not
// checking if it overlaps with wall of horizontally preceeding pillar
continue ;
} else if (this.exitDoorKey.x == this.dungeonWalls[this.i].x && this.exitDoorKey.y == this.dungeonWalls[this.i].y) {
// checking if it overlaps with the wall of the current pillar
continue ;
} else if ( this.i != 83 && this.exitDoorKey.x == this.dungeonWalls[this.i+1].x && this.exitDoorKey.y == this.dungeonWalls[this.i+1].y) {
// checking if it overlaps with the wall of horizontally succeeding pillar
continue ;
} else if ( this.i < 72 && this.exitDoorKey.x == this.dungeonWalls[this.i+12].x && this.exitDoorKey.y == this.dungeonWalls[this.i+12].y) {
// checking if it overlaps with the wall of vertically succeeding pillar
continue ;
}
}
// i'm not checking for the walls type cuz this.i-1 can even point to the pillar which can be in the previous row
break ;
}
//--------------------------------------------------------------------------------------------creating level countdonw------------------------------------------------------------------------
if (levelTimer) {
this.timeIntervals.levelCountdown = setInterval( function () {
if (This.coundownAnimation.seconds == 0 && This.coundownAnimation.minutes != 0) {
This.coundownAnimation.minutes -- ;
This.coundownAnimation.seconds = 59 ;
} else {This.coundownAnimation.seconds -- ;}
if (This.coundownAnimation.minutes == 0 && This.coundownAnimation.seconds == 0) {
gameStatus = "game over" ;
audioFiles.gameOver.play() ;
clearInterval(This.timeIntervals.levelCountdown) ;
This.timeIntervals.levelCountdown = false ;
This.timeIntervals.levelCutScene = setInterval ( function () {
if (This.cutSceneAnimationThickness == 850) {
clearInterval(This.timeIntervals.levelCutScene) ;
This.timeIntervals.levelCutScene = false ;
stopRequestingAnimationFrame = true ;
}
This.cutSceneAnimationRadius -= 5 ;
This.cutSceneAnimationThickness += 10 ;
} , 20 ) ;
This.finish() ;
} else if ((This.coundownAnimation.seconds == 30 && This.coundownAnimation.minutes == 0) || (This.coundownAnimation.seconds == 0)){
audioFiles.minuteReminder.play() ;
} else if (This.coundownAnimation.seconds <= 15 && This.coundownAnimation.minutes == 0) {
audioFiles.lastFewSeconds.load() ;
audioFiles.lastFewSeconds.play() ;
}
}, 1000 ) ;
}
//----------------------------------------------------------------------------------level starting animation--------------------------------------------------------------------------------
// this will be the last piece of code in method initialize()
this.timeIntervals.levelCutScene = setInterval ( function () {
if (This.cutSceneAnimationThickness == 0) {
clearInterval(This.timeIntervals.levelCutScene) ;
This.timeIntervals.levelCutScene = false ;
}
This.cutSceneAnimationRadius += 5 ;
This.cutSceneAnimationThickness -= 10 ;
} , 30 ) ;
}// method initialize ends here
this.setAndUpdateTurnPositions = function (index) {
// setting the turn positions
for (this.i = 0 ; this.i < 8 ; this.i ++) {
for (this.j = 0 ; this.j < 13 ; this.j ++) {
this.otherCharacters[index].turnPositions[13*this.i+this.j] = new TurnPosition(760+this.j*200,370+this.i*200) ;
// the turn positions present near the dungeon boundary should have the respective direction(s) removed from the availableTurnDirections array
if (this.j == 0) {
// remove west from the array
this.otherCharacters[index].turnPositions[13*this.i+this.j].availableTurnDirections.splice(3,1) ;
} else if (this.j == 12) {
// remove east from the array
this.otherCharacters[index].turnPositions[13*this.i+this.j].availableTurnDirections.splice(2,1) ;
}
if (this.i == 0) {
// remove north from the array
this.otherCharacters[index].turnPositions[13*this.i+this.j].availableTurnDirections.splice(0,1) ;
} else if (this.i == 7) {
// remove south from the array
this.otherCharacters[index].turnPositions[13*this.i+this.j].availableTurnDirections.splice(1,1) ;
}
}
}
// updating the turn positions
for (this.i = 0 ; this.i < this.dungeonWalls.length ; this.i++) {
// refer what wall type means
if (this.dungeonWalls[this.i].type == 0 || this.dungeonWalls[this.i].type == 2) {
// i need to change the turn positions on top and bottom of the wall
for (this.j = 0 ; this.j < this.otherCharacters[index].turnPositions.length ; this.j++) {
// turn position to the top of the wall will have south removed and the one to the bottom will have north removed from it's availableTurnDirections array and unexploredDirections array
if (this.dungeonWalls[this.i].x == this.otherCharacters[index].turnPositions[this.j].x &&
this.dungeonWalls[this.i].y-100 == this.otherCharacters[index].turnPositions[this.j].y) {
for (this.rand = 0 ; this.rand < this.otherCharacters[index].turnPositions[this.j].availableTurnDirections.length ; this.rand ++) {
if (this.otherCharacters[index].turnPositions[this.j].availableTurnDirections[this.rand] == "south") {
this.otherCharacters[index].turnPositions[this.j].availableTurnDirections.splice(this.rand,1) ;
this.rand -- ;
}
}
}
else if (this.dungeonWalls[this.i].x == this.otherCharacters[index].turnPositions[this.j].x &&
this.dungeonWalls[this.i].y+100 == this.otherCharacters[index].turnPositions[this.j].y) {
for (this.rand = 0 ; this.rand < this.otherCharacters[index].turnPositions[this.j].availableTurnDirections.length ; this.rand ++) {
if (this.otherCharacters[index].turnPositions[this.j].availableTurnDirections[this.rand] == "north") {
this.otherCharacters[index].turnPositions[this.j].availableTurnDirections.splice(this.rand,1) ;
this.rand -- ;
}
}
}
}
} else if (this.dungeonWalls[this.i].type == 1 || this.dungeonWalls[this.i].type == 3) {
// i need to change the turn positions on top and bottom of the wall
for (this.j = 0 ; this.j < this.otherCharacters[index].turnPositions.length ; this.j++) {
// turn position to the left of the wall will have east removed and the one to the right will have west removed from it's availableTurnDirections array
if (this.dungeonWalls[this.i].x-100 == this.otherCharacters[index].turnPositions[this.j].x &&
this.dungeonWalls[this.i].y == this.otherCharacters[index].turnPositions[this.j].y) {
for (this.rand = 0 ; this.rand < this.otherCharacters[index].turnPositions[this.j].availableTurnDirections.length ; this.rand ++) {
if (this.otherCharacters[index].turnPositions[this.j].availableTurnDirections[this.rand] == "east") {
this.otherCharacters[index].turnPositions[this.j].availableTurnDirections.splice(this.rand,1) ;
this.rand -- ;
}
}
}
else if (this.dungeonWalls[this.i].x+100 == this.otherCharacters[index].turnPositions[this.j].x &&
this.dungeonWalls[this.i].y == this.otherCharacters[index].turnPositions[this.j].y) {
for (this.rand = 0 ; this.rand < this.otherCharacters[index].turnPositions[this.j].availableTurnDirections.length ; this.rand ++) {
if (this.otherCharacters[index].turnPositions[this.j].availableTurnDirections[this.rand] == "west") {
this.otherCharacters[index].turnPositions[this.j].availableTurnDirections.splice(this.rand,1) ;
this.rand -- ;
}
}
}
}
}
}
}
this.setIntervalForOtherCharacters = function (index,aTG) {
this.timeIntervals[this.otherCharacters[index].name] = setInterval (function () {
if (This.otherCharacters[index].currentHorizontalAnimationFrameIndex == This.otherCharacters[index].totalAnimationFrames - 1) {
This.otherCharacters[index].currentHorizontalAnimationFrameIndex = 0 ;
} else {
This.otherCharacters[index].currentHorizontalAnimationFrameIndex ++ ;
}
} , aTG ) ;
}
// n=1,0 imply object whose position is influenced and not influenced by overallDisplacement, eg.n=0 for protaagonist and projectiles, rest n=1
// m=1,0 imply obstacle whose position is influenced and not influenced by overallDisplacement eg.m=0 for projectle destination collision box and 1 for others
// objB is object boundary and obsB is obstacle boundary
// objC is object center
// direction holds the value of direction in which the object is moving
this.checkCollision = function (direction,objC,objB,obsB,n,m) {
if ( ( ((objB.north+n*this.overallDisplacement.y>obsB.north+m*this.overallDisplacement.y)&&(objB.north+n*this.overallDisplacement.y<obsB.south+m*this.overallDisplacement.y)) ||
((objB.south+n*this.overallDisplacement.y>obsB.north+m*this.overallDisplacement.y)&&(objB.south+n*this.overallDisplacement.y<obsB.south+m*this.overallDisplacement.y)) ||
((objC.y+n*this.overallDisplacement.y>obsB.north+m*this.overallDisplacement.y)&&(objC.y+n*this.overallDisplacement.y<obsB.south+this.overallDisplacement.y)) )
&&
( ((objB.east+n*this.overallDisplacement.x>obsB.west+m*this.overallDisplacement.x)&&(objB.east+n*this.overallDisplacement.x<obsB.east+m*this.overallDisplacement.x)) ||
((objB.west+n*this.overallDisplacement.x>obsB.west+m*this.overallDisplacement.x)&&(objB.west+n*this.overallDisplacement.x<obsB.east+m*this.overallDisplacement.x)) ||
((objC.x+n*this.overallDisplacement.x>obsB.west+m*this.overallDisplacement.x)&&(objC.x+n*this.overallDisplacement.x<obsB.east+m*this.overallDisplacement.x)) ) ) {
if (direction == "north" || direction == "south") {
return Math.abs(obsB[this.oppositeDirection[direction]]+m*this.overallDisplacement.y - (objB[direction]+n*this.overallDisplacement.y) ) ;
} else if (direction == "east" || direction == "west") {
return Math.abs(obsB[this.oppositeDirection[direction]]+m*this.overallDisplacement.x - (objB[direction]+n*this.overallDisplacement.x) ) ;
} else {
return true ;
}