-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaddle.py
More file actions
34 lines (26 loc) · 798 Bytes
/
paddle.py
File metadata and controls
34 lines (26 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pygame
BLACK = (0,0,0)
class Paddle(pygame.sprite.Sprite):
#Paddle Class
def __init__(self, color, width, height):
super().__init__()
#initialize image
self.image = pygame.Surface([width, height])
self.image.fill(BLACK)
self.image.set_colorkey(BLACK)
# Draw the rectangle
pygame.draw.rect(self.image, color, [0, 0, width, height])
#get rectangle
self.rect = self.image.get_rect()
def moveUp(self, pixels):
#move up
self.rect.y -= pixels
#Check if too far up
if self.rect.y < 0:
self.rect.y = 0
def moveDown(self, pixels):
#move down
self.rect.y += pixels
#Check if too far down
if self.rect.y > 400:
self.rect.y = 400