-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMember2.py
More file actions
352 lines (240 loc) · 8.92 KB
/
Member2.py
File metadata and controls
352 lines (240 loc) · 8.92 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<<<<<<< HEAD
=======
"""
Bounce balls on the screen.
Spawn a new ball for each mouse-click.
If Python and Arcade are installed, this example can be run from the command line with:
python -m arcade.examples.bouncing_balls
"""
>>>>>>> 6190719e2bfcd481a7a9d7a6f599de110a47dfd0
import arcade
import random
###
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
SCREEN_TITLE = "Retro Ping Pong"
Count_1 = 0
Count_2 = 0
up_pressed = False
down_pressed = False
up_2pressed = False
down_2pressed = False
game_mode = 0
MOVEMENT_SPEED = 10
arcade_mode = random.randrange(1, 5)
<<<<<<< HEAD
=======
def Title_Screen():
texture = arcade.load_texture("Images/Title Screen.png")
if game_mode == 0:
arcade.draw_texture_rectangle(texture.width//2, texture.height//2, texture.width,texture.height, texture, 0)
>>>>>>> 6190719e2bfcd481a7a9d7a6f599de110a47dfd0
def fire_mode():
arcade.draw_rectangle_outline(640, 360, 500, 500, arcade.color.ORANGE, 10)
class Ball:
def __init__(self):
self.x = 0
self.y = 0
self.change_x = 0
self.change_y = 0
self.size = 0
self.color = None
class Rectangle1:
def __init__(self):
self.x = 0
self.y = 0
self.change_x = 0
self.change_y = 0
self.size = 0
self.color = None
class Rectangle2:
def __init__(self):
self.x = 0
self.y = 0
self.change_x = 0
self.change_y = 0
self.size = 0
self.color = None
def make_rectangle1():
rectangle1 = Rectangle1()
rectangle1.size = 14
rectangle1.x = 10
rectangle1.y = 350
rectangle1.change_y = 0
rectangle1.color = arcade.color.WHITE
return rectangle1
def make_rectangle2():
rectangle2 = Rectangle2()
rectangle2.size = 14
rectangle2.x = 1270
rectangle2.y = 350
rectangle2.change_y = 0
rectangle2.color = arcade.color.WHITE
return rectangle2
def make_ball():
global Count_1
global Count_2
ball = Ball()
# Size of the ball
ball.size = 14
# Starting position of the ball.
# Take into account the ball size so we don't spawn on the edge.
ball.x = 640
ball.y = 360
# Speed and direction of rectangle
if Count_1 >= Count_2:
ball.change_x = random.randrange(10,20)
ball.change_y = random.randrange(10,20)
if Count_2 > Count_1:
ball.change_x = random.randrange(-10,-20)
ball.change_y = random.randrange(-10,-20)
# Color
ball.color = arcade.color.WHITE
return ball
class MyGame(arcade.Window):
""" Main application class. """
<<<<<<< HEAD
def __init__(self):
=======
def __init__(self):
>>>>>>> 6190719e2bfcd481a7a9d7a6f599de110a47dfd0
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
self.ball_list = []
ball = make_ball()
self.ball_list.append(ball)
self.rectangle1_list = []
rectangle1 = make_rectangle1()
self.rectangle1_list.append(rectangle1)
self.rectangle2_list = []
rectangle2 = make_rectangle2()
self.rectangle2_list.append(rectangle2)
<<<<<<< HEAD
=======
>>>>>>> 6190719e2bfcd481a7a9d7a6f599de110a47dfd0
def on_draw(self):
"""
Render the screen.
"""
global Count_1, Count_2
# This command has to happen before we start drawing
arcade.start_render()
texture = arcade.load_texture("Images/background.png")
arcade.draw_texture_rectangle(texture.width//2, texture.height//2, texture.width,texture.height, texture, 0)
for ball in self.ball_list:
arcade.draw_circle_filled(ball.x, ball.y, ball.size, ball.color)
ball = make_ball()
for rectangle1 in self.rectangle1_list:
arcade.draw_rectangle_filled(rectangle1.x, rectangle1.y, rectangle1.size, 150, rectangle1.color)
rectangle1 = make_rectangle1()
for rectangle2 in self.rectangle2_list:
arcade.draw_rectangle_filled(rectangle2.x, rectangle2.y, rectangle2.size, 150, rectangle2.color)
rectangle2 = make_rectangle2()
#def make_score_board():
Player_1 = "{}" .format(Count_1)
Player_2 = "{}" .format(Count_2)
arcade.draw_text(Player_1, 590, 660, arcade.color.WHITE, 30)
arcade.draw_text(Player_2, 690, 660, arcade.color.WHITE, 30)
<<<<<<< HEAD
=======
>>>>>>> 6190719e2bfcd481a7a9d7a6f599de110a47dfd0
def on_update(self, delta_time):
""" Movement and game logic """
global Count_1, Count_2
for ball in self.ball_list:
ball.x += ball.change_x
ball.y += ball.change_y
if ball.y < ball.size:
ball.change_y *= -1
if ball.y > SCREEN_HEIGHT - ball.size:
ball.change_y *= -1
if ball.x >= 1300 and Count_1 <= 6:
ball.x = 640
ball.y = 360
Count_1 += 1
if ball.x <= -20 and Count_2 <= 6:
ball.x = 640
ball.y = 360
Count_2 += 1
for rectangle2 in self.rectangle2_list:
if ball.x > rectangle2.x-10 and ball.y < rectangle2.y + 75 and ball.y > rectangle2.y - 75:
<<<<<<< HEAD
=======
ball.change_x = random.randrange(-10,-20)
ball.change_y = random.randrange(-10,-20)
>>>>>>> 6190719e2bfcd481a7a9d7a6f599de110a47dfd0
ball.change_x *= -1
ball.change_y *= -1
for rectangle1 in self.rectangle1_list:
<<<<<<< HEAD
if ball.x < rectangle1.x+10 and ball.y < rectangle1.y + 75 and ball.y > rectangle1.y - 75:
ball.change_x *= -1
ball.change_y *= -1
=======
if ball.x < rectangle1.x+10 and ball.y < rectangle1.y + 75 and ball.y > rectangle1.y - 75:
ball.change_x = random.randrange(10,20)
ball.change_y = random.randrange(10,20)
ball.change_x *= -1
ball.change_y *= -1
>>>>>>> 6190719e2bfcd481a7a9d7a6f599de110a47dfd0
for rectangle2 in self.rectangle2_list:
if up_pressed == True:
rectangle2.y += 5
if down_pressed == True:
rectangle2.y -= 5
for rectangle1 in self.rectangle1_list:
if down_2pressed == True:
rectangle1.y -= 5
if up_2pressed == True:
rectangle1.y += 5
for ball in self.ball_list:
for rectangle1 in self.rectangle1_list:
if ball.size <= rectangle1.x and ball.y <= rectangle1.y + 75 and ball.y >= rectangle1.y - 75:
ball.change_y *= -1
for rectangle2 in self.rectangle2_list:
if ball.size >= rectangle2.x and ball.y <= rectangle2.y + 75 and ball.y >= rectangle2.y - 75:
ball.change_y*=-1
def on_key_press(self, key, modifiers):
"""Called whenever a key is pressed. """
global up_pressed, down_pressed, up_2pressed, down_2pressed
if key == arcade.key.UP:
up_pressed = True
elif key == arcade.key.DOWN:
down_pressed = True
elif key == arcade.key.W:
up_2pressed = True
elif key == arcade.key.S:
down_2pressed = True
def on_mouse_press(x, y, button, modifiers):
<<<<<<< HEAD
# Need to check all four limits of the button.
if (x > 496 and x < 810 and y > 306 and y < 371 ):
game_mode = 1
elif(x > 460 and x < 805 and y > 135 and y < 220 ):
game_mode = 2
=======
# Need to check all four limits of the button.
if game_mode == 0:
if (x > 496 and x < 810 and y > 306 and y < 371 ):
game_mode = 1
elif(x > 460 and x < 805 and y > 135 and y < 220 ):
game_mode = 2
>>>>>>> 6190719e2bfcd481a7a9d7a6f599de110a47dfd0
def on_key_release(self, key, modifiers):
"""Called when the user releases a key. """
global up_pressed, down_pressed, up_2pressed, down_2pressed
if key == arcade.key.UP:
up_pressed = False
elif key == arcade.key.DOWN:
down_pressed = False
elif key == arcade.key.W:
up_2pressed = False
elif key == arcade.key.S:
down_2pressed = False
def main():
MyGame()
arcade.run()
texture = arcade.load_texture("Images/background.png")
arcade.draw_texture_rectangle(texture.width//2, texture.height//2, texture.width,texture.height, texture, 0)
arcade.set_background_color()
if __name__ == "__main__":
main()