Commits

Don Clark committed 83da5b1 Merge

Merged Issue_six into master. Issue #6 fixed.

Comments (0)

Files changed (3)

             #distance_c = self.play_area.width - self._rect.left
        
         print 'distance c', distance_c
-        
+        print 'position', self.rect
+
         down = False    
         if self.velocity[1] > 0: 
             down = True
                 self.rect.move_ip(self.velocity)
                 self.surface.blit(original_background, (0, 0))
                 return
-        
+
+        #6 Attempt to fix #6 where we have zombie balls with the next two elifs
+
+        if self.rect.left > self.surface.get_width() + 40:  # #6 should not happen
+            self.rect.top = (self.surface.get_height()/2)
+            self.rect.left = (self.surface.get_width()/2)
+            #set the new velocity to a random between initial and max
+            self.velocity[0] = random.randint(self._initial_velocity[0], MAX_HORIZONTAL_VELOCITY)
+            self.velocity[1] = -1 * abs(random.randint(self._initial_velocity[1], MAX_VERTICAL_VELOCITY))
+            self.velocity[0] *= -1.0  # change direction
+            self.need_updated_intercept_position = True
+
+        elif self.rect.left - self.rect.width < -40:  # #6 should not happen right edge more than 40 off0
+            self.rect.top = (self.surface.get_height()/2)
+            self.rect.left = (self.surface.get_width()/2)
+            #set the new velocity to a random between initial and max
+            self.velocity[0] = random.randint(self._initial_velocity[0], MAX_HORIZONTAL_VELOCITY)
+            self.velocity[1] = -1 * abs(random.randint(self._initial_velocity[1], MAX_VERTICAL_VELOCITY))
+            self.velocity[0] *= -1.0  # change direction
+            self.need_updated_intercept_position = True
+
         # check for top and bottom bounce
         if t_position.top < 0 + self.top_bottom_offset:	    
             self.velocity[1] *= -1.0
         elif t_position.bottom > self.surface.get_height() - self.top_bottom_offset:
             self.velocity[1] *= -1.0
             self.need_updated_intercept_position = True
-        
+
+        # What happens if we're off screen here?
+
         #Check to see if we score
         elif t_position.right > self.surface.get_width():   # score
             #increase score for left player
             self.rect.left = (self.surface.get_width()/2)
             #set the new velocity to a random between initial and max
             self.velocity[0] = random.randint(self._initial_velocity[0], MAX_HORIZONTAL_VELOCITY)
-            self.velocity[1] = random.randint(self._initial_velocity[1], MAX_VERTICAL_VELOCITY)
+            self.velocity[1] = -1 * abs(random.randint(self._initial_velocity[1], MAX_VERTICAL_VELOCITY))
             self.velocity[0] *= -1.0  # change direction
             self.need_updated_intercept_position = True
             self.point_scored('left')
             self.rect.left = (self.surface.get_width()/2)   
             #set the new velocity to a random between initial and max
             self.velocity[0] = random.randint(self._initial_velocity[0], MAX_HORIZONTAL_VELOCITY)
-            self.velocity[1] = random.randint(self._initial_velocity[1], MAX_VERTICAL_VELOCITY)
+            self.velocity[1] = -1 * abs(random.randint(self._initial_velocity[1], MAX_VERTICAL_VELOCITY))
             #self.velocity[0] *=	-1  #change direction
             #print 'right player score - ball exited at: ' + str(t_position.top)
             self.point_scored('right')

pypong-clock/paddle.py

         t_position = pygame.Rect((self._rect.left, self._rect.top + self.velocity, self._rect.width, self._rect.height))
 
         #only stop moving if we will move above the top or bottom edge and tracking beneath or above it
-        if t_position.top <= self.play_area.top and \
-                                self.track_to_position - self._rect.height / 2  < self.play_area.top:
+        # for #6 changed boundary check to greater than rather than greater than or equal this allows paddle
+        # to travel further up.
+        if t_position.top < self.play_area.top and \
+                                self.track_to_position - self._rect.height / 2 < self.play_area.top:
             turn_velocity = self.play_area.top - self._rect.top  # move next to border
             at_boundary = True
 
-        if t_position.bottom >= self.play_area.top + self.play_area.height \
+        if t_position.bottom > self.play_area.top + self.play_area.height \
             and self.track_to_position + self._rect.height / 2 > \
                                 self.play_area.top + self.play_area.height:
             turn_velocity = self.play_area.top + self.play_area.height - self._rect.bottom

pypong-clock/pypong-clock.py

 FIELD_EDGE_OFFSET = 8		# Offset between the display surface edge and the edging
 CAN_RESET_HOUR = True	    # On the hour we reset the score to 00, 00
 
-SCREEN_MODE = pygame.FULLSCREEN  # RESIZABLE as option
+SCREEN_MODE = pygame.RESIZABLE  # RESIZABLE as option
 
 #Check argv for anything interesting.
 for arg in sys.argv:
     If different it forces a miss to increase the score"""
     global CAN_RESET_HOUR
     now = datetime.datetime.now()
+    print "Time ", now
+    print "Hour ", now.strftime("%I")
+    print "Minute ", now.minute
+
+    #now = time.localtime()
     hour = now.strftime("%I")
 
+    # Working on Issue # 6
+    if left_score.score > int(hour):
+        right_score.reset_score()
+        left_score.reset_score()
+        CAN_RESET_HOUR = False
+        return
+
     if left_score.score < int(hour):
         right_paddle.allow_score()
         return