-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_or.py
205 lines (139 loc) · 3.79 KB
/
menu_or.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
from turtle import *
import random
import turtle
import time
from block_Omar import Block
from ball_Omar import Ball
import math
score=0
score_total=turtle.clone()
IS_GAME_OVER = False
def inst(event):
turtle.clear()
turtle.goto(250,-250)
turtle.write("""
A BRICK WALL APPEARS AT THE SCREEN
AND OUR MISSION IS TO SMASH IT-
ONE BREAK AT A TIME!
*use the mouse to move the platform
across the bottom screen
*across the bottom screen
each time the ball hits a break,
the brick disappears
and you score points
2. PLAY!!
PRESS ENTER TO QUIT
""",True, align="right", font=("Helvetica", 15,"bold italic"))
turtle.update()
def play(event):
turtle.clear()
tracer(0)
# IS_GAME_OVER = False
t=20
l=-290
SCREEN_WIDTH=turtle.getcanvas().winfo_width()/2
SCREEN_HEIGHT=turtle.getcanvas().winfo_height()/2
platform=Block(0,-SCREEN_HEIGHT+20,"black",0.8,7)
BLOCKS=[]
NUMBER_OF_BLOCKS_LINE=9
NUMBER_OF_BLOCKS_COLUMN=10
for i in range(NUMBER_OF_BLOCKS_COLUMN):
color=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
for g in range(NUMBER_OF_BLOCKS_LINE):
x=l
y=SCREEN_HEIGHT-t
new_block=Block(x,y,color,1,3)
BLOCKS.append(new_block)
l=l+70
t=t+25
l=-290
# turtle.pu()
# turtle.goto(1000,0)
# turtle.pd()
turtle.ht()
MY_BALL=Ball(0,0,3,3,10,"turquoise")
MY_BALL.goto(0,-SCREEN_HEIGHT+50)
def move_all_balls():
global IS_GAME_OVER
IS_GAME_OVER = MY_BALL.move(SCREEN_WIDTH,SCREEN_HEIGHT)
print(IS_GAME_OVER)
def collision(ball_a,block_a):
if(
ball_a.top() >= block_a.bottom() and
ball_a.right() >= block_a.left() and
ball_a.bottom() <= block_a.top() and
ball_a.left() <= block_a.right()
):
return True
else:
return False
def movearound(event):
platform.goto(event.x-SCREEN_WIDTH,-SCREEN_HEIGHT+20)
turtle.getcanvas().bind("<Motion>",movearound)
turtle.getscreen().listen()
def ball_plat():
if collision(platform,MY_BALL)==True:
MY_BALL.dy=-(MY_BALL.dy)
def check_myball_collision():
global score , score_total
for block in BLOCKS:
if collision(MY_BALL,block) == True:
block.ht()
BLOCKS.remove(block)
if(MY_BALL.ycor() < block.bottom() or MY_BALL.ycor() > block.top()):
MY_BALL.dy = -MY_BALL.dy
else:
MY_BALL.dx = -MY_BALL.dx
# if MY_BALL.top() >= block.bottom() :
# self.dy = -self.dy
# elif MY_BALL.right() >= block.left():
# self.dx = -self.dx
# elif MY_BALL.bottom() <= block.top():
# self.dy = -self.dy
# elif MY_BALL.left() <= block.right():
# self.dx = -self.dx
if score == len(BLOCKS):
print("YOU WIN")
score_total.pu()
score_total.goto(0,-250)
score_total.clear()
score_total.write("SCORE: "+str(score),align="center",font=("Arial",20,"normal"))
score_total.goto(0,0)
scoreb_total.write("YOU WIN"+str(score),align="center",font=("Arial",80,"normal"))
time.sleep(0.9)
turtle.bye()
else:
score+=1
score_total.pu()
score_total.goto(0,-250)
score_total.clear()
score_total.write("SCORE: "+str(score),align="center",font=("Arial",20,"normal"))
# def
while IS_GAME_OVER != True:
# print(IS_GAME_OVER)
move_all_balls()
check_myball_collision()
ball_plat()
turtle.update()
print("yaay")
turtle.goto(-40,0)
turtle.write("GAME OVER",True,align="center",font=("Arial",25,"normal"))
turtle.update()
ans = True
turtle.ht()
turtle.tracer(0)
turtle.penup()
turtle.goto (-100,-100)
turtle.write("""
1. INSTRUCTIONS
2. PLAY!!
PRESS ENTER TO QUIT
""",True, align="center", font=("Helvetica", 24, "bold italic"))
def bye(event):
turtle.bye()
for i in range (10000):
turtle.getcanvas().bind("<Return>",bye)
turtle.getcanvas().bind("2",play)
turtle.getcanvas().bind("1",inst)
turtle.listen()
turtle.mainloop()