Fix: Wasseroberfläche proportional zur Terminalhöhe (rows//3)
Hardcodiertes wl=5 ließ bei kleinen Terminals (~10 Zeilen) nur 1-2 Zeilen Unterwasserraum. Wie im Perl-Original: wl=rows//3. - add_environment: y=wl+i statt y=i+5 - Alle Spawn-y für Fische/Haie/Taucher usw.: wl+4 als Minimum - Delfine: start_ys relativ zu wl - Enten: y=wl statt y=5 - Castle nur bei rows>=20 (passt sonst nicht ins Terminal)
This commit is contained in:
parent
0ca2bf109d
commit
860fb7b3dd
1 changed files with 19 additions and 15 deletions
|
|
@ -301,6 +301,9 @@ class Aquarium:
|
||||||
self.cols = cols
|
self.cols = cols
|
||||||
self.cfg = cfg or Config()
|
self.cfg = cfg or Config()
|
||||||
self.canvas = Canvas(rows, cols)
|
self.canvas = Canvas(rows, cols)
|
||||||
|
# wl = first row of the wave area, proportional like Perl's int($lines/3).
|
||||||
|
# wl+4 is the first fully-underwater row (4 wave rows below wl).
|
||||||
|
self.wl = max(3, rows // 3)
|
||||||
self.entities: List[Entity] = []
|
self.entities: List[Entity] = []
|
||||||
|
|
||||||
fns = [self.add_whale, self.add_monster, self.add_swan,
|
fns = [self.add_whale, self.add_monster, self.add_swan,
|
||||||
|
|
@ -324,13 +327,15 @@ class Aquarium:
|
||||||
def _setup(self):
|
def _setup(self):
|
||||||
self.entities.clear()
|
self.entities.clear()
|
||||||
self.add_environment()
|
self.add_environment()
|
||||||
self.add_castle()
|
if self.rows >= 20:
|
||||||
|
self.add_castle()
|
||||||
self.add_all_seaweed()
|
self.add_all_seaweed()
|
||||||
self.add_all_fish()
|
self.add_all_fish()
|
||||||
self.random_object(None)
|
self.random_object(None)
|
||||||
|
|
||||||
def resize(self, rows: int, cols: int):
|
def resize(self, rows: int, cols: int):
|
||||||
self.rows, self.cols = rows, cols
|
self.rows, self.cols = rows, cols
|
||||||
|
self.wl = max(3, rows // 3)
|
||||||
self.canvas.resize(rows, cols)
|
self.canvas.resize(rows, cols)
|
||||||
self._cs_state = 0
|
self._cs_state = 0
|
||||||
self._cs_portcullis = None
|
self._cs_portcullis = None
|
||||||
|
|
@ -368,7 +373,7 @@ class Aquarium:
|
||||||
self._add(Entity(
|
self._add(Entity(
|
||||||
frames=[[seg * repeat]],
|
frames=[[seg * repeat]],
|
||||||
masks=None,
|
masks=None,
|
||||||
x=0, y=i + 5,
|
x=0, y=self.wl + i,
|
||||||
cb_args=[0, 0, 0],
|
cb_args=[0, 0, 0],
|
||||||
default_color='c',
|
default_color='c',
|
||||||
die_offscreen=False,
|
die_offscreen=False,
|
||||||
|
|
@ -663,7 +668,7 @@ class Aquarium:
|
||||||
|
|
||||||
height = len(shape)
|
height = len(shape)
|
||||||
width = max(len(l) for l in shape)
|
width = max(len(l) for l in shape)
|
||||||
y = random.randint(9, max(10, self.rows - height))
|
y = random.randint(self.wl + 4, max(self.wl + 5, self.rows - height))
|
||||||
|
|
||||||
# Initial population (dead=None): start already on-screen so the
|
# Initial population (dead=None): start already on-screen so the
|
||||||
# aquarium is immediately populated. Respawned fish enter from edges.
|
# aquarium is immediately populated. Respawned fish enter from edges.
|
||||||
|
|
@ -770,7 +775,7 @@ class Aquarium:
|
||||||
going_right = random.random() < 0.5
|
going_right = random.random() < 0.5
|
||||||
speed = 2.0 * (1 if going_right else -1)
|
speed = 2.0 * (1 if going_right else -1)
|
||||||
x = -53 if going_right else self.cols - 2
|
x = -53 if going_right else self.cols - 2
|
||||||
y = random.randint(9, max(10, self.rows - 19))
|
y = random.randint(self.wl + 4, max(self.wl + 5, self.rows - 19))
|
||||||
|
|
||||||
self._add(Entity(
|
self._add(Entity(
|
||||||
frames=[shape_r if going_right else shape_l],
|
frames=[shape_r if going_right else shape_l],
|
||||||
|
|
@ -1061,7 +1066,7 @@ BBBB BBBBB
|
||||||
else:
|
else:
|
||||||
x = self.cols - 1; shape = shape_l; mask = _rand_color(mask_l_t)
|
x = self.cols - 1; shape = shape_l; mask = _rand_color(mask_l_t)
|
||||||
|
|
||||||
y = random.randint(9, max(10, self.rows - 15))
|
y = random.randint(self.wl + 4, max(self.wl + 5, self.rows - 15))
|
||||||
self._add(Entity(
|
self._add(Entity(
|
||||||
frames=[shape], masks=[mask],
|
frames=[shape], masks=[mask],
|
||||||
x=x, y=y,
|
x=x, y=y,
|
||||||
|
|
@ -1119,7 +1124,7 @@ ygcgwwwww ygcgwwwww ygcgwwwww
|
||||||
|
|
||||||
self._add(Entity(
|
self._add(Entity(
|
||||||
frames=shapes, masks=[mask] * 3,
|
frames=shapes, masks=[mask] * 3,
|
||||||
x=x, y=5,
|
x=x, y=self.wl,
|
||||||
cb_args=[speed, 0, 0, 0.25],
|
cb_args=[speed, 0, 0, 0.25],
|
||||||
default_color='W',
|
default_color='W',
|
||||||
die_offscreen=True,
|
die_offscreen=True,
|
||||||
|
|
@ -1176,12 +1181,11 @@ ygcgwwwww ygcgwwwww ygcgwwwww
|
||||||
base_x = -13 if going_right else self.cols - 2
|
base_x = -13 if going_right else self.cols - 2
|
||||||
|
|
||||||
# Three dolphins offset in their path cycle (offsets 0, 12, 24).
|
# Three dolphins offset in their path cycle (offsets 0, 12, 24).
|
||||||
# start_ys are the y positions at path offsets 0, 12, 24.
|
# Relative to wl so the arc crosses the surface at any terminal size.
|
||||||
# With amplitude ±7 and center y=10 the arc spans y=3 (above waves)
|
# Amplitude ±7: range [wl+5-7, wl+5] = [wl-2, wl+5]
|
||||||
# to y=10 (just below waterline), crossing the surface in both phases.
|
# → briefly above waves and ~2 rows underwater.
|
||||||
# Cumulative dy: offset 0→0, offset 12→-6, offset 24→-3
|
# Cumulative dy at offsets 0/12/24: 0/-6/-3
|
||||||
# so start_ys = [10, 10-6, 10-3] = [10, 4, 7]
|
start_ys = [self.wl + 5, self.wl - 1, self.wl + 2]
|
||||||
start_ys = [10, 4, 7]
|
|
||||||
colors = ['b', 'B', 'C']
|
colors = ['b', 'B', 'C']
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
is_lead = (i == 2)
|
is_lead = (i == 2)
|
||||||
|
|
@ -1304,7 +1308,7 @@ ygyyy
|
||||||
going_right = random.random() < 0.5
|
going_right = random.random() < 0.5
|
||||||
speed = random.uniform(0.3, 0.8) * (1 if going_right else -1)
|
speed = random.uniform(0.3, 0.8) * (1 if going_right else -1)
|
||||||
x = -5 if going_right else self.cols - 2
|
x = -5 if going_right else self.cols - 2
|
||||||
y = random.randint(9, max(10, self.rows - 10))
|
y = random.randint(self.wl + 4, max(self.wl + 5, self.rows - 10))
|
||||||
self._add(Entity(
|
self._add(Entity(
|
||||||
frames=[frame0, frame1], masks=[mask0, mask1],
|
frames=[frame0, frame1], masks=[mask0, mask1],
|
||||||
x=x, y=y,
|
x=x, y=y,
|
||||||
|
|
@ -1353,7 +1357,7 @@ mmmmmm
|
||||||
going_right = random.random() < 0.5
|
going_right = random.random() < 0.5
|
||||||
speed = random.uniform(0.5, 1.5) * (1 if going_right else -1)
|
speed = random.uniform(0.5, 1.5) * (1 if going_right else -1)
|
||||||
x = -8 if going_right else self.cols - 2
|
x = -8 if going_right else self.cols - 2
|
||||||
y = random.randint(9, max(10, self.rows - 8))
|
y = random.randint(self.wl + 4, max(self.wl + 5, self.rows - 8))
|
||||||
frames = [frame_r0, frame_r1] if going_right else [frame_l0, frame_l1]
|
frames = [frame_r0, frame_r1] if going_right else [frame_l0, frame_l1]
|
||||||
self._add(Entity(
|
self._add(Entity(
|
||||||
frames=frames, masks=[mask_r, mask_r],
|
frames=frames, masks=[mask_r, mask_r],
|
||||||
|
|
@ -1403,7 +1407,7 @@ yccw
|
||||||
x, frames, mask = -6, [diver_r0, diver_r1], mask_r
|
x, frames, mask = -6, [diver_r0, diver_r1], mask_r
|
||||||
else:
|
else:
|
||||||
x, frames, mask = self.cols - 2, [diver_l0, diver_l1], mask_l
|
x, frames, mask = self.cols - 2, [diver_l0, diver_l1], mask_l
|
||||||
y = random.randint(9, max(10, self.rows - 5))
|
y = random.randint(self.wl + 4, max(self.wl + 5, self.rows - 5))
|
||||||
|
|
||||||
def on_death(e, aq):
|
def on_death(e, aq):
|
||||||
aq.add_bubble(e)
|
aq.add_bubble(e)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue