summaryrefslogtreecommitdiffstats
path: root/fish_types.py
diff options
context:
space:
mode:
authorRaymond Hogenson <rayhogenson@openmailbox.org>2016-10-18 10:12:25 -0400
committerRaymond Hogenson <rayhogenson@openmailbox.org>2016-10-18 10:12:25 -0400
commitdf81c9cd3e03870182c7ef1a2caf0aae8564b170 (patch)
treeb86282248d9a6311d9ed5f9e1526c00608ef1de7 /fish_types.py
parent1b0d46151bb6e0d98787fa1cdcc3b5b80b7d2478 (diff)
downloadbridge-df81c9cd3e03870182c7ef1a2caf0aae8564b170.tar.zst
Make fish come from the right
Diffstat (limited to 'fish_types.py')
-rw-r--r--fish_types.py41
1 files 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()