-
Notifications
You must be signed in to change notification settings - Fork 8
/
Table.gd
1136 lines (1036 loc) · 32.3 KB
/
Table.gd
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
# This script manages most of the table logic.
extends Node
# High score file location
const HIGH_SCORE_FILE = "user://high_score"
# Screen geometry constants
const WINDOW_SIZE = Vector2(896, 2016)
const BALL_ENTRY = Vector2(834, 1810)
const BALL_EJECT = Vector2(0, -2000)
# Force and other values for bumpers, kickers, nudging
const RELEASE_FORCE = 750
const NUDGE_V_FORCE = 300
const NUDGE_H_FORCE = 300
const NUDGE_VIEW_OFFSET = 10
const FORCE_BUMPER = 700.0
const FORCE_KICKER = 1200.0
# Score awards
const SCORE_BUMPER = 25
const SCORE_DROP = 100
const SCORE_DROP_ALL = 1000
const SCORE_KICKER = 10
const SCORE_LANE = 500
const SCORE_LANE_HUNT = 5000
const SCORE_TARGET_HUNT = 5000
const SCORE_ALL_BUMPERS = 5000
const SCORE_LOOP = 250
const SCORE_JACKPOT = 10000
const SCORE_WIZARD_LANE = 2500
const SCORE_BONUS = 100
const SCORE_SKILL_SHOT = 1000
# Goals for game events
const EXTRA_BALL_GOAL = 100000
const BUMPER_PROGRESS = 10
const BUMPER_GOAL = 100
# Bottom-of-screen needles hit their max when the ball reaches this velocity
const NEEDLE_MAX_VELOCITY = 2000.0
# Timing for certain conditions
const OUT_TIME = 3.0
const BONUS_TIME = 5.0
const SLOW_RELEASE_TIME = 4.0
const COUNTDOWN_LEAD_TIME = 30.0
const COUNTDOWN_TICK_TIME = 1.0
# Color values
const EJECT_IMPACT_COLOR = Color(0.7, 0.7, 1.0)
const WIZARD_LANE_IMPACT_COLOR = Color(1.0, 0.7, 0.7)
const KICKER_IMPACT_COLOR = Color(1.0, 1.0, 0.5)
const BUMPER_IMPACT_COLOR = Color(0.7, 0.7, 1.0)
const TARGET_IMPACT_COLOR = Color(1.0, 0.5, 1.0)
# Values used to track what mode the game is in
enum {
MODE_ATTRACT,
MODE_NORMAL,
MODE_MULTIBALL,
MODE_LANE_HUNT,
MODE_TARGET_HUNT,
MODE_WIZARD,
MODE_GAME_OVER,
MODE_NEW_HIGH,
MODE_BALL_OUT,
MODE_BONUS}
var rng = RandomNumberGenerator.new()
var ball_scene = preload("res://Ball.tscn")
var impact_scene = preload("res://Impact.tscn")
var zap_scene = preload("res://Zap.tscn")
var score
var ball
var last_ball
var lit_lane
var save_lit
var save_next_ball
var special_lit
var skill_gate
var multiplier
var balls_queued
var balls_in_play
var mode
var lanes
var loops
var banks
var bumps
var lane_hunt_1
var lane_hunt_2
var lane_hunt_3
var targets_hunted
var lane_hunter_victory
var target_hunter_victory
var multiball_victory
var bumper_victory
var high_score
var ticks
func _ready():
#Engine.set_time_scale(0.5) Uncomment this to slow the game down
# The game starts at a low resolution so the splash screen will look correct.
# These lines set us to the correct higher resolution.
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_2D, SceneTree.STRETCH_ASPECT_KEEP, WINDOW_SIZE)
OS.set_window_fullscreen(true)
# Read the high score file, or set up a new file.
var high_score_file = File.new()
if high_score_file.file_exists(HIGH_SCORE_FILE):
high_score_file.open(HIGH_SCORE_FILE, File.READ)
high_score = high_score_file.get_64()
else:
high_score_file.open(HIGH_SCORE_FILE, File.WRITE)
high_score_file.store_64(0)
high_score = 0
high_score_file.close()
$DMD.set_parameter("high_score", high_score)
# Start up all other table systems.
rng.randomize()
$Toy.lower_all_gates()
$AudioStreamPlayer.play_startup()
attract(true)
func _process(delta):
# Handle input from player.
if Input.is_action_just_pressed("ui_start"):
if get_tree().paused:
get_tree().paused = false
$DMD.set_paused(false)
elif mode == MODE_ATTRACT:
mode = MODE_NORMAL
new_game()
if Input.is_action_just_pressed("ui_nudge_up") and $NudgeUpTimer.is_stopped():
nudge_up()
if Input.is_action_just_pressed("ui_nudge_left") and $NudgeLeftTimer.is_stopped():
nudge_left()
if Input.is_action_just_pressed("ui_nudge_right") and $NudgeRightTimer.is_stopped():
nudge_right()
if Input.is_action_just_pressed("ui_pause"):
if get_tree().paused:
get_tree().quit()
else:
get_tree().paused = true
$DMD.set_paused(true)
if Input.is_action_just_pressed("ui_help"):
if $Instructions.is_visible():
$Instructions.conceal()
else:
$Instructions.reveal()
# Set needles to reflect ball velocity.
var balls = get_tree().get_nodes_in_group("balls")
var max_x = 0.0
var max_y = 0.0
for ball in balls:
var ball_velocity = ball.get_linear_velocity()
if abs(ball_velocity.x) > max_x:
max_x = abs(ball_velocity.x)
if abs(ball_velocity.y) > max_y:
max_y = abs(ball_velocity.y)
$LeftNeedle.set_level(max_x / NEEDLE_MAX_VELOCITY)
$RightNeedle.set_level(max_y / NEEDLE_MAX_VELOCITY)
"""
Uncomment this code to enable special debugging controls.
The E key toggles which capture lane reward is lit.
The W key marks all events as complete.
func _unhandled_input(event):
if event is InputEventKey:
if event.pressed:
if event.scancode == KEY_E:
change_special()
if event.scancode == KEY_W:
lane_hunter_victory = true
target_hunter_victory = true
multiball_victory = true
bumper_victory = true
bumps = 110
$TargetHuntVictoryLight.switch_on()
$LaneHuntVictoryLight.switch_on()
$MultiballVictoryLight.switch_on()
$BumperVictoryLight.switch_on()
check_wizard_mode()
"""
# Set up the between-game attract mode effects.
func attract(startup = false):
if startup:
# If we just started up, we can't show the score from the prior game.
$DMD.show_sequence($DMD.START_SEQ, true)
else:
# This DMD sequence includes the score from the prior game.
$DMD.show_sequence($DMD.ATTRACT_SEQ, true)
# Start all the lights flashing in a rotating sequence.
mode = MODE_ATTRACT
$LaneLight1.flash(3.0, 0.6)
$LaneLight2.flash(3.0, 1.2)
$LaneLight3.flash(3.0, 1.8)
$LaneLight4.flash(3.0, 2.4)
$LaneLight5.flash(3.0)
$TargetHuntVictoryLight.flash(3.0, 0.75)
$LaneHuntVictoryLight.flash(3.0, 1.5)
$MultiballVictoryLight.flash(3.0, 2.25)
$BumperVictoryLight.flash(3.0, 0)
$LeftTargetLight.flash(3.0, 1.5)
$RightTargetLight.flash(3.0)
$SpecialLight1.flash(3.0, 1.0)
$SpecialLight2.flash(3.0, 2.0)
$SpecialLight3.flash(3.0)
$X2Light.flash(3.0, 1.0)
$X4Light.flash(3.0, 2.0)
$X8Light.flash(3.0)
$SaveLight.flash(3.0)
$Bumper1.get_node("Light").flash(3.0, 1.0)
$Bumper2.get_node("Light").flash(3.0, 2.0)
$Bumper3.get_node("Light").flash(3.0)
$LeftKickerLight.flash(3.0, 1.5)
$RightKickerLight.flash(3.0)
$SkillLight1.flash(3.0, 1.0)
$SkillLight2.flash(3.0, 2.0)
$SkillLight3.flash(3.0)
# Start a new game.
func new_game():
# Reset game variables.
score = 0
ball = 1
last_ball = 3
lit_lane = 0
save_lit = false
save_next_ball = true
special_lit = 1
skill_gate = 0
multiplier = 1
balls_queued = 0
mode = MODE_NORMAL
lanes = 0
loops = 0
banks = 0
targets_hunted = 0
balls_in_play = 0
bumps = 0
lane_hunter_victory = false
target_hunter_victory = false
multiball_victory = false
bumper_victory = false
# Set up the table.
$Toy.start()
$DMD.set_parameter("score", score)
$DMD.set_parameter("ball", ball)
clear_all_lights()
change_lit_lane(false)
$SpecialLight1.switch_on()
$ResetLeftTargets.start()
$ResetRightTargets.start()
new_ball()
$AudioStreamPlayer.play_begin()
# Create a particle effect when the ball hits something interesting.
func impact(ball, color):
var new_impact = impact_scene.instance()
new_impact.set_global_position(ball.get_global_position())
new_impact.setup(color, mode == MODE_WIZARD)
call_deferred("add_child", new_impact)
# Common logic for hitting a bumper.
func bump(ball, bumper, force):
impact(ball, BUMPER_IMPACT_COLOR)
# Apply velocity due to impact from bumper.
var from_bumper = ball.get_position() - bumper.get_position()
ball.apply_central_impulse(from_bumper.normalized() * force)
# Apply score and rules due to bumper hit.
add_score(SCORE_BUMPER)
bumps += 1
if bumps >= BUMPER_GOAL:
if bumper_victory == false:
bumper_victory = true
$AudioStreamPlayer.play_award()
$DMD.set_parameter("reward", SCORE_ALL_BUMPERS)
$DMD.show_once($DMD.DISPLAY_BUMPER_REWARD)
$BumperVictoryLight.flash_on()
check_wizard_mode()
elif bumps % BUMPER_PROGRESS == 0:
$DMD.set_parameter("progress", BUMPER_GOAL - bumps)
$DMD.show_once($DMD.DISPLAY_BUMPER_PROGRESS)
# Common logic for hitting a kicker.
func kick(ball, kicker, force):
add_score(SCORE_KICKER)
impact(ball, KICKER_IMPACT_COLOR)
"""
# Find offset from ball to kicker origin.
var offset = ball.get_position() - kicker.get_position()
# Rotate around kicker origin based on kicker orientation.
var rotated_offset = offset.rotated(0 - kicker.get_global_rotation())
# Determine whether ball is on the "kick" side.
if rotated_offset.x > 0:
# If so, apply impulse.
ball.apply_central_impulse(Vector2.RIGHT.rotated(kicker.get_global_rotation()) * force)
"""
ball.apply_central_impulse(Vector2.RIGHT.rotated(kicker.get_global_rotation()) * force)
# Nudge the table up.
func nudge_up(first_impulse = true):
var view_transform = get_viewport().get_canvas_transform()
if first_impulse:
# Initial nudge - the ball slides down.
get_tree().call_group("balls", "apply_central_impulse", Vector2.DOWN * NUDGE_V_FORCE)
view_transform.origin += Vector2.UP * NUDGE_VIEW_OFFSET
$NudgeUpTimer.start()
else:
# Table bounces back - the ball slides up.
get_tree().call_group("balls", "apply_central_impulse", Vector2.UP * NUDGE_V_FORCE)
view_transform.origin += Vector2.DOWN * NUDGE_VIEW_OFFSET
get_viewport().set_canvas_transform(view_transform)
# Nudge the table from the left side.
func nudge_left(first_impulse = true):
var view_transform = get_viewport().get_canvas_transform()
if first_impulse:
# Initial nudge - the ball slides left.
get_tree().call_group("balls", "apply_central_impulse", Vector2.LEFT * NUDGE_H_FORCE)
view_transform.origin += Vector2.RIGHT * NUDGE_VIEW_OFFSET
$NudgeLeftTimer.start()
else:
# Table bounces back - the ball slides right.
get_tree().call_group("balls", "apply_central_impulse", Vector2.RIGHT * NUDGE_H_FORCE)
view_transform.origin += Vector2.LEFT * NUDGE_VIEW_OFFSET
get_viewport().set_canvas_transform(view_transform)
# Nudge the table from the right side.
func nudge_right(first_impulse = true):
var view_transform = get_viewport().get_canvas_transform()
if first_impulse:
# Initial nudge - the ball slides right.
get_tree().call_group("balls", "apply_central_impulse", Vector2.RIGHT * NUDGE_H_FORCE)
view_transform.origin += Vector2.LEFT * NUDGE_VIEW_OFFSET
$NudgeRightTimer.start()
else:
# Table bounces back - the ball slides left.
get_tree().call_group("balls", "apply_central_impulse", Vector2.LEFT * NUDGE_H_FORCE)
view_transform.origin += Vector2.RIGHT * NUDGE_VIEW_OFFSET
get_viewport().set_canvas_transform(view_transform)
# Put a new ball in play.
func new_ball(eject = false):
if mode != MODE_MULTIBALL:
$DMD.show_and_keep($DMD.DISPLAY_SCORE)
if save_next_ball:
# Usually, if we just lost a ball, we'll turn on ball save for the new ball.
save_next_ball = false
save_lit = true
$SaveLight.switch_on()
$BallSaveTimer.start()
# Put the ball on the table.
var new_ball = ball_scene.instance()
new_ball.set_global_position(BALL_ENTRY)
if eject:
# Sometimes we want to eject the ball automatically.
new_ball.set_linear_velocity(BALL_EJECT)
if mode == MODE_WIZARD:
impact(new_ball, EJECT_IMPACT_COLOR)
else:
# But if we're not auto-ejecting the ball, we'll set up a skill shot opportunity.
choose_skill_gate()
$AudioStreamPlayer.play_new_ball()
if (not eject) or (mode == MODE_MULTIBALL):
balls_in_play += 1
call_deferred("add_child", new_ball)
# Randomly pick a skill shot gate.
func choose_skill_gate():
skill_gate = rng.randi_range(1, 3)
match skill_gate:
1:
$SkillLight1.flash_on()
2:
$SkillLight2.flash_on()
3:
$SkillLight3.flash_on()
$SkillShotTimer.start()
# Check if the ball hit the lit skill shot gate.
func check_skill_gate(gate_hit):
if skill_gate == gate_hit:
match skill_gate:
1:
$SkillLight1.flash_off()
2:
$SkillLight2.flash_off()
3:
$SkillLight3.flash_off()
skill_gate = 0
add_score(SCORE_SKILL_SHOT)
$DMD.show_once($DMD.DISPLAY_SKILL_SHOT)
$AudioStreamPlayer.play_award()
else:
clear_skill_gates()
# Turn off the skill shot gates.
func clear_skill_gates():
skill_gate = 0
$SkillLight1.switch_off()
$SkillLight2.switch_off()
$SkillLight3.switch_off()
$SkillShotTimer.stop()
# Increment score, update DMD, and check if we earned an extra ball.
func add_score(points):
score += points
$DMD.set_parameter("score", score)
check_extra_ball()
# These effects run when the ball passes through the upper loop.
func looped():
$LoopLight.flash_off()
if mode == MODE_MULTIBALL:
# Score a jackpot if multiball is running.
add_score(SCORE_JACKPOT)
$DMD.show_once($DMD.DISPLAY_JACKPOT)
$AudioStreamPlayer.play_jackpot()
else:
# Otherwise increment loops for end-of-ball bonus.
loops += 1
add_score(SCORE_LOOP)
$DMD.show_once($DMD.DISPLAY_LOOP)
$AudioStreamPlayer.play_loop()
# Check whether the player has earned an extra ball.
func check_extra_ball():
if score >= EXTRA_BALL_GOAL and last_ball == 3:
last_ball = 4
$DMD.show_once($DMD.DISPLAY_EXTRA_BALL)
$AudioStreamPlayer.play_jackpot()
# Check whether the player has triggered multiball.
func check_multiball():
print("entering check_multiball")
if $Toy.are_all_gates_raised():
print("all gates are raised")
halt_events()
mode = MODE_MULTIBALL
lit_lane = 0
balls_queued = 3
balls_in_play = 0
save_lit = false
$MultiballVictoryLight.flash_on()
$DMD.show_once($DMD.DISPLAY_MULTIBALL)
$LaneLight1.flash()
$LaneLight3.flash()
$SaveLight.switch_off()
$BallSaveTimer.stop()
$LaneLight1.switch_off()
$LaneLight2.switch_off()
$LaneLight3.switch_off()
$LaneLight4.switch_off()
$LaneLight5.switch_off()
turn_off_specials()
$Toy.flash()
$AudioStreamPlayer.play_challenge()
else:
print("gates are not raised")
$DMD.show_once($DMD.DISPLAY_LOCKED)
$Toy.flash_off()
print("starting BallEjectTimer")
$BallEjectTimer.start()
# Change which lane is lit.
func change_lit_lane(score_lane = true):
if score_lane:
# If we're scoring this event, flash the hit lane.
match lit_lane:
1:
$LaneLight1.flash_off()
2:
$LaneLight2.flash_off()
3:
$LaneLight3.flash_off()
4:
$LaneLight4.flash_off()
5:
$LaneLight5.flash_off()
else:
# Otherwise just switch off all the lanes.
$LaneLight1.switch_off()
$LaneLight2.switch_off()
$LaneLight3.switch_off()
$LaneLight4.switch_off()
$LaneLight5.switch_off()
var new_lit_lane = lit_lane
while new_lit_lane == lit_lane:
new_lit_lane = rng.randi_range(1, 5)
lit_lane = new_lit_lane
if score_lane:
# If we're scoring this event, increment the lane counter for the end-of-ball bonus.
lanes += 1
add_score(SCORE_LANE)
$DMD.show_once($DMD.DISPLAY_LANE_REWARD)
$AudioStreamPlayer.play_lane()
# Light up the new lane.
match lit_lane:
1:
$LaneLight1.switch_on()
2:
$LaneLight2.switch_on()
3:
$LaneLight3.switch_on()
4:
$LaneLight4.switch_on()
5:
$LaneLight5.switch_on()
# If the player hit a lane during the lane hunt event, check if the event was completed.
func check_lane_hunt():
$AudioStreamPlayer.play_lane()
$DMD.show_once($DMD.DISPLAY_LANE_HUNTED)
# If all the flashing lanes were hit, the event is complete.
if lane_hunt_1 and lane_hunt_2 and lane_hunt_3:
lane_hunter_victory = true
$LaneHuntVictoryLight.flash_on()
check_wizard_mode()
add_score(SCORE_LANE_HUNT)
$AudioStreamPlayer.play_award()
$DMD.set_parameter("reward", SCORE_LANE_HUNT)
$DMD.show_once($DMD.DISPLAY_LANE_HUNT_REWARD)
$CountdownTimer.stop()
mode = MODE_NORMAL
change_lit_lane(false)
change_special()
# If the player hits any lane during wizard mode, give an extra reward.
func wizard_lane(active_ball):
add_score(SCORE_WIZARD_LANE)
$DMD.set_parameter("reward", SCORE_WIZARD_LANE)
$DMD.show_once($DMD.DISPLAY_WIZARD_JACKPOT)
$AudioStreamPlayer.play_jackpot()
impact(active_ball, WIZARD_LANE_IMPACT_COLOR)
# Switch which special reward is lit, in front of the capture lane.
func change_special():
if mode != MODE_MULTIBALL and mode != MODE_WIZARD:
match special_lit:
1:
special_lit = 2
$SpecialLight1.switch_off()
$SpecialLight2.switch_on()
2:
special_lit = 3
$SpecialLight2.switch_off()
$SpecialLight3.switch_on()
3:
special_lit = 1
$SpecialLight3.switch_off()
$SpecialLight1.switch_on()
# Turn off special reward lights.
func turn_off_specials():
$SpecialLight1.switch_off()
$SpecialLight2.switch_off()
$SpecialLight3.switch_off()
# Turn on special reward lights.
func turn_on_specials():
match special_lit:
1:
$SpecialLight1.switch_on()
2:
$SpecialLight2.switch_on()
3:
$SpecialLight3.switch_on()
# Identify whether all events are complete.
func all_events_complete():
return lane_hunter_victory and target_hunter_victory and multiball_victory and bumper_victory
# Get ready for wizard mode if all events are complete.
func check_wizard_mode():
if all_events_complete():
$SpecialLight1.flash()
$SpecialLight2.flash()
$SpecialLight3.flash()
$Toy.raise_all_gates()
$WizardReadyTimer.start()
# Start wizard mode.
func start_wizard_mode():
turn_off_specials()
$WizardReadyTimer.stop()
$BallSaveTimer.stop()
$ZapTimer.start()
lit_lane = 0
save_lit = false
$DMD.show_once($DMD.DISPLAY_WIZARD)
$LaneLight1.flash(0.2)
$LaneLight2.flash(0.2)
$LaneLight3.flash(0.2)
$LaneLight4.flash(0.2)
$LaneLight5.flash(0.2)
$TargetHuntVictoryLight.flash(1.0)
$LaneHuntVictoryLight.flash(1.0, 2.0)
$MultiballVictoryLight.flash(1.0)
$BumperVictoryLight.flash(1.0, 2.0)
$SaveLight.switch_on()
$Toy.flash(1.0)
mode = MODE_WIZARD
$AudioStreamPlayer.play_wizard()
$WizardModeTimer.start()
$BallReleaseRightTimer.start(1.0)
# Turn off all the table lights.
func clear_all_lights():
$SpecialLight1.switch_off()
$SpecialLight2.switch_off()
$SpecialLight3.switch_off()
$LaneLight1.switch_off()
$LaneLight2.switch_off()
$LaneLight3.switch_off()
$LaneLight4.switch_off()
$LaneLight5.switch_off()
$LaneHuntVictoryLight.switch_off()
$TargetHuntVictoryLight.switch_off()
$MultiballVictoryLight.switch_off()
$BumperVictoryLight.switch_off()
$X2Light.switch_off()
$X4Light.switch_off()
$X8Light.switch_off()
$LeftTargetLight.switch_off()
$RightTargetLight.switch_off()
$SaveLight.switch_off()
$Toy.switch_off()
$Bumper1.get_node("Light").switch_off()
$Bumper2.get_node("Light").switch_off()
$Bumper3.get_node("Light").switch_off()
$LeftKickerLight.switch_off()
$RightKickerLight.switch_off()
$SkillLight1.switch_off()
$SkillLight2.switch_off()
$SkillLight3.switch_off()
# Stop any active event.
func halt_events():
match mode:
MODE_MULTIBALL:
turn_on_specials()
$Toy.switch_off()
$Toy.lower_all_gates()
MODE_LANE_HUNT:
$LaneLight1.switch_off()
$LaneLight2.switch_off()
$LaneLight3.switch_off()
$CountdownTimer.stop()
change_lit_lane(false)
change_special()
MODE_TARGET_HUNT:
$DropTarget1.raise()
$DropTarget2.raise()
$DropTarget3.raise()
$DropTarget4.raise()
$DropTarget5.raise()
$DropTarget6.raise()
$CountdownTimer.stop()
$LeftTargetLight.switch_off()
$RightTargetLight.switch_off()
change_special()
MODE_WIZARD:
lane_hunter_victory = false
target_hunter_victory = false
multiball_victory = false
bumper_victory = false
bumps = 0
clear_all_lights()
change_lit_lane(false)
$WizardModeTimer.stop()
$ZapTimer.stop()
$Toy.lower_all_gates()
turn_on_specials()
mode = MODE_NORMAL
# This function runs multiple times after a game is over.
func game_over():
match mode:
MODE_GAME_OVER:
# After showing the game over message, show the new high score if appropriate.
if score > high_score:
high_score = score
var high_score_file = File.new()
high_score_file.open(HIGH_SCORE_FILE, File.WRITE_READ)
high_score_file.store_64(high_score)
high_score_file.close()
$DMD.set_parameter("high_score", high_score)
$DMD.show_and_keep($DMD.DISPLAY_NEW_HIGH_SCORE)
$AudioStreamPlayer.play_jackpot()
$GameOverTimer.start()
mode = MODE_NEW_HIGH
else:
attract()
MODE_NEW_HIGH:
# After showing the new high score, fall back to the attract loop.
attract()
_:
# If this is the first entry to this function, show the game over message.
mode = MODE_GAME_OVER
$WizardModeTimer.stop()
$Toy.reset()
$DMD.show_and_keep($DMD.DISPLAY_GAME_OVER)
$AudioStreamPlayer.play_end()
$GameOverTimer.start()
# These effects run when the ball drains.
func _on_Exit_body_entered(body):
balls_in_play -= 1
body.queue_free()
if save_lit:
# If ball save is lit, eject a replacement ball.
save_lit = false
$SaveLight.flash_off()
$BallSaveTimer.stop()
$BallEjectTimer.start()
$DMD.show_once($DMD.DISPLAY_BALL_SAVED)
$AudioStreamPlayer.play_save()
elif mode == MODE_WIZARD:
# If we're in wizard mode, eject a replacement ball.
$SaveLight.flash_on()
$BallEjectTimer.start()
else:
if mode == MODE_MULTIBALL:
if balls_queued == 0 and balls_in_play == 1:
# If we're in multiball and there's only one ball left, turn off multiball.
halt_events()
multiball_victory = true
check_wizard_mode()
else:
# If we're not in multiball, that's the end of this ball.
halt_events()
$X2Light.switch_off()
$X4Light.switch_off()
$X8Light.switch_off()
ball += 1
# Calculate and display the end-of-ball bonuses.
var loops_bonus = loops * SCORE_BONUS
var lanes_bonus = lanes * SCORE_BONUS
var banks_bonus = banks * SCORE_BONUS
var total_bonus = multiplier * (loops_bonus + lanes_bonus + banks_bonus)
score += total_bonus
$DMD.set_parameter("score", score)
$DMD.set_parameter("ball", ball)
$DMD.set_parameter("loops", loops)
$DMD.set_parameter("loops_bonus", loops_bonus)
$DMD.set_parameter("lanes", lanes)
$DMD.set_parameter("lanes_bonus", lanes_bonus)
$DMD.set_parameter("banks", banks)
$DMD.set_parameter("banks_bonus", banks_bonus)
$DMD.set_parameter("reward", total_bonus)
$DMD.set_parameter("multiplier", multiplier)
$DMD.show_and_keep($DMD.DISPLAY_BALL_LOST)
multiplier = 1
save_next_ball = true
mode = MODE_BALL_OUT
$AudioStreamPlayer.play_drain()
$BallLostTimer.start(OUT_TIME)
# These effects run when the ball enters the capture lane.
func _on_BallCaptureRight_rollover_entered(body):
body.queue_free()
if mode == MODE_NORMAL:
# If there isn't an event running, we'll issue a reward.
if all_events_complete():
# If we've beat all the events, start wizard mode.
start_wizard_mode()
else:
# Otherwise issue the lit reward.
$AudioStreamPlayer.play_award()
match special_lit:
1:
# Reward number 1 is to increment the bonus multiplier.
match multiplier:
1:
multiplier = 2
$DMD.show_once($DMD.DISPLAY_X2)
$X2Light.flash_on()
2:
multiplier = 4
$DMD.show_once($DMD.DISPLAY_X4)
$X2Light.switch_off()
$X4Light.flash_on()
4, 8:
multiplier = 8
$DMD.show_once($DMD.DISPLAY_X8)
$X4Light.switch_off()
$X8Light.flash_on()
$BallReleaseRightTimer.start()
change_special()
2:
# Reward number 2 is to start the lane hunt event.
mode = MODE_LANE_HUNT
lane_hunt_1 = false
lane_hunt_2 = false
lane_hunt_3 = false
lit_lane = 0
$LaneLight1.flash()
$LaneLight2.flash()
$LaneLight3.flash()
$LaneLight4.switch_off()
$LaneLight5.switch_off()
$DMD.show_sequence($DMD.LANE_HUNT_SEQ)
$SpecialLight2.flash()
$BallReleaseRightTimer.start(SLOW_RELEASE_TIME)
$CountdownTimer.start(COUNTDOWN_LEAD_TIME)
ticks = 5
3:
# Reward number 3 is to start the drop target hunt event.
mode = MODE_TARGET_HUNT
$DropTarget1.raise()
$DropTarget2.raise()
$DropTarget3.raise()
$DropTarget4.raise()
$DropTarget5.raise()
$DropTarget6.raise()
$DMD.show_sequence($DMD.TARGET_HUNT_SEQ)
$SpecialLight3.flash()
$LeftTargetLight.flash()
$RightTargetLight.flash()
$BallReleaseRightTimer.start(SLOW_RELEASE_TIME)
$CountdownTimer.start(COUNTDOWN_LEAD_TIME)
ticks = 5
else:
# If there's an event in progress, just release the ball from the capture lane.
$BallReleaseRightTimer.start(1.0)
# The following three functions react to hits against the three bumpers.
func _on_Bumper1_body_entered(body):
$Bumper1.get_node("Light").flash_once()
bump(body, $Bumper1, FORCE_BUMPER)
func _on_Bumper2_body_entered(body):
$Bumper2.get_node("Light").flash_once()
bump(body, $Bumper2, FORCE_BUMPER)
func _on_Bumper3_body_entered(body):
$Bumper3.get_node("Light").flash_once()
bump(body, $Bumper3, FORCE_BUMPER)
# The following three functions react to hits against the left drop targets.
func _on_DropTarget1_body_entered(body):
impact(body, TARGET_IMPACT_COLOR)
$DropTarget1.drop()
left_target_dropped()
func _on_DropTarget2_body_entered(body):
impact(body, TARGET_IMPACT_COLOR)
$DropTarget2.drop()
left_target_dropped()
func _on_DropTarget3_body_entered(body):
impact(body, TARGET_IMPACT_COLOR)
$DropTarget3.drop()
left_target_dropped()
# This logic is common to all drop targets on the left side.
func left_target_dropped():
if mode == MODE_TARGET_HUNT:
# If we're in the target hunt event, check if the event is complete.
check_target_hunting()
else:
# Otherwise check if the player cleared all left-side drop targets.
add_score(SCORE_DROP)
if $DropTarget1.is_down() and $DropTarget2.is_down() and $DropTarget3.is_down():
banks += 1
add_score(SCORE_DROP_ALL)
$AudioStreamPlayer.play_award()
$ResetLeftTargets.start()
$LeftTargetLight.flash_off()
$DMD.show_once($DMD.DISPLAY_TARGET_BANK_REWARD)
# When this timer expires, pop up the targets on the left side.
func _on_ResetLeftTargets_timeout():
$DropTarget1.raise()
$DropTarget2.raise()
$DropTarget3.raise()
# The following three functions react to hits against the right drop targets.
func _on_DropTarget4_body_entered(body):
impact(body, TARGET_IMPACT_COLOR)
$DropTarget4.drop()
right_target_dropped()
func _on_DropTarget5_body_entered(body):
impact(body, TARGET_IMPACT_COLOR)
$DropTarget5.drop()
right_target_dropped()
func _on_DropTarget6_body_entered(body):
impact(body, TARGET_IMPACT_COLOR)
$DropTarget6.drop()
right_target_dropped()
# This logic is common to all drop targets on the right side.
func right_target_dropped():
if mode == MODE_TARGET_HUNT:
# If we're in the target hunt event, check if the event is complete.
check_target_hunting()
else:
# Otherwise check if the player cleared all right-side drop targets.
add_score(SCORE_DROP)
if $DropTarget4.is_down() and $DropTarget5.is_down() and $DropTarget6.is_down():
banks += 1
$AudioStreamPlayer.play_award()
add_score(SCORE_DROP_ALL)
$ResetRightTargets.start()
$RightTargetLight.flash_off()
$DMD.show_once($DMD.DISPLAY_TARGET_BANK_REWARD)
# Run these effects if the player completes the drop target hunt event.
func check_target_hunting():
if $DropTarget1.is_down() and $DropTarget2.is_down() and $DropTarget3.is_down() and $DropTarget4.is_down() and $DropTarget5.is_down() and $DropTarget6.is_down():
add_score(SCORE_TARGET_HUNT)
$AudioStreamPlayer.play_award()
$DMD.set_parameter("reward", SCORE_TARGET_HUNT)
$DMD.show_once($DMD.DISPLAY_TARGET_HUNT_REWARD)
target_hunter_victory = true
$TargetHuntVictoryLight.flash_on()
$LeftTargetLight.switch_off()
$RightTargetLight.switch_off()
change_special()
mode = MODE_NORMAL
$CountdownTimer.stop()
$ResetLeftTargets.start()
$ResetRightTargets.start()
check_wizard_mode()
# When this timer expires, pop up the targets on the right side.
func _on_ResetRightTargets_timeout():
$DropTarget4.raise()
$DropTarget5.raise()
$DropTarget6.raise()
# The next two functions manage hits against the lower kickers.
func _on_LKicker_body_entered(body):
if mode == MODE_NORMAL and not all_events_complete():
change_special()
$LeftKickerLight.flash_once()
kick(body, $LKicker, FORCE_KICKER)
func _on_RKicker_body_entered(body):
if mode == MODE_NORMAL and not all_events_complete():
change_special()
$RightKickerLight.flash_once()
kick(body, $RKicker, FORCE_KICKER)
# The next five functions run when the ball passes through lanes.
func _on_Lane1Rollover_rollover_entered(body):
if mode == MODE_WIZARD:
wizard_lane(body)
elif mode == MODE_LANE_HUNT:
if not lane_hunt_1:
$LaneLight1.switch_off()
lane_hunt_1 = true
check_lane_hunt()
elif lit_lane == 1:
change_lit_lane()
else:
looped()
func _on_Lane2Rollover_rollover_entered(body):
if mode == MODE_WIZARD:
wizard_lane(body)
elif mode == MODE_LANE_HUNT:
if not lane_hunt_2:
$LaneLight2.switch_off()
lane_hunt_2 = true
check_lane_hunt()
elif lit_lane == 2:
change_lit_lane()
func _on_Lane3Rollover_rollover_entered(body):
if mode == MODE_WIZARD:
wizard_lane(body)
elif mode == MODE_LANE_HUNT:
if not lane_hunt_3:
$LaneLight3.switch_off()
lane_hunt_3 = true
check_lane_hunt()
elif lit_lane == 3:
change_lit_lane()
else:
looped()