-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
126 lines (105 loc) · 2.47 KB
/
classes.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Shivam does this part.
from pygame.image import load
from pygame.transform import scale
class Player:
imgs = [
scale(load("player1.png"), (128, 128)),
scale(load("player2.png"), (128, 128)),
scale(load("player3.png"), (128, 128))
]
# Krishna does this part.
def __init__(self, x, y):
self.x = x
self.y = y
self.swinging = False
self.swing_cnt = None
self.img = self.imgs[0]
self.swing_time = 30
def update(self):
if self.swinging:
self.swing_cnt += 1
if self.swing_cnt == self.swing_time // 2:
self.img = self.imgs[2]
return "balldisp"
if self.swing_cnt == self.swing_time:
self.stop_swing()
return "endswing"
return None
def draw(self, win):
win.blit(self.img, (self.x, self.y))
def swing(self):
if not self.swinging:
self.swinging = True
self.swing_cnt = 1
self.img = self.imgs[1]
print("Swing!")
def stop_swing(self):
self.swinging = False
self.swing_cnt = 0
self.img = self.imgs[0]
# Shivam does this part.
class Bowler:
imgs = [
scale(load("bowler1.png"), (128, 128)),
scale(load("bowler2.png"), (128, 128))
]
def __init__(self, x, y):
self.x = x
self.y = y
self.bowling = False
self.bowl_cnt = None
self.img = self.imgs[0]
self.bowl_time = 30
def update(self):
if self.bowling:
self.bowl_cnt += 1
if self.bowl_cnt == self.bowl_time // 2:
self.img = self.imgs[1]
return "balldisp"
if self.bowl_cnt == self.bowl_time:
self.stop_bowl()
return "endswing"
def stop_bowl(self):
self.bowling = False
self.bowl_cnt = 0
self.img = self.imgs[0]
def bowl(self):
if not self.bowling:
self.bowling = True
self.bowl_cnt = 1
print("Bowl!")
def draw(self, win):
win.blit(self.img, (self.x, self.y))
class Ball:
imgs = [scale(load("ball1.png"), (12, 12)), scale(load("ball2.png"), (12, 12))]
def __init__(self, x, y):
self.o_x = x
self.x = x
self.o_y = y
self.y = y
self.img = self.imgs[0]
self.img_cnt = 0
self.img_margin = 5
self.move_cnt = 0
def start_move(self):
self.move_cnt = 1
def continue_move(self):
self.move_cnt += 1
self.move_ball(self.x - 1, self.y + 10)
if self.y > 600:
self.end_move()
return False
return True
def end_move(self):
self.move_cnt = 0
self.x = self.o_x
self.y = self.o_y
def move_ball(self, new_x, new_y):
self.x = new_x
self.y = new_y
self.img_cnt += 1
if self.img_cnt == 9:
self.img_cnt = 1
self.img = self.imgs[self.img_cnt // 5]
def draw(self, win):
win.blit(self.img, (self.x, self.y))