-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.py
More file actions
93 lines (70 loc) · 2.84 KB
/
classes.py
File metadata and controls
93 lines (70 loc) · 2.84 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pygame
import numpy
class Player():
def __init__(self, number, x, y, width, height, color):
self.number = number
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.rect = (self.x, self.y, width, height)
self.vel = 5
self.ready = False
def draw(self, win):
pygame.draw.rect(win, self.color, self.rect)
def move(self):
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
self.y -= self.vel
if keys[pygame.K_DOWN]:
self.y += self.vel
self.update()
def update(self):
self.rect = (self.x, self.y, self.width, self.height)
def border_guard(self):
# prevent player from going off the screen
if self.y < 0:
self.y = 0
elif self.y > 400 - self.height:
self.y = 400 - self.height
class Ball():
def __init__(self, x, y, width, height, color):
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.rect = (self.x, self.y, width, height)
self.xvel = 3 # numpy.random.randint(3,5)
self.yvel = numpy.random.randint(-3, 3)
self.yvelmax = 3
def update(self):
self.x += self.xvel
self.y += self.yvel
self.rect = (self.x, self.y, self.width, self.height)
class Settings:
def __init__(self, p1size, p2size, p1vel, p2vel, ballxvel, ballyvel):
self.p1size = p1size
self.p2size = p2size
self.p1vel = p1vel
self.p2vel = p2vel
self.ballxvel = ballxvel
self.ballyvel = ballyvel
# draw text for each setting
def draw(self, win, display_width, color, settings_btns):
font = pygame.font.SysFont("comicsans", 40)
text = font.render("P1 size: " + str(round(self.p1size / 10)), 1, color)
win.blit(text, (round(display_width / 2) - round(text.get_width() / 2), 25))
text = font.render("P2 size: " + str(round(self.p2size / 10)), 1, color)
win.blit(text, (round(display_width / 2) - round(text.get_width() / 2), 75))
text = font.render("P1 speed: " + str(self.p1vel), 1, color)
win.blit(text, (round(display_width / 2) - round(text.get_width() / 2), 125))
text = font.render("P2 speed: " + str(self.p2vel), 1, color)
win.blit(text, (round(display_width / 2) - round(text.get_width() / 2), 175))
text = font.render("Ball horizontal speed: " + str(self.ballxvel), 1, color)
win.blit(text, (round(display_width / 2) - round(text.get_width() / 2), 225))
text = font.render("Ball vertical speed: " + str(self.ballyvel), 1, color)
win.blit(text, (round(display_width / 2) - round(text.get_width() / 2), 275))
for btn in settings_btns:
btn.draw(win)