-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguitutorial.js
More file actions
687 lines (501 loc) · 20.8 KB
/
Copy pathguitutorial.js
File metadata and controls
687 lines (501 loc) · 20.8 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
//@ts-check
class GUITutorial extends GUIObject {
constructor(depth){
super("Tutorial", 0, 0, depth);
this.show = false;
this.behaviorState = "Start";
this.activeTutorial = null;
}
update(){
this.updateStateMachine();
push();
//skip tutorial text
let textColor = color(255,255,255);
noStroke();
textSize(20);
fill(textColor);
text("Press Q to skip the tutorial at any time", 10, height-15);
textSize(10);
fill(255, 255, 255, 80);
let creditX = width-220;
let creditY = height;
text("CREDITS", creditX, creditY-91);
text("Fonts: G-Type by Gomarice Font", creditX, creditY-78);
text("Sound Effects, Art: Kenney Game Assets", creditX, creditY-65);
text("Music: YouTube Copyright-Free Music Library", creditX, creditY-52);
text(" Above Planets - Patrick Patrikios", creditX, creditY-39);
text(" Cages - Density & Time", creditX, creditY-26);
text(" Lost Constructs - White Hex", creditX, creditY-13);
pop();
//if the player decides to skip the tutorial...
if(!anythingPressedLastFrame && keyIsDown(81)){//Q
this.behaviorState = "Finished";
this.activeTutorial.slatedForDeletion = true;
this.slatedForDeletion = true;
World.instance.player.hitpoints = 100;
World.instance.player.shield.hitpoints = 100;
}
}
updateStateMachine(){
if(this.behaviorState=="Start"){
this.activeTutorial = new MovementTutorial(5);
GUI.instance.addGuiObject(this.activeTutorial);
this.behaviorState="Welcome";
}
if(this.behaviorState=="Welcome"){
if(this.activeTutorial.finished){
this.activeTutorial.slatedForDeletion=true;
this.behaviorState="BeginEnemyTutorial";
}
}
if(this.behaviorState=="BeginEnemyTutorial"){
this.activeTutorial = new EnemyTutorial(5);
GUI.instance.addGuiObject(this.activeTutorial);
this.behaviorState="EnemyTutorial";
}
if(this.behaviorState=="EnemyTutorial"){
if(this.activeTutorial.finished){
this.activeTutorial.slatedForDeletion=true;
this.behaviorState="BeginHomingEnemyTutorial";
}
}
if(this.behaviorState=="BeginHomingEnemyTutorial"){
this.activeTutorial = new HomingEnemyTutorial(5);
GUI.instance.addGuiObject(this.activeTutorial);
this.behaviorState="HomingEnemyTutorial";
}
if(this.behaviorState=="HomingEnemyTutorial"){
if(this.activeTutorial.finished){
this.activeTutorial.slatedForDeletion=true;
this.behaviorState="BeginShootingEnemyTutorial";
}
}
if(this.behaviorState=="BeginShootingEnemyTutorial"){
this.activeTutorial = new ShootingEnemyTutorial(5);
GUI.instance.addGuiObject(this.activeTutorial);
this.behaviorState="ShootingEnemyTutorial";
}
if(this.behaviorState=="ShootingEnemyTutorial"){
if(this.activeTutorial.finished){
this.activeTutorial.slatedForDeletion=true;
this.behaviorState="BeginBlockingTutorial";
}
}
if(this.behaviorState=="BeginBlockingTutorial"){
this.activeTutorial = new BlockingTutorial(5);
GUI.instance.addGuiObject(this.activeTutorial);
this.behaviorState="BlockingTutorial";
}
if(this.behaviorState=="BlockingTutorial"){
if(this.activeTutorial.finished){
this.activeTutorial.slatedForDeletion=true;
this.behaviorState="BeginLaserEnemyTutorial";
}
}
if(this.behaviorState=="BeginLaserEnemyTutorial"){
this.activeTutorial = new LaserEnemyTutorial(5);
GUI.instance.addGuiObject(this.activeTutorial);
this.behaviorState="LaserEnemyTutorial";
}
if(this.behaviorState=="LaserEnemyTutorial"){
if(this.activeTutorial.finished){
this.activeTutorial.slatedForDeletion=true;
this.behaviorState="BeginEndingTutorial";
}
}
if(this.behaviorState=="BeginEndingTutorial"){
this.activeTutorial = new EndingTutorial(5);
GUI.instance.addGuiObject(this.activeTutorial);
this.behaviorState="EndingTutorial";
}
if(this.behaviorState=="EndingTutorial"){
if(this.activeTutorial.finished){
this.activeTutorial.slatedForDeletion=true;
this.behaviorState="Finished";
}
}
if(this.behaviorState=="Finished"){
this.debugLog("Finished the tutorial");
this.activeTutorial.slatedForDeletion = true;
this.slatedForDeletion = true;
}
}
}
const fadeTime = 1000;
class TutorialComponent extends GUIObject {
constructor(type, x, y, depth){
super(type, x, y, depth);
this.finished=false;
this.behaviorState="Initial";
}
}
function getFadeAlphaMult(timer, originalValue){
if(timer<fadeTime){
return timer/fadeTime;
} else if(originalValue-timer<fadeTime){
return (originalValue-timer)/fadeTime;
} else {
return 1;
}
}
class MovementTutorial extends TutorialComponent {
constructor(depth){
super("MovementTutorial",0,0,depth);
this.welcomeTimer = 6000;
this.welcomeCounter = this.welcomeTimer;
this.movementTimer = 15000;
this.movementCounter = this.movementTimer;
}
//technically a violation, but also updates the state machine
display(){
if(Sketch.paused)return;
push();
noStroke();
textAlign(CENTER);
let fillColor = color(255,255,255);
if(this.behaviorState=="Initial"){
World.instance.player.supressShooting = true;
fillColor.setAlpha(255*getFadeAlphaMult(this.welcomeCounter, this.welcomeTimer));
fill(fillColor);
text("Welcome to the game, a short tutorial will follow", width/2, height-100);
text(`${(this.welcomeCounter/1000).toFixed(0)}`, width/2, height-50);
this.welcomeCounter-=deltaTime;
if(this.welcomeCounter<=0){
this.behaviorState="Movement";
}
}
if(this.behaviorState=="Movement"){
fillColor.setAlpha(255*getFadeAlphaMult(this.movementCounter, this.movementTimer));
fill(fillColor);
text("The hand you see is your character.", width/2, height-130);
text("Try moving it around and getting a feel for the boundaries.", width/2, height-100);
text("(The game will pause if your hand goes out of bounds)", width/2, height-70);
text(`${(this.movementCounter/1000).toFixed(0)}`, width/2, height-50);
this.movementCounter-=deltaTime;
if(this.movementCounter<=0){
this.finished=true;
}
}
pop();
}
}
class EnemyTutorial extends TutorialComponent {
constructor(depth){
super("EnemyTutorial",0,0,depth);
this.enemy = new Enemy(width+100, height/2);
this.enemy.movement.velocity.x = -50
this.enemyAdded = false;
this.waitTimeAfterEnemySpawn = 4000;
this.waitTimeAfterEnemySpawnCounter = this.waitTimeAfterEnemySpawn;
this.congratsTimer = 5000;
this.congratsCounter = this.congratsTimer;
}
//technically a violation, but also updates the state machine
display(){
push();
noStroke();
textAlign(CENTER);
let fillColor = color(255,255,255);
if(this.behaviorState=="Initial"){
//text("Welcome to the game, a short tutorial will follow", width/2, height-100);
if(!(this.enemyAdded)){
World.instance.addGameObject(this.enemy);
this.enemyAdded=true;
}
this.waitTimeAfterEnemySpawnCounter-=deltaTime;
if(this.waitTimeAfterEnemySpawnCounter<=0){
this.behaviorState="Instructions";
}
}
if(this.behaviorState=="Instructions"){
World.instance.player.supressShooting = false;
//fillColor.setAlpha(255*getFadeAlphaMult(this.pauseCounter, this.pauseTimer));
fillColor.setAlpha(255);
fill(fillColor);
text("What you see coming in from the right is an enemy.", width/2, height-130);
text("Do a fingergun gesture, aim, and destroy it!.", width/2, height-100);
//text(`Unpause in: ${(this.pauseCounter/1000).toFixed(0)}`, width/2, height-50);
if(this.enemy.slatedForDeletion==true || this.enemy==null){
this.behaviorState="Congrats";
}
}
if(this.behaviorState=="Congrats"){
World.instance.player.supressShooting = true;
fillColor.setAlpha(255*getFadeAlphaMult(this.congratsCounter, this.congratsTimer));
fill(fillColor);
text("Good Job!", width/2, height-130);
text(`${(this.congratsCounter/1000).toFixed(0)}`, width/2, height-50);
this.congratsCounter-=deltaTime;
if(this.congratsCounter<=0){
this.behaviorState="Finished";
}
}
if(this.behaviorState=="Finished"){
this.finished=true;
}
pop();
}
}
class HomingEnemyTutorial extends TutorialComponent {
constructor(depth){
super("HomingEnemyTutorial",0,0,depth);
this.enemy = new HomingEnemy(width+100, height/2);
this.enemyAdded = false;
this.enemy.hitpoints = 150;
this.waitTimeAfterEnemySpawn = 100;
this.waitTimeAfterEnemySpawnCounter = this.waitTimeAfterEnemySpawn;
this.congratsTimer = 4000;
this.congratsCounter = this.congratsTimer;
}
//technically a violation, but also updates the state machine
display(){
push();
noStroke();
textAlign(CENTER);
let fillColor = color(255,255,255);
if(this.behaviorState=="Initial"){
//text("Welcome to the game, a short tutorial will follow", width/2, height-100);
if(!(this.enemyAdded)){
World.instance.addGameObject(this.enemy);
this.enemyAdded=true;
}
this.waitTimeAfterEnemySpawnCounter-=deltaTime;
if(this.waitTimeAfterEnemySpawnCounter<=0){
this.behaviorState="Instructions";
}
}
if(this.behaviorState=="Instructions"){
World.instance.player.supressShooting = false;
//fillColor.setAlpha(255*getFadeAlphaMult(this.pauseCounter, this.pauseTimer));
fillColor.setAlpha(255);
fill(fillColor);
text("This one tracks you. DODGE THEM!", width/2, height-130);
text("(Or shoot them if your aim is good).", width/2, height-100);
//text(`Unpause in: ${(this.pauseCounter/1000).toFixed(0)}`, width/2, height-50);
if(this.enemy.slatedForDeletion==true || this.enemy==null){
this.behaviorState="Congrats";
}
}
if(this.behaviorState=="Congrats"){
World.instance.player.supressShooting = true;
fillColor.setAlpha(255*getFadeAlphaMult(this.congratsCounter, this.congratsTimer));
fill(fillColor);
text("Good Job!", width/2, height-130);
text(`${(this.congratsCounter/1000).toFixed(0)}`, width/2, height-50);
this.congratsCounter-=deltaTime;
if(this.congratsCounter<=0){
this.behaviorState="Finished";
}
}
if(this.behaviorState=="Finished"){
this.finished=true;
}
pop();
}
}
class ShootingEnemyTutorial extends TutorialComponent {
constructor(depth){
super("ShootingEnemyTutorial",0,0,depth);
this.enemy = new ShootingEnemy(width+100, height/2);
this.enemy.hitpoints = 200;
this.enemyAdded = false;
this.waitTimeAfterEnemySpawn = 100;
this.waitTimeAfterEnemySpawnCounter = this.waitTimeAfterEnemySpawn;
this.congratsTimer = 4000;
this.congratsCounter = this.congratsTimer;
}
//technically a violation, but also updates the state machine
display(){
push();
noStroke();
textAlign(CENTER);
let fillColor = color(255,255,255);
if(this.behaviorState=="Initial"){
//text("Welcome to the game, a short tutorial will follow", width/2, height-100);
if(!(this.enemyAdded)){
World.instance.addGameObject(this.enemy);
this.enemyAdded=true;
}
this.waitTimeAfterEnemySpawnCounter-=deltaTime;
if(this.waitTimeAfterEnemySpawnCounter<=0){
this.behaviorState="Instructions";
}
}
if(this.behaviorState=="Instructions"){
World.instance.player.supressShooting = false;
//fillColor.setAlpha(255*getFadeAlphaMult(this.pauseCounter, this.pauseTimer));
fillColor.setAlpha(255);
fill(fillColor);
text("This next one shoots at you.", width/2, height-130);
text("Dodge and take aim simultaneously!", width/2, height-100);
//text(`Unpause in: ${(this.pauseCounter/1000).toFixed(0)}`, width/2, height-50);
if(this.enemy.slatedForDeletion==true || this.enemy==null){
this.behaviorState="Congrats";
}
}
if(this.behaviorState=="Congrats"){
World.instance.player.supressShooting = true;
fillColor.setAlpha(255*getFadeAlphaMult(this.congratsCounter, this.congratsTimer));
fill(fillColor);
text("Good Job!", width/2, height-130);
text(`${(this.congratsCounter/1000).toFixed(0)}`, width/2, height-50);
this.congratsCounter-=deltaTime;
if(this.congratsCounter<=0){
this.behaviorState="Finished";
}
}
if(this.behaviorState=="Finished"){
this.finished=true;
}
pop();
}
}
class BlockingTutorial extends TutorialComponent {
constructor(depth){
super("BlockingTutorial",0,0,depth);
this.enemy = new ShootingEnemy(width+100, height/2);
this.enemyAdded = false;
this.waitTimeAfterEnemySpawn = 100;
this.waitTimeAfterEnemySpawnCounter = this.waitTimeAfterEnemySpawn;
this.congratsTimer = 9000;
this.congratsCounter = this.congratsTimer;
}
//technically a violation, but also updates the state machine
display(){
push();
noStroke();
textAlign(CENTER);
let fillColor = color(255,255,255);
if(this.behaviorState=="Initial"){
World.instance.player.supressShooting = true;
//text("Welcome to the game, a short tutorial will follow", width/2, height-100);
if(!(this.enemyAdded)){
World.instance.addGameObject(this.enemy);
this.enemyAdded=true;
}
this.waitTimeAfterEnemySpawnCounter-=deltaTime;
if(this.waitTimeAfterEnemySpawnCounter<=0){
this.behaviorState="Instructions";
}
}
if(this.behaviorState=="Instructions"){
//fillColor.setAlpha(255*getFadeAlphaMult(this.pauseCounter, this.pauseTimer));
fillColor.setAlpha(255);
fill(fillColor);
text("Ball your hand into a fist to block with your shields.", width/2, height-130);
text("Here comes another, try blocking and ramming them this time!", width/2, height-100);
//text(`Unpause in: ${(this.pauseCounter/1000).toFixed(0)}`, width/2, height-50);
if(this.enemy.slatedForDeletion==true || this.enemy==null){
this.behaviorState="Congrats";
}
}
if(this.behaviorState=="Congrats"){
fillColor.setAlpha(255*getFadeAlphaMult(this.congratsCounter, this.congratsTimer));
fill(fillColor);
text("Notice that your shield must recharge, and increases your hitbox.", width/2, height-130);
text("You cannot simultaneously block and shoot.", width/2, height-100);
text("Maybe dodging is better in certain cases?", width/2, height-70);
text(`${(this.congratsCounter/1000).toFixed(0)}`, width/2, height-50);
this.congratsCounter-=deltaTime;
if(this.congratsCounter<=0){
this.behaviorState="Finished";
}
}
if(this.behaviorState=="Finished"){
this.finished=true;
}
pop();
}
}
class LaserEnemyTutorial extends TutorialComponent {
constructor(depth){
super("LaserEnemyTutorial",0,0,depth);
this.enemy = new LaserEnemy(width+100, height/2);
this.enemy.hitpoints = 200;
this.enemyAdded = false;
this.waitTimeAfterEnemySpawn = 100;
this.waitTimeAfterEnemySpawnCounter = this.waitTimeAfterEnemySpawn;
this.congratsTimer = 10000;
this.congratsCounter = this.congratsTimer;
}
//technically a violation, but also updates the state machine
display(){
push();
noStroke();
textAlign(CENTER);
let fillColor = color(255,255,255);
if(this.behaviorState=="Initial"){
//text("Welcome to the game, a short tutorial will follow", width/2, height-100);
if(!(this.enemyAdded)){
World.instance.addGameObject(this.enemy);
this.enemyAdded=true;
}
this.waitTimeAfterEnemySpawnCounter-=deltaTime;
if(this.waitTimeAfterEnemySpawnCounter<=0){
this.behaviorState="Instructions";
}
}
if(this.behaviorState=="Instructions"){
//fillColor.setAlpha(255*getFadeAlphaMult(this.pauseCounter, this.pauseTimer));
fillColor.setAlpha(255);
fill(fillColor);
text("You can't dodge this next enemy's shots.", width/2, height-130);
text("You must block their shot! (ball your hand into a fist)", width/2, height-100);
//text(`Unpause in: ${(this.pauseCounter/1000).toFixed(0)}`, width/2, height-50);
if(this.enemy.slatedForDeletion==true || this.enemy==null){
this.behaviorState="Congrats";
}
}
if(this.behaviorState=="Congrats"){
World.instance.player.supressShooting = false;
fillColor.setAlpha(255*getFadeAlphaMult(this.congratsCounter, this.congratsTimer));
fill(fillColor);
text("Even if you don't destroy an enemy, they will leave after a while.", width/2, height-130);
text("Destroying enemies also restores your HP.", width/2, height-100);
text("Destroy as many possible to earn the most points!", width/2, height-70);
text(`${(this.congratsCounter/1000).toFixed(0)}`, width/2, height-50);
this.congratsCounter-=deltaTime;
if(this.congratsCounter<=0){
this.behaviorState="Finished";
}
}
if(this.behaviorState=="Finished"){
this.finished=true;
}
pop();
}
}
class EndingTutorial extends TutorialComponent {
constructor(depth){
super("EndingTutorial",0,0,depth);
this.congratsTimer = 8000;
this.congratsCounter = this.congratsTimer;
}
//technically a violation, but also updates the state machine
display(){
push();
noStroke();
textAlign(CENTER);
let fillColor = color(255,255,255);
if(this.behaviorState=="Initial"){
World.instance.player.supressShooting = false;
this.behaviorState="Congrats";
}
if(this.behaviorState=="Congrats"){
fillColor.setAlpha(255*getFadeAlphaMult(this.congratsCounter, this.congratsTimer));
fill(fillColor);
text("All in all, how to play the game:", width/2, height-130);
text("Dodge, shoot, and block;", width/2, height-100);
text("Destroy enemies, survive, and get a high score!", width/2, height-70);
text(`${(this.congratsCounter/1000).toFixed(0)}`, width/2, height-50);
this.congratsCounter-=deltaTime;
if(this.congratsCounter<=0){
this.behaviorState="Finished";
}
}
if(this.behaviorState=="Finished"){
this.finished=true;
}
pop();
}
}