-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrhythmgame.rpy
829 lines (808 loc) · 39 KB
/
rhythmgame.rpy
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
# Code for rhythm minigames
# General notes:
# - Assumes a screen resolution of 1920x1080.
# State of button presses.
# If this value is True when a note lands, then it was a successful hit.
default leftpressed = False
default rightpressed = False
default uppressed = False
# The amount of time before game actually starts.
# (To allow time for some intro animation for the controls)
default rhythmgame_leadin = 2.0
# Indicates if rhythm game has started yet (to show control movement).
default rhythmgame_started = False
# The amount of time a beat is visible on the screen.
# (how much time the user has to react).
default beat_leadtime = 2.0
# The amount of grace time before/after the time to hit the note.
default beat_gracetime = 0.13
# The set of on-screen beats currently displayed.
# The keys are the ids, the values are the timing (position) within the music.
default onscreen_leftbeats = dict()
default onscreen_rightbeats = dict()
default onscreen_upbeats = dict()
default onscreen_Wbeats = dict()
default onscreen_Abeats = dict()
default onscreen_Sbeats = dict()
default onscreen_Dbeats = dict()
default onscreen_Qbeats = dict()
default onscreen_Ebeats = dict()
# Note: disable arrow key mappings for the quick menu, or it spazzes out
# during the minigame.
init python:
config.keymap['focus_left'] = []
config.keymap['focus_right'] = []
config.keymap['focus_up'] = []
renpy.add_layer("rhythmgame",above="master",menu_clear=True)
# Locations of the landing pads for the notes coming from the three directions.
transform leftish:
xpos 795 ypos 845
transform rightish:
xpos 1035 ypos 845
transform upish:
xpos 915 ypos 725
# Filler circle in the middle of the landing pads.
transform centreish:
xpos 915 ypos 845
# Count number of WASD pads used (for indexing a location to use).
default wasd_count = 0
# Locations to put WASD pads (cycle through these),
default wasd_xpos = [400,800,1200,1600,1600,1200,800,400]
default wasd_ypos = [200,200,200,200,600,600,600,600]
# Factor out the starting / ending positions for beats.
default left_beat_x0 = -136
default left_beat_x1 = 772
default right_beat_x0 = 1920
default right_beat_x1 = 1012
default up_beat_y0 = -136
default up_beat_y1 = 702
default qe_beat_x0 = 200
default qe_beat_x1 = 1720
default qe_beat_y0 = -200
default qe_beat_y1 = 800
# Animation for the beats
image beat:
"beat1"
pause 0.1
"beat2"
pause 0.1
"beat3"
pause 0.1
repeat
image wpad:
"w1"
pause 0.1
"w2"
pause 0.1
"w3"
pause 0.1
repeat
image apad:
"a1"
pause 0.1
"a2"
pause 0.1
"a3"
pause 0.1
repeat
image spad:
"s1"
pause 0.1
"s2"
pause 0.1
"s3"
pause 0.1
repeat
image dpad:
"d1"
pause 0.1
"d2"
pause 0.1
"d3"
pause 0.1
repeat
image wasd_ring:
"ring1"
pause 0.1
"ring2"
pause 0.1
"ring3"
pause 0.1
repeat
image chevron:
"chevron1"
pause 0.1
"chevron2"
pause 0.1
"chevron3"
pause 0.1
repeat
image chevron_q:
"chevronq"
image chevron_e:
"chevrone"
# Locations to draw the beats
transform reallyleft:
xpos left_beat_x0 ypos 822
linear beat_leadtime xpos left_beat_x1
transform reallyright:
xpos right_beat_x0 ypos 822
linear beat_leadtime xpos right_beat_x1
transform reallyup:
xpos 892 ypos up_beat_y0
linear beat_leadtime ypos up_beat_y1
# Sliding centre circle around a bit to show the selected direction better.
transform slide_left:
easein 0.15 xanchor 0.5
transform slide_right:
easein 0.15 xanchor -0.5
transform slide_up:
easein 0.15 yanchor 0.5
transform slide_back:
easein 0.15 xanchor 0.0 yanchor 0.0
# Circle closing in on WASD pads
transform closing_in:
alpha 1.0 zoom 5.0
linear beat_leadtime zoom 1.0
# Chevrons coming down
transform reallyup_q:
xpos qe_beat_x0 ypos qe_beat_y0
xanchor 0.5 yanchor 0.5
linear beat_leadtime ypos qe_beat_y1
transform reallyup_e:
xpos qe_beat_x1 ypos qe_beat_y0
xanchor 0.5 yanchor 0.5
linear beat_leadtime ypos qe_beat_y1
# Fading out for hits / misses
transform briefly:
easeout 0.1 zoom 2.0 alpha 0.0
default file_prefix = None # Directory and file prefix for rhythm game files, needed for recording mode.
default rhythmfile = None # For saving beat patterns (in "record" mode)
default lyricfile = None # For saving lyric display times (in "lyric" mode)
default rhythms = None # List of beat timings (loaded from rhythm file)
default lyric_infile = None # For reading each line of lyrics (in "lyric" mode)
screen rhythmgame(name,mode="play"):
layer "rhythmgame"
#modal True
# Most of the rhythmgame is rendered dynamically with Python functions.
python:
# Set up the screen
def start(name,mode):
# Seed the random number generator to make it deterministic.
renpy.random.seed(0)
# Turn off quick menu at bottom, it's too distracting!
global quick_menu
quick_menu = False
renpy.restart_interaction()
# Animation for introducing the centre circle
def show_centrecircle():
renpy.show("centrecircle",layer="rhythmgame",at_list=[centreish],tag="centrecircle")
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=892+68,ypos=822+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Animation for introducing the left landing pad
def show_leftcircle():
renpy.show("smallcircle1",layer="rhythmgame",at_list=[leftish],tag="leftcircle")
xpos = left_beat_x1
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=xpos+68,ypos=822+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Animation for introducing the up landing pad
def show_upcircle():
renpy.show("smallcircle3",layer="rhythmgame",at_list=[upish],tag="upcircle")
ypos = up_beat_y1
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=892+68,ypos=ypos+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Animation for introducing the right landing pad
def show_rightcircle():
renpy.show("smallcircle2",layer="rhythmgame",at_list=[rightish],tag="rightcircle")
xpos = right_beat_x1
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=xpos+68,ypos=822+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Start playing the song
def start_music(name,mode):
global rhythmgame_started, file_prefix
# Get the path and prefix for the rhythm files for recording.
# This is done by opening a known file, and querying for its location.
file_prefix = renpy.open_file("audio/"+name+".mp3").name[:-4]
# Open rhythm file for recording?
# Use .tmp extension to avoid overwriting any existing file (for now)
if mode == "record":
global rhythmfile
rhythmfile = open(file_prefix+".rhythm.txt.tmp",'wt')
if mode == "lyrics":
global lyricfile, lyric_infile
lyric_infile = renpy.open_file("audio/"+name+".lyrics.txt")
lyricfile = open(file_prefix+".lyrics-cue.txt.tmp",'wt')
# Start the music
renpy.music.play(name+".mp3",loop=False)
rhythmgame_started = True # Can animate button presses now.
# Handle left button press
def pressleft(mode=None):
global rhythmgame_started, leftpressed
if not rhythmgame_started: return
leftpressed = True
pos = renpy.music.get_pos() or 0.0
if mode == "record":
rhythmfile.write("%s left\n"%pos)
renpy.show("bigcircle",layer="rhythmgame",at_list=[leftish],tag="leftbigcircle")
renpy.show("centrecircle",layer="rhythmgame",at_list=[slide_left])
# Check if a beat was hit
for beat_id, final_pos in list(onscreen_leftbeats.items()):
if pos + beat_gracetime >= final_pos and pos - beat_gracetime <= final_pos:
renpy.hide("leftbeat%03d"%beat_id,layer="rhythmgame")
del onscreen_leftbeats[beat_id]
# Compute the position of the beat when it was hit.
xpos = int(left_beat_x1 - (left_beat_x1-left_beat_x0)*(final_pos-pos)/beat_leadtime)
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=xpos+68,ypos=822+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def unpressleft():
global leftpressed
if not rhythmgame_started: return
leftpressed = False
renpy.hide("leftbigcircle",layer="rhythmgame")
renpy.restart_interaction()
renpy.show("centrecircle",layer="rhythmgame",at_list=[slide_back])
# Handle right button press
def pressright(mode=None):
global rhythmgame_started, rightpressed
if not rhythmgame_started: return
rightpressed = True
pos = renpy.music.get_pos() or 0.0
if mode == "record":
rhythmfile.write("%s right\n"%renpy.music.get_pos())
renpy.show("bigcircle",layer="rhythmgame",at_list=[rightish],tag="rightbigcircle")
renpy.show("centrecircle",layer="rhythmgame",at_list=[slide_right])
# Check if a beat was hit
for beat_id, final_pos in list(onscreen_rightbeats.items()):
if pos + beat_gracetime >= final_pos and pos - beat_gracetime <= final_pos:
renpy.hide("rightbeat%03d"%beat_id,layer="rhythmgame")
del onscreen_rightbeats[beat_id]
# Compute the position of the beat when it was hit.
xpos = int(right_beat_x1 - (right_beat_x1-right_beat_x0)*(final_pos-pos)/beat_leadtime)
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=xpos+68,ypos=822+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def unpressright():
global rhythmgame_started, rightpressed
if not rhythmgame_started: return
rightpressed = False
renpy.hide("rightbigcircle",layer="rhythmgame")
renpy.restart_interaction()
renpy.show("centrecircle",layer="rhythmgame",at_list=[slide_back])
# Handle up button press
def pressup(mode=None):
global rhythmgame_started, uppressed
if not rhythmgame_started: return
uppressed = True
pos = renpy.music.get_pos() or 0.0
if mode == "record":
rhythmfile.write("%s up\n"%renpy.music.get_pos())
renpy.show("bigcircle",layer="rhythmgame",at_list=[upish],tag="upbigcircle")
renpy.show("centrecircle",layer="rhythmgame",at_list=[slide_up])
# Check if a beat was hit
for beat_id, final_pos in list(onscreen_upbeats.items()):
if pos + beat_gracetime >= final_pos and pos - beat_gracetime <= final_pos:
renpy.hide("upbeat%03d"%beat_id,layer="rhythmgame")
del onscreen_upbeats[beat_id]
# Compute the position of the beat when it was hit.
ypos = int(up_beat_y1 - (up_beat_y1-up_beat_y0)*(final_pos-pos)/beat_leadtime)
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=892+68,ypos=ypos+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def unpressup():
global rhythmgame_started, uppressed
if not rhythmgame_started: return
uppressed = False
renpy.hide("upbigcircle",layer="rhythmgame")
renpy.restart_interaction()
renpy.show("centrecircle",layer="rhythmgame",at_list=[slide_back])
# Handle W button press
def pressW(mode=None):
pos = renpy.music.get_pos() or 0.0
if mode == "record":
rhythmfile.write("%s W\n"%pos)
# Check if a beat was hit
for beat_id, (final_pos, xpos, ypos) in list(onscreen_Wbeats.items()):
if pos + beat_gracetime >= final_pos and pos - beat_gracetime <= final_pos:
renpy.hide("wpad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ring%03d"%beat_id,layer="rhythmgame")
del onscreen_Wbeats[beat_id]
renpy.hide("hit_pad",layer="rhythmgame")
renpy.show("hit",tag="hit_pad",layer="rhythmgame",at_list=[Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Handle A button press
def pressA(mode=None):
pos = renpy.music.get_pos() or 0.0
if mode == "record":
rhythmfile.write("%s A\n"%pos)
# Check if a beat was hit
for beat_id, (final_pos, xpos, ypos) in list(onscreen_Abeats.items()):
if pos + beat_gracetime >= final_pos and pos - beat_gracetime <= final_pos:
renpy.hide("apad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ring%03d"%beat_id,layer="rhythmgame")
del onscreen_Abeats[beat_id]
renpy.hide("hit_pad",layer="rhythmgame")
renpy.show("hit",tag="hit_pad",layer="rhythmgame",at_list=[Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Handle S button press
def pressS(mode=None):
pos = renpy.music.get_pos() or 0.0
if mode == "record":
rhythmfile.write("%s S\n"%pos)
# Check if a beat was hit
for beat_id, (final_pos, xpos, ypos) in list(onscreen_Sbeats.items()):
if pos + beat_gracetime >= final_pos and pos - beat_gracetime <= final_pos:
renpy.hide("spad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ring%03d"%beat_id,layer="rhythmgame")
del onscreen_Sbeats[beat_id]
renpy.hide("hit_pad",layer="rhythmgame")
renpy.show("hit",tag="hit_pad",layer="rhythmgame",at_list=[Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Handle D button press
def pressD(mode=None):
pos = renpy.music.get_pos() or 0.0
if mode == "record":
rhythmfile.write("%s D\n"%pos)
# Check if a beat was hit
for beat_id, (final_pos, xpos, ypos) in list(onscreen_Dbeats.items()):
if pos + beat_gracetime >= final_pos and pos - beat_gracetime <= final_pos:
renpy.hide("dpad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ring%03d"%beat_id,layer="rhythmgame")
del onscreen_Dbeats[beat_id]
renpy.hide("hit_pad",layer="rhythmgame")
renpy.show("hit",tag="hit_pad",layer="rhythmgame",at_list=[Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Handle Q button press
def pressQ(mode=None):
pos = renpy.music.get_pos() or 0.0
if mode == "record":
rhythmfile.write("%s QE\n"%pos)
# Check if a beat was hit
for beat_id, final_pos in list(onscreen_Qbeats.items()):
if pos + beat_gracetime >= final_pos and pos - beat_gracetime <= final_pos:
renpy.hide("qpad%03d"%beat_id,layer="rhythmgame")
renpy.hide("qkey%03d"%beat_id,layer="rhythmgame")
renpy.hide("qbeat%03d"%beat_id,layer="rhythmgame")
del onscreen_Qbeats[beat_id]
# Compute the position of the beat when it was hit.
ypos = int(qe_beat_y1 - (qe_beat_y1-qe_beat_y0)*(final_pos-pos)/beat_leadtime)
renpy.hide("hit_q",layer="rhythmgame")
renpy.show("hit",tag="hit_q",layer="rhythmgame",at_list=[Transform(xpos=qe_beat_x0,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Handle E button press
def pressE(mode=None):
pos = renpy.music.get_pos() or 0.0
# Check if a beat was hit
for beat_id, final_pos in list(onscreen_Ebeats.items()):
if pos + beat_gracetime >= final_pos and pos - beat_gracetime <= final_pos:
renpy.hide("epad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ekey%03d"%beat_id,layer="rhythmgame")
renpy.hide("ebeat%03d"%beat_id,layer="rhythmgame")
del onscreen_Ebeats[beat_id]
# Compute the position of the beat when it was hit.
ypos = int(qe_beat_y1 - (qe_beat_y1-qe_beat_y0)*(final_pos-pos)/beat_leadtime)
renpy.hide("hit_e",layer="rhythmgame")
renpy.show("hit",tag="hit_e",layer="rhythmgame",at_list=[Transform(xpos=qe_beat_x1,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Handle progressing through lyrics (for recording their timing.)
def pressN():
global lyricfile, lyric_infile
pos = renpy.music.get_pos() or 0.0
line = lyric_infile.readline().strip().decode()
lyricfile.write("%s %s\n"%(pos,line))
s = renpy.get_screen('rhythmgame')
lyrics = renpy.get_widget(s,id='lyrics')
lyrics.set_text(line)
renpy.restart_interaction()
# Dummy function (do nothing)
def donothing():
pass
# Get all beats
def get_beats(name,mode):
global rhythmgame_leadin, rhythms
if mode != "play": return []
# Open rhythm file?
if rhythms is None:
_rhythms = []
beat_id = 1
with renpy.open_file("audio/"+name+".rhythm.txt") as f:
for line in f:
pos, direction = line.strip().split()
pos = float(pos)
direction = direction.decode()
_rhythms.append ((beat_id, pos+rhythmgame_leadin, direction))
beat_id += 1
rhythms = _rhythms
for beat_id, pos, direction in rhythms:
yield (beat_id, pos, direction)
# Get all lyrics and timings
def get_lyrics(name,mode):
global rhythmgame_leadin
if mode != "play": return []
try:
with renpy.open_file("audio/"+name+".lyrics-cue.txt") as f:
for line in f:
try:
pos, lyric = line.strip().split(maxsplit=1)
except ValueError:
return # No more useable lines?
pos = float(pos)
lyric = lyric.decode()
yield (pos+rhythmgame_leadin, lyric)
except OSError:
return # No lyrics available
# Routines for drawing beats on the screen when it's time for them to
# be visible.
def draw_left_beat(beat_id,final_pos):
global rhythmgame_leadin
renpy.show("beat",layer="rhythmgame",at_list=[reallyleft],tag="leftbeat%03d"%beat_id)
onscreen_leftbeats[beat_id] = final_pos - rhythmgame_leadin
renpy.restart_interaction()
def draw_right_beat(beat_id,final_pos):
global rhythmgame_leadin
renpy.show("beat",layer="rhythmgame",at_list=[reallyright],tag="rightbeat%03d"%beat_id)
onscreen_rightbeats[beat_id] = final_pos - rhythmgame_leadin
renpy.restart_interaction()
def draw_up_beat(beat_id,final_pos):
global rhythmgame_leadin
renpy.show("beat",layer="rhythmgame",at_list=[reallyup],tag="upbeat%03d"%beat_id)
onscreen_upbeats[beat_id] = final_pos - rhythmgame_leadin
renpy.restart_interaction()
def draw_W_pad(beat_id,final_pos):
# Find somewhere to draw the pad.
global wasd_count, rhythmgame_leadin
i = wasd_count % len(wasd_xpos)
xpos = wasd_xpos[i] + renpy.random.randint(-100,100)
ypos = wasd_ypos[i] + renpy.random.randint(-100,100)
wasd_count += 1
location = Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5)
renpy.show("wpad",layer="rhythmgame",at_list=[location],tag="wpad%03d"%beat_id)
renpy.show("wasd_ring",layer="rhythmgame",at_list=[location,closing_in],tag="ring%03d"%beat_id)
onscreen_Wbeats[beat_id] = (final_pos-rhythmgame_leadin,xpos,ypos)
renpy.restart_interaction()
def draw_A_pad(beat_id,final_pos):
# Find somewhere to draw the pad.
global wasd_count, rhythmgame_leadin
i = wasd_count % len(wasd_xpos)
xpos = wasd_xpos[i] + renpy.random.randint(-100,100)
ypos = wasd_ypos[i] + renpy.random.randint(-100,100)
wasd_count += 1
location = Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5)
renpy.show("apad",layer="rhythmgame",at_list=[location],tag="apad%03d"%beat_id)
renpy.show("wasd_ring",layer="rhythmgame",at_list=[location,closing_in],tag="ring%03d"%beat_id)
onscreen_Abeats[beat_id] = (final_pos-rhythmgame_leadin,xpos,ypos)
renpy.restart_interaction()
def draw_S_pad(beat_id,final_pos):
# Find somewhere to draw the pad.
global wasd_count, rhythmgame_leadin
i = wasd_count % len(wasd_xpos)
xpos = wasd_xpos[i] + renpy.random.randint(-100,100)
ypos = wasd_ypos[i] + renpy.random.randint(-100,100)
wasd_count += 1
location = Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5)
renpy.show("spad",layer="rhythmgame",at_list=[location],tag="spad%03d"%beat_id)
renpy.show("wasd_ring",layer="rhythmgame",at_list=[location,closing_in],tag="ring%03d"%beat_id)
onscreen_Sbeats[beat_id] = (final_pos-rhythmgame_leadin,xpos,ypos)
renpy.restart_interaction()
def draw_D_pad(beat_id,final_pos):
# Find somewhere to draw the pad.
global wasd_count, rhythmgame_leadin
i = wasd_count % len(wasd_xpos)
xpos = wasd_xpos[i] + renpy.random.randint(-100,100)
ypos = wasd_ypos[i] + renpy.random.randint(-100,100)
wasd_count += 1
location = Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5)
renpy.show("dpad",layer="rhythmgame",at_list=[location],tag="dpad%03d"%beat_id)
renpy.show("wasd_ring",layer="rhythmgame",at_list=[location,closing_in],tag="ring%03d"%beat_id)
onscreen_Dbeats[beat_id] = (final_pos-rhythmgame_leadin,xpos,ypos)
renpy.restart_interaction()
def draw_Q_beat(beat_id,final_pos):
global rhythmgame_leadin
renpy.show("chevron",layer="rhythmgame",at_list=[reallyup_q],tag="qbeat%03d"%beat_id)
xpos = qe_beat_x0
ypos = qe_beat_y1
renpy.show("chevron",layer="rhythmgame",at_list=[Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5)],tag="qpad%03d"%beat_id)
renpy.show("chevron_q",layer="rhythmgame",at_list=[Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5)],tag="qkey%03d"%beat_id)
onscreen_Qbeats[beat_id] = final_pos - rhythmgame_leadin
renpy.restart_interaction()
def draw_E_beat(beat_id,final_pos):
global rhythmgame_leadin
renpy.show("chevron",layer="rhythmgame",at_list=[reallyup_e],tag="ebeat%03d"%beat_id)
xpos = qe_beat_x1
ypos = qe_beat_y1
renpy.show("chevron",layer="rhythmgame",at_list=[Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5)],tag="epad%03d"%beat_id)
renpy.show("chevron_e",layer="rhythmgame",at_list=[Transform(xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5)],tag="ekey%03d"%beat_id)
onscreen_Ebeats[beat_id] = final_pos - rhythmgame_leadin
renpy.restart_interaction()
# Routines for checking if a beat is running into an already-activated
# pad.
def check_left_collision(beat_id):
if not leftpressed: return
final_pos = onscreen_leftbeats.pop(beat_id,None)
if final_pos is None: return #???
renpy.hide("leftbeat%03d"%beat_id,layer="rhythmgame")
# Compute the position of the beat when it was hit.
xpos = int(left_beat_x1 - (left_beat_x1-left_beat_x0)*beat_gracetime/beat_leadtime)
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=xpos+68,ypos=822+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def check_right_collision(beat_id):
if not rightpressed: return
final_pos = onscreen_rightbeats.pop(beat_id,None)
if final_pos is None: return #???
renpy.hide("rightbeat%03d"%beat_id,layer="rhythmgame")
# Compute the position of the beat when it was hit.
xpos = int(right_beat_x1 - (right_beat_x1-right_beat_x0)*beat_gracetime/beat_leadtime)
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=xpos+68,ypos=822+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def check_up_collision(beat_id):
if not uppressed: return
final_pos = onscreen_upbeats.pop(beat_id,None)
if final_pos is None: return #???
renpy.hide("upbeat%03d"%beat_id,layer="rhythmgame")
# Compute the position of the beat when it was hit.
ypos = int(up_beat_y1 - (up_beat_y1-up_beat_y0)*beat_gracetime/beat_leadtime)
renpy.hide("hit",layer="rhythmgame")
renpy.show("hit",layer="rhythmgame",at_list=[Transform(xpos=892+68,ypos=ypos+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Routines for handling beat misses
def miss_left(beat_id):
if onscreen_leftbeats.pop(beat_id,None) is None: return
renpy.hide("leftbeat%03d"%beat_id,layer="rhythmgame")
xpos = left_beat_x1
renpy.hide("miss",layer="rhythmgame")
renpy.show("miss",layer="rhythmgame",at_list=[Transform(alpha=0.5,xpos=xpos+68,ypos=822+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def miss_right(beat_id):
if onscreen_rightbeats.pop(beat_id,None) is None: return
renpy.hide("rightbeat%03d"%beat_id,layer="rhythmgame")
xpos = right_beat_x1
renpy.hide("miss",layer="rhythmgame")
renpy.show("miss",layer="rhythmgame",at_list=[Transform(alpha=0.5,xpos=xpos+68,ypos=822+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def miss_up(beat_id):
if onscreen_upbeats.pop(beat_id,None) is None: return
renpy.hide("upbeat%03d"%beat_id,layer="rhythmgame")
ypos = up_beat_y1
renpy.hide("miss",layer="rhythmgame")
renpy.show("miss",layer="rhythmgame",at_list=[Transform(alpha=0.5,xpos=892+68,ypos=ypos+68,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def miss_W(beat_id):
beat_info = onscreen_Wbeats.pop(beat_id,None)
if beat_info is None: return
_, xpos, ypos = beat_info
renpy.hide("wpad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ring%03d"%beat_id,layer="rhythmgame")
renpy.hide("miss_pad",layer="rhythmgame")
renpy.show("miss",tag="miss_pad",layer="rhythmgame",at_list=[Transform(alpha=0.5,xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def miss_A(beat_id):
beat_info = onscreen_Abeats.pop(beat_id,None)
if beat_info is None: return
_, xpos, ypos = beat_info
renpy.hide("apad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ring%03d"%beat_id,layer="rhythmgame")
renpy.hide("miss_pad",layer="rhythmgame")
renpy.show("miss",tag="miss_pad",layer="rhythmgame",at_list=[Transform(alpha=0.5,xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def miss_S(beat_id):
beat_info = onscreen_Sbeats.pop(beat_id,None)
if beat_info is None: return
_, xpos, ypos = beat_info
renpy.hide("spad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ring%03d"%beat_id,layer="rhythmgame")
renpy.hide("miss_pad",layer="rhythmgame")
renpy.show("miss",tag="miss_pad",layer="rhythmgame",at_list=[Transform(alpha=0.5,xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def miss_D(beat_id):
beat_info = onscreen_Dbeats.pop(beat_id,None)
if beat_info is None: return
_, xpos, ypos = beat_info
renpy.hide("dpad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ring%03d"%beat_id,layer="rhythmgame")
renpy.hide("miss_pad",layer="rhythmgame")
renpy.show("miss",tag="miss_pad",layer="rhythmgame",at_list=[Transform(alpha=0.5,xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def miss_Q(beat_id):
if onscreen_Qbeats.pop(beat_id,None) is None: return
renpy.hide("qpad%03d"%beat_id,layer="rhythmgame")
renpy.hide("qkey%03d"%beat_id,layer="rhythmgame")
renpy.hide("qbeat%03d"%beat_id,layer="rhythmgame")
xpos = qe_beat_x0
ypos = qe_beat_y1
renpy.hide("miss_q",layer="rhythmgame")
renpy.show("miss",tag="miss_q",layer="rhythmgame",at_list=[Transform(alpha=0.5,xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
def miss_E(beat_id):
if onscreen_Ebeats.pop(beat_id,None) is None: return
renpy.hide("epad%03d"%beat_id,layer="rhythmgame")
renpy.hide("ekey%03d"%beat_id,layer="rhythmgame")
renpy.hide("ebeat%03d"%beat_id,layer="rhythmgame")
xpos = qe_beat_x1
ypos = qe_beat_y1
renpy.hide("miss_e",layer="rhythmgame")
renpy.show("miss",tag="miss_e",layer="rhythmgame",at_list=[Transform(alpha=0.5,xpos=xpos,ypos=ypos,xanchor=0.5,yanchor=0.5),briefly])
renpy.restart_interaction()
# Update lyrics at the bottom of the screen.
def lyric (line):
s = renpy.get_screen('rhythmgame')
lyrics = renpy.get_widget(s,id='lyrics')
lyrics.set_text(line)
# Near end of minigame (saving files)
def finalize_recording(mode,finish):
global rhythmfile, lyricfile
s = renpy.get_screen('rhythmgame')
v = renpy.get_widget(s,id='promptbox')
if mode == "record":
rhythmfile.close()
bakfile = file_prefix + ".rhythm.txt.bak"
outfile = file_prefix + ".rhythm.txt"
tmpfile = file_prefix + ".rhythm.txt.tmp"
elif mode == "lyrics":
lyricfile.close()
bakfile = file_prefix + ".lyrics-cue.txt.bak"
outfile = file_prefix + ".lyrics-cue.txt"
tmpfile = file_prefix + ".lyrics-cue.txt.tmp"
def overwrite (bakfile, outfile, tmpfile):
# Make a backup copy of the old recording, just in case.
bak = open(bakfile,'wt')
out = open(outfile, 'rt')
for line in out:
bak.write(line)
bak.close()
out.close()
# Save copy of new recording.
out = open(outfile,'wt')
tmp = open(tmpfile,'rt')
for line in tmp:
out.write(line)
out.close()
tmp.close()
# Check if output file already exists.
# If it does, them prompt for overwriting.
try:
out = open(outfile, 'rt')
out.close()
v.add(Text("A previous recording has already been made. Overwrite?", textalign=0.5, outlines=[(5,"000000",0,0)]))
v.add(TextButton("Yes",xalign=0.5, text_size=50, text_outlines=[(5,"000000",0,0)], action=[Function(overwrite,bakfile,outfile,tmpfile),Function(finish,mode)]))
v.add(TextButton("No",xalign=0.5, text_size=50, text_outlines=[(5,"000000",0,0)], action=Function(finish,mode)))
renpy.restart_interaction()
except OSError: # File does not exist, nothing will be overwritten.
out = open(outfile,'wt')
tmp = open(tmpfile,'rt')
for line in tmp:
out.write(line)
out.close()
tmp.close()
finish(mode)
# End of minigame (cleanup)
def finish(mode):
# Turn on quick menu at bottom
global quick_menu
quick_menu = True
# Rest state of button presses, so they start unpressed for the
# next rhythmgame after this one.
leftpressed = False
rightpressed = False
uppressed = False
# Stop any music that's playing
renpy.music.stop()
# Blank out rhythm and lyrics files.
if mode == "record":
global rhythmfile
rhythmfile = None
if mode == "lyrics":
global lyricfile
lyricfile = None
# No more onscreen beats.
global onscreen_leftbeats, onscreen_rightbeats, onscreen_upbeats
global onscreen_Wbeats, onscreen_Abeats, onscreen_Sbeats, onscreen_Dbeats
global wasd_count
onscreen_leftbeats = dict()
onscreen_rightbeats = dict()
onscreen_upbeats = dict()
onscreen_Abeats = dict()
onscreen_Sbeats = dict()
onscreen_Dbeats = dict()
onscreen_Qbeats = dict()
onscreen_Ebeats = dict()
wasd_count = 0
global rhythmgame_started, rhythms
rhythmgame_started = False
rhythms = None
# Clear the rhythmgame screen from display.
ui.layer("rhythmgame")
ui.clear()
ui.close()
# Bind arrow keys to the landing pads.
key "keydown_K_LEFT" action Function(pressleft,mode)
key "keyup_K_LEFT" action unpressleft
key "keydown_K_RIGHT" action Function(pressright,mode)
key "keyup_K_RIGHT" action unpressright
key "keydown_K_UP" action Function(pressup,mode)
key "keyup_K_UP" action unpressup
# Bind WASD keys as well.
key "K_w" action Function(pressW,mode)
key "K_a" action Function(pressA,mode)
key "K_s" action Function(pressS,mode)
key "K_d" action Function(pressD,mode)
# Bind Q and E keys for those chevron things
key "K_q" action Function(pressQ,mode)
key "K_e" action Function(pressE,mode)
# Bind "N" key for next lyric line.
if mode == "lyrics":
key "K_n" action Function(pressN)
# Disable menu during minigame (the beats won't pause!)
key "game_menu" action donothing
# Add a text widget for showing the lyrics.
frame:
background None
xsize 1.0
yanchor 0.5 ypos 1000
hbox:
xalign 0.5
# Text will be dynamically updated during rhythmgame.
text "" textalign 0.5 line_spacing 10 outlines [(5,"000000",0,0)] id "lyrics"
# Add a text widget and buttons for getting user input about saving files.
frame:
background None
xsize 1.0
yanchor 0.5 ypos 0.2
hbox:
xalign 0.5
vbox:
spacing 50
id "promptbox"
# Call the startup routine once for this screen.
on "show" action Function(start,name,mode)
# Show the pads.
timer 1.0 action Function(show_centrecircle)
timer 1.6 action Function(show_leftcircle)
timer 1.8 action Function(show_upcircle)
timer 2.0 action Function(show_rightcircle)
timer rhythmgame_leadin action Function(start_music,name,mode)
# Queue up the beats.
for beat_id, pos, direction in get_beats(name,mode):
if direction == "left":
timer pos-beat_leadtime action Function(draw_left_beat,beat_id,pos)
timer pos-beat_gracetime action Function(check_left_collision,beat_id)
timer pos+beat_gracetime action Function(miss_left,beat_id)
if direction == "right":
timer pos-beat_leadtime action Function(draw_right_beat,beat_id,pos)
timer pos-beat_gracetime action Function(check_right_collision,beat_id)
timer pos+beat_gracetime action Function(miss_right,beat_id)
if direction == "up":
timer pos-beat_leadtime action Function(draw_up_beat,beat_id,pos)
timer pos-beat_gracetime action Function(check_up_collision,beat_id)
timer pos+beat_gracetime action Function(miss_up,beat_id)
if direction == "W":
timer pos-beat_leadtime action Function(draw_W_pad,beat_id,pos)
timer pos+beat_gracetime action Function(miss_W,beat_id)
if direction == "A":
timer pos-beat_leadtime action Function(draw_A_pad,beat_id,pos)
timer pos+beat_gracetime action Function(miss_A,beat_id)
if direction == "S":
timer pos-beat_leadtime action Function(draw_S_pad,beat_id,pos)
timer pos+beat_gracetime action Function(miss_S,beat_id)
if direction == "D":
timer pos-beat_leadtime action Function(draw_D_pad,beat_id,pos)
timer pos+beat_gracetime action Function(miss_D,beat_id)
if direction == "QE":
timer pos-beat_leadtime action Function(draw_Q_beat,beat_id,pos)
timer pos-beat_leadtime action Function(draw_E_beat,beat_id,pos)
timer pos+beat_gracetime action Function(miss_Q,beat_id)
timer pos+beat_gracetime action Function(miss_E,beat_id)
# Clean up close rhythmgame after the last beats are done.
if mode == "play":
timer pos+2.0 action [Function(finish,mode),Return()]
# Allow termination of rhything / lyrics recording with space bar.
else:
key "K_SPACE" action [Function(finalize_recording,mode,finish),Return()]
# Queue up the lyrics.
for pos, line in get_lyrics(name,mode):
timer pos action Function(lyric,line)