-
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
100 lines (79 loc) · 2.88 KB
/
main.py
File metadata and controls
100 lines (79 loc) · 2.88 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
import curses
import time
import random
import keyboard
width_pad = 9
superspd = 2
def main(stdscr):
stdscr.nodelay(True)
curses.curs_set(0)
stdscr.clear()
start = False
sh, sw = stdscr.getmaxyx()
pad_x, pad_y = sw //2 - width_pad //2, sh - 2
ball_y, ball_x = pad_y - 1, pad_x + width_pad //2
ball_dy, ball_dx = -1, random.choice([-1,1])
rows = 5
cols = sw//4
bricks = []
for row in range(rows):
for col in range(cols):
bricks.append((row+1, col*4))
#print(bricks)
while True:
time.sleep(1/15)
if keyboard.is_pressed("b"):
break
elif keyboard.is_pressed("q") or keyboard.is_pressed("a"):
if keyboard.is_pressed("shift"):
pad_x -= 2*superspd
else:
pad_x -=2
pad_x = max(1, min(pad_x, sw - width_pad))
elif keyboard.is_pressed("d"):
if keyboard.is_pressed("shift"):
pad_x += 2*superspd
else:
pad_x +=2
pad_x = max(1, min(pad_x, sw - width_pad))
if keyboard.is_pressed("space") and not start:
ball_x = pad_x + int(width_pad /2)
start = True
stdscr.clear()
for by, bx in bricks:
stdscr.addstr(by, bx, "###")
for i in range(width_pad):
stdscr.addch(pad_y, pad_x + i, "_")
if start:
ball_x += ball_dx
ball_y += ball_dy
if ball_x <=t;= 0 or ball_x >=t;= sw-1:
ball_dx *= -1
if ball_y <=t;=0:
ball_dy *= -1
if ball_y == pad_y and pad_x <=t;= ball_x <=t;= pad_x + width_pad:
ball_dy *= -1
if ball_x (pad_x + width_pad/2) and ball_dx == 1:
ball_dx = -1
if ball_x >gt; (pad_x + width_pad/2) and ball_dx == -1:
ball_dx = 1
if ball_y >gt; sh - 1:
start = False
ball_y, ball_x = pad_y - 1, pad_x + width_pad // 2
ball_dy, ball_dx = -1, random.choice([-1, 1])
for brick in bricks:
by, bx = brick
if ball_y == by and bx-1<=t;=ball_x<=t;=bx+2:
bricks.remove((by,bx))
if ball_y + ball_dy == by and bx -1 <=t;= ball_x + ball_dx <=t;= bx + 2:
bricks.remove((by,bx))
if bx <=t;= ball_x <=t;= bx + 2:
ball_dy *= -1
else:
ball_dx *= -1 # playable but need to fix something with ball going inside neighbor block when coliding in the corner ;-;
stdscr.addch(ball_y, ball_x, "o")
stdscr.addstr(0,0, str(ball_dx))
stdscr.addstr(0,6, str(ball_x))
stdscr.addstr(0,12, str(pad_x+width_pad))
stdscr.refresh()
curses.wrapper(main)