Feb-27-2022, 02:41 PM
(This post was last modified: Feb-27-2022, 06:33 PM by deanhystad.)
EnhancedSprite has a rect that is assigned in the __init__() method.
def __init__(self, image, group = None, **kwargs): super().__init__(**kwargs) self.image = image self.rect = image.get_rect() # <- This is the rectangle for the image if group is not None: group.add(self)To clamp paddle movement so the entire paddle is always on screen.
def __init__(self,bottom): super().__init__(create_image(PADDLE_IMAGE, PADDLE_COLOR), self.group) self.bottom = bottom self.xmin = self.rect.width // 2 # set paddle x range. self.xmax = SCREEN_WIDTH - self.xmin def move(self, x): """Move to follow the cursor. Clamp to window bounds""" self.centerx = max(self.xmin, min(self.xmax, x))I started out doing this and didn't like how it played. I wish the paddle could go even further off the edge of the screen, but it can't since it follows the cursor.