-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpmp.py
More file actions
98 lines (84 loc) · 2.88 KB
/
Copy pathpmp.py
File metadata and controls
98 lines (84 loc) · 2.88 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
import pygame
import random
# تعيين الألوان
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# تعيين الأبعاد
WIDTH = 600
HEIGHT = 400
BALL_SIZE = 20
CAR_SIZE = 40
GOAL_SIZE = 10
# تهيئة الشاشة
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Mini Rocket League")
clock = pygame.time.Clock()
# تعيين المواقع الابتدائية
player_car_x = WIDTH // 4
player_car_y = HEIGHT // 2
opponent_car_x = WIDTH * 3 // 4
opponent_car_y = HEIGHT // 2
ball_x = WIDTH // 2
ball_y = HEIGHT // 2
# تعيين سرعة اللاعب والكرة
player_speed = 5
ball_speed_x = random.choice([-3, 3])
ball_speed_y = random.choice([-3, 3])
# دورة اللعبة
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# التحكم بالسيارة الخاصة باللاعب
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
player_car_y -= player_speed
if keys[pygame.K_DOWN]:
player_car_y += player_speed
if keys[pygame.K_LEFT]:
player_car_x -= player_speed
if keys[pygame.K_RIGHT]:
player_car_x += player_speed
# تحديد حركة الكرة
ball_x += ball_speed_x
ball_y += ball_speed_y
# ارسم الشاشة
screen.fill(WHITE)
pygame.draw.circle(screen, BLACK, (ball_x, ball_y), BALL_SIZE)
pygame.draw.rect(screen, RED, (player_car_x, player_car_y, CAR_SIZE, CAR_SIZE))
pygame.draw.rect(screen, BLUE, (opponent_car_x, opponent_car_y, CAR_SIZE, CAR_SIZE))
pygame.draw.rect(screen, GREEN, (0, (HEIGHT - GOAL_SIZE) // 2, GOAL_SIZE, GOAL_SIZE))
pygame.draw.rect(screen, GREEN, (WIDTH - GOAL_SIZE, (HEIGHT - GOAL_SIZE) // 2, GOAL_SIZE, GOAL_SIZE))
# الاصطدام بالحواف
if ball_x <= 0 or ball_x >= WIDTH:
ball_speed_x *= -1
if ball_y <= 0 or ball_y >= HEIGHT:
ball_speed_y *= -1
# الاصطدام بالسيارات
if player_car_x < ball_x < player_car_x + CAR_SIZE and player_car_y < ball_y < player_car_y + CAR_SIZE:
ball_speed_x *= -1
ball_speed_y *= -1
if opponent_car_x < ball_x < opponent_car_x + CAR_SIZE and opponent_car_y < ball_y < opponent_car_y + CAR_SIZE:
ball_speed_x *= -1
ball_speed_y *= -1
# التحقق من التسجيل
if ball_x <= GOAL_SIZE:
print("Goal for Opponent!")
ball_x = WIDTH // 2
ball_y = HEIGHT // 2
ball_speed_x = random.choice([-3, 3])
ball_speed_y = random.choice([-3, 3])
elif ball_x >= WIDTH - GOAL_SIZE:
print("Goal for Player!")
ball_x = WIDTH // 2
ball_y = HEIGHT // 2
ball_speed_x = random.choice([-3, 3])
ball_speed_y = random.choice([-3, 3])
pygame.display.flip()
clock.tick(60)
pygame.quit()