-
Notifications
You must be signed in to change notification settings - Fork 0
/
paddle.py
46 lines (26 loc) · 872 Bytes
/
paddle.py
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
35
36
37
38
39
40
41
42
43
44
45
46
import pygame
BLACK = (0, 0, 0)
class Paddle(pygame.sprite.Sprite):
def __init__(self, color, width, height):
super().__init__()
self.image = pygame.Surface([width, height])
self.image.fill(BLACK)
self.image.set_colorkey(BLACK)
pygame.draw.rect(self.image, color, [0, 0, width, height])
self.rect = self.image.get_rect()
def moveUp(self, pixels):
self.rect.y -= pixels
if self.rect.y < 0:
self.rect.y = 0
def moveDown(self, pixels):
self.rect.y += pixels
if self.rect.y > 600:
self.rect.y = 600
def moveRight(self, pixels):
self.rect.x += pixels
if self.rect.x > 600:
self.rect.x = 600
def moveLeft(self, pixels):
self.rect.x -= pixels
if self.rect.x < 0:
self.rect.x = 0