-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamemech.js
2363 lines (2294 loc) · 83.5 KB
/
gamemech.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
//
// GAME STARTUP. LET'S DO THIS!
//
// Create the canvas
var canvas = document.createElement('canvas');
canvas.id = 'playground';
var ctx = canvas.getContext('2d');
canvas.width = 1024;
canvas.height = 768;
//canvas.width = 800;
//canvas.height = 600;
document.getElementById('gameContainer').appendChild(canvas);
var TO_RADIANS = Math.PI / 180;
const audio = {
backgroundMusic: new Audio('./sounds/hitman.mp3'),
macheteSound: new Audio('./sounds/sword.mp3'),
pistolSound: new Audio('./sounds/pistol.mp3'),
shotgunSound: new Audio('./sounds/shotgun.mp3'),
flamethrowerSound: new Audio('./sounds/flamethrower.mp3'),
granadeSound: new Audio('./sounds/granade.mp3'),
fireworksSound: new Audio('./sounds/fireworks.mp3'),
emptySound: new Audio('./sounds/empty.mp3'),
monsterinitSound: new Audio('./sounds/monsterGrunt.mp3'),
avatarHitSound: new Audio('./sounds/avatarHit.mp3'),
laserSound: new Audio('./sounds/laser.mp3'),
missionSound: new Audio('./sounds/mission.mp3'),
monsterDeath: new Audio('./sounds/zombie.mp3'),
};
audio.backgroundMusic.volume = 0.035;
audio.fireworksSound.volume = 0.1;
audio.emptySound.volume = 0.2;
audio.backgroundMusic.loop = true;
function cloneAndPlay(audioNode, start, vol) {
const clone = audioNode.cloneNode(true);
clone.volume = vol ? vol : 0.1;
clone.currentTime = start ? start : 0;
clone.play();
clone.onended = () => clone.remove();
}
function playgame() {
//set interface buttons
document.getElementById('restartGameFromStats').onclick = function () {
reset(
drops,
gameVariables,
gameArrays,
inventory,
hero,
keyPressed,
backgroundImage,
gameDisplay,
tileDisplay,
keysDown,
tileArray,
schematics,
missionArray,
environmentalPoints,
survivorImage,
elderweedImage,
zombieExcrementImage,
butterflyEggsImage,
environmentImagesLoaded,
gameArrays.treeAndHouseArray,
treeImagesLoaded
);
};
document.getElementById('weaponMachete').onclick = function () {
selectWeapon('machete', hero);
};
document.getElementById('weaponPistol').onclick = function () {
selectWeapon('pistol', hero);
};
document.getElementById('weaponShotgun').onclick = function () {
selectWeapon('shotgun', hero);
};
document.getElementById('weaponMachinegun').onclick = function () {
selectWeapon('machinegun', hero);
};
document.getElementById('weaponFlamethrower').onclick = function () {
selectWeapon('flamethrower', hero);
};
//document.getElementById('utilitiesGranade').onclick=function(){throwingGranade(gameArrays);};
document.getElementById('utilitiesAntidote').onclick = function () {
useAntidote(hero);
};
document.getElementById('utilitiesMedkit').onclick = function () {
useMedkit(hero);
};
document.getElementById('gameInventory').onclick = function (e) {
showInventory('Inventory', inventory, gameVariables, this.id, schematics, hero);
};
document.getElementById('gameSchematics').onclick = function (e) {
showInventory('Schematics', inventory, gameVariables, this.id, schematics, hero);
};
document.getElementById('missionInteractionContainerExit').onclick = function () {
closeInteractionContainer(hero);
};
//document.getElementById('testbutton').onclick=function(){changeStatusOfMissionProgress(missionArray,hero,gameVariables.timeControler)};
//document.getElementById('testbutton').onclick=function(){bossThrowGranade(gameArrays.thrownGranadeArray,gameVariables.timeControler);};
//document.getElementById('testbutton').onclick=function(){spawnMonster(800,600,20,300,1000,1000,4,gameArrays.monsterArray,"boss");console.log(gameArrays.monsterArray);};
document.getElementById('testbutton').onclick = function () {
launchRandomRocket(gameArrays.rocketArray, gameVariables.timeControler);
};
//set specialAbilityButtons
document.getElementById('gameAbilityOne').onclick = function () {
GuidePlayerToObjective(missionArray, hero, arrowImage, gameVariables);
};
document.getElementById('gameAbilityTwo').onclick = function () {
activateHeatGoggles(hero);
};
document.getElementById('gameAbilityThree').onclick = function () {
activateLazerScope(hero);
};
document.getElementById('gameAbilityFour').onclick = function () {
activateScavanger(hero);
};
document.getElementById('gameAbilityFive').onclick = function () {
activateRocketBoots(hero);
};
document.getElementById('gameAbilitySix').onclick = function () {
firePulseTransmitter(hero, gameVariables.timeControler);
};
document.getElementById('gameAbilitySeven').onclick = function () {
activateFlashlight(hero, keysDown, gameVariables);
};
window.addEventListener('focus', function () {
audio.backgroundMusic.paused ? audio.backgroundMusic.play() : null;
});
window.addEventListener('blur', function () {
audio.backgroundMusic.pause();
});
// Arrays and variables.
var gameArrays = {
backgroundArray: [],
backgroundObjectArray: [],
numberOfLampsOnScreen: [],
environmentArray: [],
monsterArray: [],
bulletArray: [],
granadeArray: [],
thrownGranadeArray: [],
archivedObjectArray: [],
archivedBulletArray: [],
archivedMonsterArray: [],
archivedGranadeArray: [],
objectArray: [],
rocketArray: [],
treeAndHouseArray: [],
};
var drops = [
{ name: 'Handgun rounds', imgName: 'handgunRounds', amount: '7', offset: '12', itemType: 'ammo' },
{ name: 'Shotgun shells', imgName: 'shotgunShells', amount: '8', offset: '13', itemType: 'ammo' },
{ name: 'Machinegun magazine', imgName: 'machinegunMagazine', amount: '30', offset: '22', itemType: 'ammo' },
{ name: 'Flamethrower shells', imgName: 'flamethrowerShells', amount: '50', offset: '28', itemType: 'ammo' },
{
name: 'Schematic: Rocketbooster boots',
imgName: 'schematicBoots',
amount: '1',
offset: '34',
itemType: 'schematic',
description: 'A set of rocket boots that will increase your running speed.',
materials: [
{ name: 'Rocket fuel', constructor: 'rocketFuel', amount: 5 },
{ name: 'Leather straps', constructor: 'leatherStraps', amount: 8 },
{ name: 'Metal scrap', constructor: 'metalScrap', amount: 9 },
{ name: 'Electronic components', constructor: 'electronicComponents', amount: 6 },
{ name: 'Wires', constructor: 'wires', amount: 4 },
],
},
{
name: 'Schematic: Lazerscope',
imgName: 'schematicScope',
amount: '1',
offset: '30',
itemType: 'schematic',
description: 'A laser scope on your weapons which will make aiming easier.',
materials: [
{ name: 'Lenses', constructor: 'lenses', amount: 4 },
{ name: 'Broken scope', constructor: 'brokenScope', amount: 1 },
{ name: 'Screws', constructor: 'screws', amount: 10 },
{ name: 'Steel tube', constructor: 'steelTube', amount: 1 },
{ name: 'Glass shards', constructor: 'glassShard', amount: 4 },
{ name: 'Gaffe tape', constructor: 'gaffaTape', amount: 1 },
],
},
//{name:"Schematic: Radio",imgName:"schematicRadio",amount:"1",offset:"15",itemType:"schematic",description:"A small radio which will let you talk to the base without having to run back.",materials:[{name:"Screws",constructor:"screws",amount:10},{name:"Broken antenna",constructor:"brokenAntenna",amount:1},{name:"Speaker unit",constructor:"speakerUnit",amount:1},{name:"Battery",constructor:"battery",amount:1},{name:"Steel case",constructor:"steelCase",amount:1},{name:"Wires",constructor:"wires",amount:10},{name:"Handful of transistors",constructor:"transistors",amount:10}]},
{
name: 'Schematic: Thermo-goggles',
imgName: 'schematicGoogles',
amount: '1',
offset: '28',
itemType: 'schematic',
description: 'A pair of glasses which will let you see monster more easily.',
materials: [
{ name: 'Lenses', constructor: 'lenses', amount: 2 },
{ name: 'Screws', constructor: 'screws', amount: 10 },
{ name: 'Metal scrap', constructor: 'metalScrap', amount: 12 },
{ name: 'Electronic components', constructor: 'electronicComponents', amount: 6 },
{ name: 'Wires', constructor: 'wires', amount: 12 },
{ name: 'Battery', constructor: 'battery', amount: 2 },
],
},
{
name: 'Schematic: Pulse-Emitter',
imgName: 'schematicPulse',
amount: '1',
offset: '27',
itemType: 'schematic',
description: 'A device setting off a pulse, damaging all monsters in range.',
materials: [
{ name: 'Broken antenna', constructor: 'brokenAntenna', amount: 1 },
{ name: 'Small electronic screen', constructor: 'smallElectronicScreen', amount: 1 },
{ name: 'Wires', constructor: 'wires', amount: 8 },
{ name: 'Metal scrap', constructor: 'metalScrap', amount: 6 },
{ name: 'Electronic components', constructor: 'electronicComponents', amount: 6 },
{ name: 'Gaffa tape', constructor: 'gaffaTape', amount: 3 },
{ name: 'Steel case', constructor: 'steelCase', amount: 1 },
{ name: 'Battery', constructor: 'battery', amount: 1 },
{ name: 'Screws', constructor: 'screws', amount: 5 },
],
},
{
name: 'Schematic: Scavanger 101',
imgName: 'schematicTrash',
amount: '1',
offset: '27',
itemType: 'schematic',
description: 'A device that lets you identify monsters which will drop loot.',
materials: [
{ name: 'Handful of transistors', constructor: 'transistors', amount: 5 },
{ name: 'Broken antenna', constructor: 'brokenAntenna', amount: 1 },
{ name: 'Battery', constructor: 'battery', amount: 2 },
{ name: 'Small electronic screen', constructor: 'smallElectronicScreen', amount: 1 },
{ name: 'Wires', constructor: 'wires', amount: 5 },
{ name: 'Steel case', constructor: 'steelCase', amount: 1 },
],
},
{ name: 'Desert Eagle', imgName: 'pistol', amount: '1', offset: '8', itemType: 'gun' },
{ name: 'MAC-7', imgName: 'shotgun', amount: '1', offset: '1', itemType: 'gun' },
{ name: 'AK-47', imgName: 'machinegun', amount: '1', offset: '1', itemType: 'gun' },
{ name: 'M1A1 Flamethrower', imgName: 'flamethrower', amount: '1', offset: '14', itemType: 'gun' },
{ name: 'Medkit', imgName: 'medkit', amount: '1', offset: '2', itemType: 'utility' },
{ name: 'Antidote', imgName: 'antidote', amount: '1', offset: '5', itemType: 'utility' },
{ name: 'Granade', imgName: 'granade', amount: '1', offset: '4', itemType: 'utility' },
{ name: 'Broken scope', imgName: 'brokenScope', amount: '1', offset: '8', itemType: 'mat' },
{ name: 'Lenses', imgName: 'lenses', amount: '2', offset: '2', itemType: 'mat' },
{ name: 'Screws', imgName: 'screws', amount: '5', offset: '5', itemType: 'mat' },
{ name: 'Metal scrap', imgName: 'metalScrap', amount: '2', offset: '15', itemType: 'mat' },
{ name: 'Battery', imgName: 'battery', amount: '1', offset: '7', itemType: 'mat' },
{ name: 'Electronic components', imgName: 'electronicComponents', amount: '3', offset: '26', itemType: 'mat' },
{ name: 'Wires', imgName: 'wires', amount: '4', offset: '3', itemType: 'mat' },
{ name: 'Steel case', imgName: 'steelCase', amount: '1', offset: '9', itemType: 'mat' },
{ name: 'Small electronic screen', imgName: 'smallElectronicScreen', amount: '1', offset: '27', itemType: 'mat' },
{ name: 'Broken antenna', imgName: 'brokenAntenna', amount: '1', offset: '15', itemType: 'mat' },
{ name: 'Steel tube', imgName: 'steelTube', amount: '1', offset: '7', itemType: 'mat' },
{ name: 'Glass shards', imgName: 'glassShard', amount: '2', offset: '8', itemType: 'mat' },
{ name: 'Rocket fuel', imgName: 'rocketFuel', amount: '1', offset: '6', itemType: 'mat' },
//{name:"Speaker unit",imgName:"speakerUnit",amount:"1",offset:"8",itemType:"mat"},
{ name: 'Leather straps', imgName: 'leatherStraps', amount: '2', offset: '15', itemType: 'mat' },
{ name: 'Gaffa tape', imgName: 'gaffaTape', amount: '1', offset: '7', itemType: 'mat' },
{ name: 'Handful of transistors', imgName: 'transistors', amount: '10', offset: '28', itemType: 'mat' },
//{name:"Zombie specimen",imgName:"zombieSpecimen",amount:"1",offset:"15",itemType:"questDrop"}
];
var hero = {
death: 0,
health: 100,
calcSpeed: 3,
initialSpeed: 3, // movement in pixels per second
speed: 3, // current in pixels per second
rocketSpeed: 5, // speed of rocketboots in pixels per second
angle: 0,
mouseFire: false,
walking: 0,
machete: 1,
lastFire: 0,
macheteDamage: 13,
pistol: 1,
pistolDamage: 35,
machinegun: 0,
machinegunDamage: 20,
shotgun: 0,
shotgunDamage: 20,
flamethrower: 0,
flamethrowerDamage: 10,
gun: 'machete',
gunshots: 40,
machinegunshots: 0,
shotgunshots: 0,
flameshells: 0,
clip: 7,
machinegunclip: 30,
shotgunclip: 8,
medkit: 0,
isPoisoned: 0,
antidote: 0,
flashlight: 'on',
armor: 0,
radioObtained: 0, // 1
radioOn: 0,
heatGogglesObtained: 0, // 2
heatGogglesOn: 0,
scopeObtained: 0, // 3
scopeOn: 0,
scavangerObtained: 0, // 4
scavangerOn: 0,
trackerActivated: 0,
trackerActivatedTime: 0,
trackerCountdown: 0,
trackerFadeInit: 0.2,
trackerMaxFadeReached: 0,
rocketBootsObtained: 0, // 5
rocketBootsOn: 0,
pulseTransmitterObtained: 0, //6
pulseTransmitterFired: 0,
pulseTransmitterFiredTime: 0,
pulseTransmitterCountdown: 0,
pulseTransmitterCounter: 4,
reloadDelay: 0,
missionProgress: 13,
currentMission: 13,
missionPresented: 0,
missionShown: 0,
missionShownTimer: 0,
hitByPoison: 0,
poisonPeaked: 0,
poisonOpacity: 0,
};
var missionArray = [
//0: Get to basecamp.
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'find',
name: 'Basecamp',
indexX: 0,
indexY: 0,
x: 0,
y: 0,
completed: 'no',
statement: 'Find the basecamp.',
message:
"Listen up soldier! You've been deployed to check out this zombie threat - Go find the basecamp and get your orders!",
completion: 'Welcome, soldier!',
}),
]),
//1: Get Radio schematic & find the city.
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'find',
name: 'Tiny farm',
indexX: 0,
indexY: 0,
x: 0,
y: 0,
completed: 'no',
statement: 'Find the farm.',
message:
'Your first objective is to get to farm not far from here, and see if you can find any survivors who can tell us what the hell happened!',
completion: 'So, you found the city, soldier!',
}),
//objective = {completionTime:0,func:"secondary",type:"get",item:"Schematic: Radio",amount:1,gathered:0,completed:"no",statement:"Build a radio.",message:"Our engineers fixed together a schematic for a low-end radio - See if you can find the materials required, so you can communicate with the base on radio - otherwise you have to run back here to report back!",completion:"*Rrrrrrr* Come in, soldier. Well done, now we can communicate over radio. Now get back to work on your primary objectives. Over."}
]),
//2: Kill 25 zombies & find survivor.
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'interact',
interacted: 0,
name: 'Survivor',
indexX: 0,
indexY: 0,
x: 0,
y: 0,
completed: 'no',
statement: 'Find and talk to the survivor.',
message: 'Now clear out the surrounding area, and for any survivors who might know what the hell happend here!',
completion: 'Excellent job with the killing and finding the survivor!',
}),
(objective = {
completionTime: 0,
func: 'primary',
type: 'kill',
name: 'Zombie',
amount: 10,
gathered: 0,
completed: 'no',
statement: 'Kill 25 zombies.',
message: '',
completion: '',
}),
]),
//3: Back go base to tell story.
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'find',
name: 'Basecamp',
indexX: 0,
indexY: 0,
x: 0,
y: 0,
completed: 'no',
statement: 'Find the basecamp.',
message: 'You must go back to tell your commander what happened!',
completion: 'Good to see you back, soldier!',
}),
]),
//4: Collect 10 specimens from monsters.
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'get',
name: 'Specimens',
amount: 3,
gathered: 0,
completed: 'no',
statement: 'Get 3 brains from zombies.',
message:
"This doesn't look good, soldier. We need to find out what caused this - by getting some examples. Gather 3 non-smashed brains from the zombies, and bring them back to our researchers for testing.",
completion: 'Good job, soldier! Hopefully our scientists will be able to find out what the hell is going on!',
}),
]),
//5: Find ground zero.
//IMPORTANT! Given a radio if they don't have one!
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'find',
name: 'Ground zero',
indexX: 0,
indexY: 0,
x: 0,
y: 0,
completed: 'no',
statement: 'Locate ground zero.',
message:
"In the meantime, i got a new job for you! We located ground zero of the disaster, and we need someone to go check it out! That's right - you, soldier! Get moving!",
completion:
"So, you found it. Any clues about what caused this? What's that sound in the back? Are you being attacked? Soldier? SOLDIER, REPORT ABACK!",
}),
]),
//6: Ambushed - kill the attackers.
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'kill',
name: 'Zombie',
amount: 15,
gathered: 0,
completed: 'no',
wave: 1,
statement: 'Kill 15 zombies',
message: 'Survive the attacks!',
completion: 'Well done!',
}),
(objective = {
completionTime: 0,
func: 'primary',
type: 'kill',
name: 'Super zombie',
amount: 3,
gathered: 0,
completed: 'no',
wave: 1,
statement: 'Kill 3 super zombies',
message: '',
completion: '',
}),
(objective = {
completionTime: 0,
func: 'primary',
type: 'kill',
name: 'Master zombie',
amount: 2,
gathered: 0,
completed: 'no',
wave: 1,
statement: 'Kill 2 master zombies',
message: '',
completion: '',
}),
]),
//7: Back to base, its under attack.
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'find',
name: 'Basecamp',
indexX: 0,
indexY: 0,
x: 0,
y: 0,
completed: 'no',
statement: 'Get back to the basecamp.',
message: "Soldier! Get back to the base immedieately - we're under attack!",
completion: "They're coming soon, help us defend the basecamp!",
}),
]),
//8: Repel attack
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'kill',
amount: 15,
gathered: 0,
completed: 'no',
wave: 0,
message: 'Kill the intruders!',
statement: 'Repel the attack.',
completion: 'Good work soldier - they appeared shortly after you left!',
}),
]),
//9: Antidote probably fixed - need stuff to test.
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'find',
name: 'Forest',
indexX: 0,
indexY: 0,
x: 0,
y: 0,
completed: 'no',
statement: 'Find the forest.',
message:
"Our scientists believe they've worked out a cure - they need you to go to the forest and get the following items: Some elderweed, some zombie excrements... and some butterfly eggs!",
completion: 'Good work, soldier.',
}),
(objective = {
completionTime: 0,
func: 'primary',
type: 'get',
item: 'Elderweed',
amount: 2,
gathered: 0,
completed: 'no',
statement: 'Gather 2 Elderweed.',
message: 'Find some elderweed, ',
completion: '',
}),
(objective = {
completionTime: 0,
func: 'primary',
type: 'get',
item: 'Zombie excrement',
amount: 3,
gathered: 0,
completed: 'no',
statement: 'Gather 3 zombie excrement',
message: '',
completion: '',
}),
(objective = {
completionTime: 0,
func: 'primary',
type: 'get',
item: 'Butterfly eggs',
amount: 2,
gathered: 0,
completed: 'no',
statement: 'Gather 2 butterfly eggs',
message: '',
completion: '',
}),
]),
//10: deliver to base.
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'find',
name: 'Basecamp',
indexX: 0,
indexY: 0,
x: 0,
y: 0,
completed: 'no',
statement: 'Get back to the basecamp with the stuff.',
message: "Now bring it back to the base asap. That's an order!",
completion: 'That took you long enough - hand it over! We should be able to cure the zombies now.',
}),
]),
//11: Base discovered master moster hide out. Get there!
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'find',
name: 'Zombie playground',
indexX: 0,
indexY: 0,
x: 0,
y: 0,
completed: 'no',
statement: 'Find the zombie playground.',
message:
'While you worked out the cure, we discovered the zombie base. Get there and end the threat once and for all, so no other people can be infected!',
completion: "*Rrrrrr* You've found it, good job!",
}),
]),
//12: Kill master monster!
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'kill',
name: 'Zombie boss',
amount: 1,
gathered: 0,
completed: 'no',
wave: 0,
bossSpawned: 0,
granadeState: 0,
shotState: 0,
shotTimer: 0,
shotWave: 0,
fleeState: 0,
fleeTime: 0,
actionCounter: 0,
statement: 'Kill the zombie boss.',
message: 'Kill their leader, fast! Before too many of his zombie-servants get to you!',
completion: 'You did it! You bloody did it! Excellent job, soldier!',
}),
]),
//13: Yay, you saved the world! Party the night away!
(mission = [
(objective = {
completionTime: 0,
func: 'primary',
type: 'win',
name: 'Win',
completed: 'no',
rocketLaunch: 0,
rocketFired: 0,
statement: 'Party your socks off!',
message: 'You really did it! You saved the world! Well done, soldier!',
completion: 'Game completed',
}),
]),
];
//console.log(missionArray);
var environmentalPoints = {
basecampPosition: { indexX: 0, indexY: 0, x: 0, y: 0, name: 'Basecamp' },
cityPosition: { indexX: 0, indexY: 0, x: 0, y: 0, name: 'Lonely farm' },
survivorPosition: { indexX: 0, indexY: 0, x: 0, y: 0, name: 'Lone survivor' },
forestPosition: { indexX: 0, indexY: 0, x: 0, y: 0, name: 'Forest' },
groundZeroPosition: { indexX: 0, indexY: 0, x: 0, y: 0, name: 'Ground zero' },
zombiePlayground: { indexX: 0, indexY: 0, x: 0, y: 0, name: 'Zombie playground' },
};
var gameDisplay = { x: canvas.width / 2, y: canvas.height / 2, indexX: 0, indexY: 0 };
var tileDisplay = { x: canvas.width / 2, y: canvas.height / 2 };
var inventory = {};
var schematics = [];
var background = {};
var tileArray = {};
var keysDown = {};
var keyPressed = {};
var gameVariables = {
pickUp: 0,
pickUpSchematics: 0,
gameStopped: 0,
paused: false,
missionType: 'Flashlight',
numberOfDrops: 0,
bulletCounter: 0,
newPick: 'no',
hasFired: 0,
isPressed: 0,
timeStamp: new Date(),
timeStart: new Date(),
timeEnd: '',
rocketInterval: 0,
missionHighlight: 0,
highlightSet: 0,
timeControler: new Date(),
setTimeState: 0,
heroImageUsed: 'graphics/hero-new/hero-standing-sword.png',
};
gameVariables.setTimeState = gameVariables.timeControler.getSeconds() + 3;
// Cross-browser support for requestAnimationFrame
var w = window;
requestAnimationFrame =
w.requestAnimationFrame || w.webkitRequestAnimationFrame || w.msRequestAnimationFrame || w.mozRequestAnimationFrame;
//
//Images
//
//Flash image
var flashReady = false;
var flashImage = new Image();
flashImage.onload = function () {
flashReady = true;
};
flashImage.src = 'graphics/flashlight80-edit2.png';
//Background image
var backgroundImage = 'graphics/grasstry2.png';
backgroundImage.height = 768;
backgroundImage.width = 1024;
//var backgroundImage = "graphics/environment/measurement.png";
bgReady = true;
var monsterHitImage = new Image();
monsterHitImage.src = 'graphics/monsterhit.png';
var poisonImage = new Image();
poisonImage.src = 'graphics/poisonhit.png';
//Lamp image
var lampReady = false;
var lampImage = new Image();
lampImage.onload = function () {
lampReady = true;
};
lampImage.src = 'graphics/shadowness80.png';
//Explosion image
var explosionReady = false;
var explosionImage = new Image();
explosionImage.onload = function () {
explosionReady = true;
};
explosionImage.src = 'graphics/explosion3.png';
//bloodpool image
var bloodpoolReady = false;
var bloodpoolImage = new Image();
bloodpoolImage.onload = function () {
bloodpoolReady = true;
};
bloodpoolImage.src = 'graphics/bloodpool.png';
//arrow image
var arrowImageReady = false;
var arrowImage = new Image();
arrowImage.onload = function () {
arrowImageReady = true;
};
arrowImage.src = 'graphics/missionArrow.png';
//Hero images
var heroArray = [
'graphics/hero-new/hero-standing-machete.png',
'graphics/hero-new/hero-standing-pistol.png',
'graphics/hero-new/hero-standing-shotgun.png',
'graphics/hero-new/hero-standing-machinegun.png',
'graphics/hero-new/hero-standing-flamethrower.png',
];
for (y = 0; y < heroArray.length; y++) {
var heroReady = false;
var heroImage = new Image();
heroImage.onload = function () {
heroReady = true;
};
heroImage.src = heroArray[y];
}
//survivorImage
var survivorReady = false;
var survivorImage = new Image();
survivorImage.onload = function () {
survivorReady = true;
};
survivorImage.src = 'graphics/hero-new/hero-standing-machete.png';
//crateImage
var materialReady = false;
var materialImage = new Image();
materialImage.onload = function () {
materialReady = true;
};
materialImage.src = 'graphics/environment/cratedone.png';
//questDrop Elderweed
var elderweedReady = false;
var elderweedImage = new Image();
elderweedImage.onload = function () {
elderweedReady = true;
};
elderweedImage.src = 'graphics/environment/flower.png';
//questDrop ZombieExcrement
var zombieExcrementReady = false;
var zombieExcrementImage = new Image();
zombieExcrementImage.onload = function () {
zombieExcrementReady = true;
};
zombieExcrementImage.src = 'graphics/environment/poo.png';
//questDrop ButterflyEggs
var butterflyEggsReady = false;
var butterflyEggsImage = new Image();
butterflyEggsImage.onload = function () {
butterflyEggsReady = true;
};
butterflyEggsImage.src = 'graphics/environment/eggs.png';
//drop images
var objectImageArray = [];
for (h = 0; h < drops.length; h++) {
objectImageArray[h] = new Image();
objectImageArray[h].src = 'graphics/environment/' + 'cratedone.png'; //drops[h].imgName + ".png";
}
questItemImage = new Image();
questItemImage.src = 'graphics/environment/' + 'brain.png'; //questItem picture
//Monster images
var monster1Ready = false;
var monsterImage1 = new Image();
var monster2Ready = false;
var monsterImage2 = new Image();
var monster3Ready = false;
var monsterImage3 = new Image();
var monster1IdleReady = false;
var monsterImageIdle1 = new Image();
var monster2IdleReady = false;
var monsterImageIdle2 = new Image();
var monster3IdleReady = false;
var monsterImageIdle3 = new Image();
var monster1HeatIdle = new Image();
monster1HeatIdle.src = 'graphics/monster1-temp-idle.png';
var monster2HeatIdle = new Image();
monster2HeatIdle.src = 'graphics/monster2-temp-idle.png';
var monster3HeatIdle = new Image();
monster3HeatIdle.src = 'graphics/monster3-temp-idle.png';
var monster1HeatAttack = new Image();
monster1HeatAttack.src = 'graphics/monster1-temp.png';
var monster2HeatAttack = new Image();
monster2HeatAttack.src = 'graphics/monster2-temp.png';
var monster3HeatAttack = new Image();
monster3HeatAttack.src = 'graphics/monster3-temp.png';
var basecampImages = ['basecampDone'];
var basecampImagesLoaded = [];
for (y = 0; y < basecampImages.length; y++) {
var objectImage = new Image();
objectImage.src = 'graphics/environment/' + basecampImages[y] + '.png';
basecampImagesLoaded.push(objectImage);
}
var treeImages = ['tree1'];
var treeImagesLoaded = [];
for (y = 0; y < treeImages.length; y++) {
var objectImage = new Image();
objectImage.src = 'graphics/environment/' + treeImages[y] + '.png';
treeImagesLoaded.push(objectImage);
}
var pgImages = ['zombiePlaygroundDone1'];
var pgImagesLoaded = [];
for (y = 0; y < pgImages.length; y++) {
var objectImage = new Image();
objectImage.src = 'graphics/environment/' + pgImages[y] + '.png';
pgImagesLoaded.push(objectImage);
}
var gzImages = ['groundZeroDone'];
var gzImagesLoaded = [];
for (y = 0; y < gzImages.length; y++) {
var objectImage = new Image();
objectImage.src = 'graphics/environment/' + gzImages[y] + '.png';
gzImagesLoaded.push(objectImage);
}
var farmImages = ['farm1', 'farm2', 'cornfield'];
var farmImagesLoaded = [];
for (y = 0; y < farmImages.length; y++) {
var objectImage = new Image();
objectImage.src = 'graphics/environment/' + farmImages[y] + '.png';
farmImagesLoaded.push(objectImage);
}
var environmentImages = ['randomTile1', 'randomTile2', 'randomTile3', 'randomTile4'];
var environmentImagesLoaded = [];
for (y = 0; y < environmentImages.length; y++) {
var objectImage = new Image();
objectImage.src = 'graphics/environment/' + environmentImages[y] + '.png';
environmentImagesLoaded.push(objectImage);
}
//console.log(environmentImagesLoaded);
monsterImage1.onload = function () {
monster1Ready = true;
};
monsterImage2.onload = function () {
monster2Ready = true;
};
monsterImage3.onload = function () {
monster3Ready = true;
};
monsterImageIdle1.onload = function () {
monster1IdleReady = true;
};
monsterImageIdle2.onload = function () {
monster2IdleReady = true;
};
monsterImageIdle3.onload = function () {
monster3IdleReady = true;
};
monsterImage1.src = 'graphics/monster1.png';
monsterImage2.src = 'graphics/monster2.png';
monsterImage3.src = 'graphics/monster3.png';
monsterImageIdle1.src = 'graphics/monster1-idle.png';
monsterImageIdle2.src = 'graphics/monster2-idle.png';
monsterImageIdle3.src = 'graphics/monster3-idle.png';
granadeToPlayer(500, 75, gameArrays.granadeArray);
granadeToPlayer(500, 75, gameArrays.granadeArray);
granadeToPlayer(500, 75, gameArrays.granadeArray);
addEventListener(
'mousemove',
function (e) {
const can = document.getElementById('playground').getBoundingClientRect();
/* if (document.getElementById('centerTest') !== null) {
test = document.getElementById('centerTest');
} else {
test = document.createElement('div');
test.id = 'centerTest';
}
test.style.left = Number(can.left + can.width / 2) + 'px';
test.style.top = Number(can.top + can.height / 2) + 'px';
document.body.appendChild(test); */
var p1 = { x: Number(can.left + can.width / 2), y: Number(can.top + can.height / 2) };
var p2 = { x: e.clientX, y: e.clientY };
var angleDeg = (Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180) / Math.PI - 270;
hero.angle = angleDeg;
//console.log(angleDeg);
},
false
);
addEventListener(
'keydown',
function (e) {
keysDown[e.keyCode] = true;
},
false
);
addEventListener(
'keyup',
function (e) {
delete keysDown[e.keyCode];
if (hero.gun === 'pistol' || hero.gun === 'shotgun' || hero.gun === 'machete') {
gameVariables.hasFired = 0;
} else {
gameVariables.isPressed = 0;
}
},
false
);
addEventListener(
'mousedown',
function (e) {
if (e.target.id === 'playground') {
hero.mouseFire = true;
}
},
false
);
addEventListener(
'mouseup',
function (e) {
hero.mouseFire = false;
if (hero.gun === 'pistol' || hero.gun === 'shotgun' || hero.gun === 'machete') {
gameVariables.hasFired = 0;
} else {
gameVariables.isPressed = 0;
}
},
false
);