-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpaddle.py
More file actions
32 lines (25 loc) · 841 Bytes
/
Copy pathpaddle.py
File metadata and controls
32 lines (25 loc) · 841 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
import pygame
import config as c
from game_object import GameObject
class Paddle(GameObject):
def __init__(self, x, y, w, h, color, offset):
GameObject.__init__(self, x, y, w, h)
self.color = color
self.offset = offset
self.moving_left = False
self.moving_right = False
def draw(self, surface):
pygame.draw.rect(surface, self.color, self.bounds)
def handle(self, key):
if key == pygame.K_LEFT:
self.moving_left = not self.moving_left
else:
self.moving_right = not self.moving_right
def update(self):
if self.moving_left:
dx = -(min(self.offset, self.left))
elif self.moving_right:
dx = min(self.offset, c.screen_width - self.right)
else:
return
self.move(dx, 0)