-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaddle.py
More file actions
37 lines (27 loc) · 978 Bytes
/
Copy pathPaddle.py
File metadata and controls
37 lines (27 loc) · 978 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
35
import pygame
class Paddle:
def __init__(self, x, y, input_type):
super().__init__()
self.x = x
self.y = y
self.width = 20
self.height = 200
self.rect = pygame.rect.Rect((x, y), (self.width, self.height))
self.input_type = input_type
def handle_input(self, window_height):
keys = pygame.key.get_pressed()
up = pygame.K_UP
down = pygame.K_DOWN
if self.input_type == "WSAD":
up = pygame.K_w
down = pygame.K_s
if keys[up] and self.y - 63 >= 0:
self.y -= 5
if keys[down] and self.y <= window_height - self.height:
self.y += 5
def draw(self, window: pygame.Surface):
pygame.draw.rect(window, "White", self.rect)
def update(self, window: pygame.Surface):
self.draw(window)
self.rect.update((self.x, self.y), (self.width, self.height))
self.handle_input(window.get_height())