Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Simplifying random_speed() and correcting random_position(), also add…

…ing documentation.
  • Loading branch information...
commit 991811bfb4edc315cb86b4f904e22cd7a1e4528b 1 parent 4675c45
Al Sweigart authored August 07, 2012
11  square-shooter/square-shooter_makeover.py
@@ -109,11 +109,18 @@ def collides_with(self, other):
109 109
         distance = math.sqrt(a * a + b * b)
110 110
         return distance < (self.radius + other.radius)
111 111
 
  112
+
112 113
 def random_position():
113  
-    return (random.random() - 0.5) * 3 + 0.5;
  114
+    """Returns a random float value that will be near the edge of the map"""
  115
+    if random.randint(0, 1) == 0:
  116
+        return random.uniform(0.0, 0.25)
  117
+    else:
  118
+        return random.uniform(0.75, 1.0)
114 119
 
115 120
 def random_speed(magnitude):
116  
-    return (random.random() * magnitude * 2 - magnitude)
  121
+    """Returns a random float value between -magnitude and magnitude."""
  122
+    return random.uniform(-magnitude, magnitude)
  123
+
117 124
 
118 125
 def make_bubble(kind):
119 126
     if kind == "big":

0 notes on commit 991811b

Please sign in to comment.
Something went wrong with that request. Please try again.