From d3a4e5b0e664aea57c4cce59631785ff5b61eabf Mon Sep 17 00:00:00 2001 From: Robert Scheibe Date: Thu, 18 Jun 2020 11:37:11 +0200 Subject: initial commit --- pong/paddle.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 pong/paddle.py (limited to 'pong/paddle.py') diff --git a/pong/paddle.py b/pong/paddle.py new file mode 100644 index 0000000..25dbcbb --- /dev/null +++ b/pong/paddle.py @@ -0,0 +1,33 @@ +import pygame +BLACK = (0,0,0) + +class Paddle(pygame.sprite.Sprite): + #This class represents a car. It derives from the "Sprite" class in Pygame. + + def __init__(self, color, width, height): + # Call the parent class (Sprite) constructor + super().__init__() + + # Pass in the color of the car, and its x and y position, width and height. + # Set the background color and set it to be transparent + self.image = pygame.Surface([width, height]) + self.image.fill(BLACK) + self.image.set_colorkey(BLACK) + + # Draw the paddle (a rectangle!) + pygame.draw.rect(self.image, color, [0, 0, width, height]) + + # Fetch the rectangle object that has the dimensions of the image. + self.rect = self.image.get_rect() + + def moveUp(self, pixels): + self.rect.y -= pixels + #Check that you are not going too far (off the screen) + if self.rect.y < 0: + self.rect.y = 0 + + def moveDown(self, pixels): + self.rect.y += pixels + #Check that you are not going too far (off the screen) + if self.rect.y > 480-100: + self.rect.y = 480-100 -- cgit v1.2.3