From df81c9cd3e03870182c7ef1a2caf0aae8564b170 Mon Sep 17 00:00:00 2001 From: Raymond Hogenson Date: Tue, 18 Oct 2016 10:12:25 -0400 Subject: Make fish come from the right --- fish_types.py | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/fish_types.py b/fish_types.py index 1f50104..25c9eb8 100644 --- a/fish_types.py +++ b/fish_types.py @@ -16,16 +16,19 @@ class Fish(object): def __init__(self, x=None, y=None): """Create fish with default parameters.""" + self.from_left = random.random() > 0.5 if x is not None: self.x = x elif not hasattr(self, 'x'): - self.x = 0 + self.x = (0 + if self.from_left else constants.BRIDGE_WIDTH - self.width) if x is not None: self.y = y elif not hasattr(self, 'y'): self.y = 0.5 self.speed = C.Vector(0, 0) - self.tailAcceleration = C.Vector(self.tailAccelMag, 0) + self.tailAcceleration = (C.Vector(self.tailAccelMag, 0) + if self.from_left else C.Vector(-self.tailAccelMag, 0)) self.tailThresholdCurrent = self.tailThreshold self.tailMoving = False self.tailMoveCount = 0 @@ -80,15 +83,26 @@ class Fish(object): min_theta = -0.32 max_theta = 0.32 if self.y + self.height < 0: - min_theta = 0 + if self.from_left: + min_theta = 0 + else: + max_theta = 0 if self.y > 2: - max_theta = 0 + if self.from_left: + max_theta = 0 + else: + min_theta = 0 #theta = rand_in_range(min_theta, max_theta) theta = random.gauss( (max_theta+min_theta)/2, (max_theta - min_theta)/self.theta_scale ) - self.tailAcceleration = C.Vector(self.tailAccelMag, 0).rot2d(theta) + if self.from_left: + self.tailAcceleration = C.Vector(self.tailAccelMag, 0).rot2d(theta) + else: + self.tailAcceleration = C.Vector( + -self.tailAccelMag, 0 + ).rot2d(theta) def color_at(self, x, y): """May be overridden to provide multicolored fish.""" @@ -128,7 +142,14 @@ class Dolphin(Fish): return False if not self.direction_fixed: - self.tailAcceleration = self.tailAcceleration.rot2d(math.pi / 30) + if self.from_left: + self.tailAcceleration = self.tailAcceleration.rot2d( + math.pi / 30 + ) + else: + self.tailAcceleration = self.tailAcceleration.rot2d( + -math.pi / 30 + ) self.direction_fixed = True self.speed += self.drag * self.speed + self.gravity @@ -197,6 +218,11 @@ class Whale(Fish): white_y_min = 1.45 white_y_height = 0.5 + def __init__(self, *args, **kwargs): + super(Whale, self).__init__(*args, **kwargs) + if not self.from_left: + self.white_x_min = self.width - self.white_x_min + def color_at(self, x, y): """Mostly copied from compute_coverage. @@ -250,7 +276,8 @@ class Eel(Fish): return 1 - y_blend def update(self): - self.front_offset += abs(self.speed) + self.front_offset += (abs(self.speed) + if self.from_left else -abs(self.speed)) if self.front_offset > self.width: self.front_offset = 0 return super(Eel, self).update() -- cgit v1.3.1