Widen centre drain gap; calm the music down

Gameplay (you should now be able to lose balls):
- flipper length 170 -> 154, so the rest-position tips meet with a ~50px
  gap instead of ~18px - balls dropping down the middle now drain freely
- keep the outlane guard posts so side drains stay fair (all drains now
  happen through the widened centre), and verify with autoplay: centre
  drains = 40, side = 0, ~10s average ball life for the bot

Audio (was a harsh machine-gun):
- completely rewrote both music loops: no more square waves or noise
  hats in the music; sparse triangle bass + soft melody with rests, at
  lower volume (play loop now ~47% audible windows, was a solid wall)
- softened the wall-hit thud (frequent during rallies) and the charge
  ticks
This commit is contained in:
georgios
2026-09-09 16:51:56 +02:00
parent 973dd870fd
commit 996918ff8c
15 changed files with 73 additions and 45 deletions
+63 -36
View File
@@ -113,9 +113,9 @@ class Synth:
# ---- all effects -----------------------------------------------------
def _build_all(self):
self._snd("flipL", self.tone(180, 0.07, 0.5, "square", slide=0.7))
self._snd("flipR", self.tone(210, 0.07, 0.5, "square", slide=0.7))
self._snd("wall", self.tone(90, 0.045, 0.18, "square", duty=0.3))
self._snd("flipL", self.tone(180, 0.07, 0.4, "square", slide=0.7))
self._snd("flipR", self.tone(210, 0.07, 0.4, "square", slide=0.7))
self._snd("wall", self.tone(140, 0.05, 0.09, "tri"))
self._snd("launch", self._mix(
self.noise(0.28, 0.5, lp=0.25),
self.tone(160, 0.3, 0.35, "saw", slide=1.9)))
@@ -162,43 +162,70 @@ class Synth:
self._build_music()
def _build_music(self):
"""Two short generative loops: a dreamy menu loop and a bouncy play loop."""
# menu loop: soft arpeggio C - Am - F - G
chords = [["C", "E", "G"], ["A", "C", "E"], ["F", "A", "C"], ["G", "B", "D"]]
bass = [("C", 2), ("A", 2), ("F", 2), ("G", 2)]
beat = 0.26
parts = []
for ci in range(4):
n = int(SR * beat * 2)
parts.append(self.tone(freq(bass[ci][0], bass[ci][1]), beat * 2.1, 0.22, "tri"))
# melodic ripple over the chord
for k in range(4):
note = chords[ci][k % 3]
f0 = freq(note, 4 if k < 2 else 5)
parts.append(self.tone(f0, beat * 0.8, 0.14, "square", duty=0.4))
parts.append(array.array("h", [0]) * int(SR * beat * 0.2))
self._menu_music = self._mix(*parts)
# ------------------------------------------------------------------ music
def _music_buffer(self, tracks, total_s):
"""Render time-placed notes (start_s, note, octave, dur_s, vol, shape)
into one softly-mixed, normalized buffer."""
n = int(SR * total_s)
buf = [0] * n
for (t0, nm, oc, dur, vol, shape) in tracks:
samples = self.tone(freq(nm, oc), dur, vol, shape)
off = int(SR * t0)
for i, v in enumerate(samples):
j = off + i
if j < n:
buf[j] = max(-32767, min(32767, buf[j] + v))
peak = max(1, max(abs(v) for v in buf))
sc = 28000.0 / peak if peak > 28000 else 1.0
return array.array("h", (int(v * sc) for v in buf))
# play loop: bouncy 8th-note line C-C-G-G-A-A-G
line = [("C", 4), ("C", 4), ("G", 4), ("G", 4), ("A", 4), ("A", 4), ("G", 4), ("E", 4)]
bassp = [("C", 2), ("C", 2), ("G", 2), ("G", 2), ("A", 2), ("A", 2), ("E", 2), ("E", 2)]
step = 0.16
parts = []
def _build_music(self):
"""Two short generative loops, deliberately sparse & soft: a calm menu
loop and a gentle bouncy play loop. (Square waves and hats are used in
SFX only - never in the music - to keep it from getting harsh.)"""
# ---- menu: dreamy, mostly rests, C - Am - F - G ------------------------
seq = [
(("C", 2), ["C", "E", "G", "D"], "E"),
(("A", 2), ["A", "C", "E", "B"], "C"),
(("F", 2), ["F", "A", "C", "G"], "A"),
(("G", 2), ["G", "B", "D", "A"], "B"),
]
tracks = []
CH = 1.8
for ci, (bass, arp, twinkle) in enumerate(seq):
t = ci * CH
tracks.append((t, bass[0], bass[1], CH * 0.72, 0.12, "tri")) # bass
for k in range(4): # arpeggio
oc = 4 if k < 2 else 5
tracks.append((t + 0.35 + k * 0.26, arp[k], oc, 0.24, 0.08, "tri"))
tracks.append((t + 1.3, twinkle, 5, 0.55, 0.045, "tri")) # twinkle
menu_total = 4 * CH + 0.8
self._menu_music = self._music_buffer(tracks, menu_total)
# ---- play: bouncy but gentle, 16 eighth-notes @ ~0.30s ----------------
step = 0.30
bass_seq = [("C", 2), ("C", 2), ("G", 2), ("G", 2),
("A", 2), ("A", 2), ("F", 2), ("G", 2),
("C", 2), ("C", 2), ("G", 2), ("G", 2),
("A", 2), ("A", 2), ("G", 2), ("C", 2)]
lead_seq = [None, None, ("E", 4), None, ("G", 4), None, ("E", 4), None,
("D", 4), None, ("F", 4), None, ("A", 4), None, ("G", 4), None]
tracks = []
for i in range(16):
nm, oc = line[i % 8]
bn, bo = bassp[i % 8]
parts.append(self.tone(freq(bn, bo), step * 1.8, 0.28, "tri"))
parts.append(self.tone(freq(nm, oc), step * 1.3, 0.18, "square", duty=0.4))
if i % 2 == 1:
parts.append(self.noise(0.03, 0.10, lp=0.15))
else:
parts.append(array.array("h", [0]) * int(SR * step * 0.3))
self._play_music = self._mix(*parts)
t = i * step
if i % 2 == 0: # bass on the beat
bn, bo = bass_seq[i]
tracks.append((t, bn, bo, step * 1.25, 0.15, "tri"))
if lead_seq[i]: # light melody
nm, oc = lead_seq[i]
tracks.append((t + 0.02, nm, oc, step * 0.85, 0.085, "tri"))
play_total = 16 * step + 1.2
self._play_music = self._music_buffer(tracks, play_total)
self._menu = pygame.mixer.Sound(buffer=self._menu_music.tobytes())
self._play = pygame.mixer.Sound(buffer=self._play_music.tobytes())
self._menu.set_volume(0.5)
self._play.set_volume(0.45)
self._menu.set_volume(0.40)
self._play.set_volume(0.30)
# ---- playback --------------------------------------------------------
def play(self, name, vol=1.0, pitch_var=0):