-
Notifications
You must be signed in to change notification settings - Fork 0
Collapse file tree
Files
Search this repository
/
Copy pathmain.py
More file actions
More file actions
Latest commit
151 lines (122 loc) · 4.8 KB
/
main.py
File metadata and controls
151 lines (122 loc) · 4.8 KB
You must be signed in to make or propose changes
More edit options
Edit and raw actions
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import time
import keyboard
import random
import curses
width_pad = 5
ai_diff = 0.7
speed = 1.5
bonus = 100 #10% basically each hit to get a bonus
def main(stdscr):
curses.curs_set(0)
stdscr.clear()
p2 = False
start = False
sc_p1 = 0
sc_p2 = 0
object = False
rand_y = rand_x = 0
p1_hit = False
p2_hit = False
width_pad_p1 = width_pad
width_pad_p2 = width_pad
sh, sw = stdscr.getmaxyx()
p1_y, p1_x = sh//2 - (width_pad//2), 0
p2_y, p2_x = sh//2 - (width_pad//2), sw-1
ball_y, ball_x = p1_y +1, p1_x + width_pad//2
ball_dy, ball_dx = random.random(), 1
while True:
time.sleep(1/15)
if keyboard.is_pressed("space") and not start:
ball_y, ball_x = p1_y +1, p1_x + width_pad//2
ball_dy, ball_dx = random.random(), 1
start = True
if start:
if keyboard.is_pressed("z") or keyboard.is_pressed("w"):
p1_y -= 1
if keyboard.is_pressed("s"):
p1_y += 1
if p2:
if keyboard.is_pressed("o"):
p2_y -= 1
if keyboard.is_pressed("L"):
p2_y += 1
elif random.random() ai_diff:
if ball_y p2_y + (width_pad//2):
p2_y -= 1
if ball_y >gt; p2_y +(width_pad//2):
p2_y += 1
if keyboard.is_pressed("b"):
break
if start:
bounce = 0
noise = [random.randint(1, 100) for _ in range(bonus)]
p1_y = max(0, min(p1_y, sh - width_pad_p1))
p2_y = max(0, min(p2_y, sh - width_pad_p2-1))
stdscr.clear()
ball_x += ball_dx
ball_y += ball_dy
if ball_y <=t;= 0 or ball_y >=t;= sh-1:
ball_dy *= -1
bounce +=1
if ball_x <=t;= p1_x + 1 and p1_y <=t;= ball_y <=t;= p1_y + width_pad_p1:
relative_intersect_y = (p1_y + (width_pad_p1 / 2)) - ball_y
normalized_intersect = relative_intersect_y / (width_pad_p1 / 2)
ball_dy = -normalized_intersect * speed
ball_dx = (speed**2 - ball_dy**2)**0.5
ball_dx = abs(ball_dx)
bounce +=1
p1_hit = True
p2_hit = False
if ball_x >=t;= p2_x - 1 and p2_y <=t;= ball_y <=t;= p2_y + width_pad:
relative_intersect_y = (p2_y + (width_pad / 2)) - ball_y
normalized_intersect = relative_intersect_y / (width_pad / 2)
ball_dy = -normalized_intersect * speed
ball_dx = (speed**2 - ball_dy**2)**0.5
ball_dx = -abs(ball_dx) #from ai :sob: i couldnt figure it out
bounce +=1
p1_hit = False
p2_hit = True
if ball_x 0:
sc_p2 +=1
start = False
elif int(ball_x) >=t;= sw-1:
sc_p1 += 1
start = False
if not object:
for i in noise:
if i == bounce:
rand_y = random.choice(list(range(0,sh)))
rand_x = random.choice(list(range(2,sw-2)))
object=True
if int(ball_y) == rand_y and int(ball_x) == rand_x:
rand_y = rand_x = 0
if p1_hit:
width_pad_p1 = width_pad + sw//4
elif p2_hit:
width_pad_p2 = width_pad + sw//4
object=False
stdscr.addch(rand_y,rand_x, "#")
stdscr.addch(int(ball_y), int(ball_x), "o")
stdscr.addstr(0,0, str(ball_dy))
for i in range(width_pad_p1):
stdscr.addch(p1_y + i, p1_x, "|")
for i in range(width_pad_p2):
stdscr.addch(p2_y + i, p2_x, "|")
else:
stdscr.clear()
rand_y = rand_x = 0
if keyboard.is_pressed("1"):
p2 = False
elif keyboard.is_pressed("2"):
p2 = True
stdscr.addstr((sh//2)-1, (sw//2)-3, "Pong !")
stdscr.addstr((sh//2), (sw//2)-len("Press 1 if ur single and 2 if you are with someone")//2, "Press 1 if ur single and 2 if you are with someone")
if p2:
stdscr.addstr((sh//2)+1, (sw//2)-(len("You are with somone !")//2), "You are with someone !")
else:
stdscr.addstr((sh//2)+1, (sw//2)-(len("You are single !")//2), "You are single !")
stdscr.addstr((sh//2)+2, (sw//2)-len("Press space to start")//2, "Press space to start")
stdscr.addstr(0, sw//2, f"P1 : {sc_p1}")
stdscr.addstr(sh-1, sw//2, f"P2 : {sc_p2}")
stdscr.refresh()
curses.wrapper(main)