-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.py
More file actions
63 lines (54 loc) · 1.31 KB
/
ball.py
File metadata and controls
63 lines (54 loc) · 1.31 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
import time
class Ball:
def __init__ (self, x, y, v_x, v_y):
super().__init__()
self.x = x
self.y = y
self.v_x = v_x
self.v_y = v_y
self.attached = False
self.spawn = 0
def update_position(self):
self.x += self.v_x
self.y += self.v_y
if(self.x >= 70):
self.x -= self.v_x
self.v_x *= -1
if (self.x < 0):
self.x -= self.v_x
self.v_x *= -1
if (self.y < 0):
self.y -= self.v_y
self.v_y *= -1
if (self.y >= 25):
self.y -= self.v_y
return "OVER"
def move(self, board, paddle_mid, paddle_vel):
print(self.y, self.x)
# time.sleep(0.3)
board[self.y][self.x] = "."
if (self.update_position() != "OVER" ):
if (board[self.y][self.x] == "_" and self.attached==False):
return self.paddle_bounce(board)
# if (board[self.y][self.x] == "_" and self.attached==True):
# return self.move_with_paddle(board, paddle_mid, paddle_vel)
else:
board[self.y][self.x] = "0"
return board
else:
return "OVER"
def paddle_bounce(self,board):
self.x -= self.v_x
self.y -= self.v_y
self.v_y *= -1
board[self.y][self.x] = "."
return board
def move_with_paddle(self, board, paddle_mid, paddle_vel):
self.y = 22
if (self.y > 0):
self.v_y *= -1
print(self.v_y)
board[self.y][self.x] = "."
self.x = paddle_mid
board[self.y][self.x] = "0"
return board