Revert commit 6955baa
commited
commit
8870901bbe1f4b72baec3300b0cd1e4ab1cb6bd6
... | ... | @@ -1,87 +0,0 @@ |
1 | import pygame |
|
2 | import math |
|
3 | ||
4 | # Initialize the game |
|
5 | pygame.init() |
|
6 | screen = pygame.display.set_mode((800, 600)) |
|
7 | clock = pygame.time.Clock() |
|
8 | ||
9 | # Colors |
|
10 | WHITE = (255, 255, 255) |
|
11 | BLACK = (0, 0, 0) |
|
12 | RED = (255, 0, 0) |
|
13 | ||
14 | # Car class |
|
15 | class Car: |
|
16 | def __init__(self, x, y): |
|
17 | self.x = x |
|
18 | self.y = y |
|
19 | self.angle = 0 |
|
20 | self.speed = 0 |
|
21 | ||
22 | def update(self): |
|
23 | self.x += self.speed * math.cos(math.radians(self.angle)) |
|
24 | self.y -= self.speed * math.sin(math.radians(self.angle)) |
|
25 | ||
26 | def draw(self): |
|
27 | car_rect = pygame.Rect(0, 0, 40, 20) |
|
28 | rotated_car = pygame.transform.rotate(pygame.Surface((40, 20)), -self.angle) |
|
29 | rotated_car.fill(RED) |
|
30 | rect = rotated_car.get_rect(center=(self.x, self.y)) |
|
31 | screen.blit(rotated_car, rect.topleft) |
|
32 | ||
33 | # Loopty Doop class |
|
34 | class LooptyDoop: |
|
35 | def __init__(self, x, y, radius): |
|
36 | self.x = x |
|
37 | self.y = y |
|
38 | self.radius = radius |
|
39 | ||
40 | def draw(self): |
|
41 | pygame.draw.circle(screen, WHITE, (self.x, self.y), self.radius, 2) |
|
42 | ||
43 | # Initialize car and loopty doops |
|
44 | car = Car(400, 300) |
|
45 | loopty_doops = [ |
|
46 | LooptyDoop(200, 300, 100), |
|
47 | LooptyDoop(400, 300, 150), |
|
48 | LooptyDoop(600, 300, 100) |
|
49 | ] |
|
50 | ||
51 | # Game loop |
|
52 | running = True |
|
53 | while running: |
|
54 | screen.fill(BLACK) |
|
55 | ||
56 | # Event handling |
|
57 | for event in pygame.event.get(): |
|
58 | if event.type == pygame.QUIT: |
|
59 | running = False |
|
60 | ||
61 | # Movement handling |
|
62 | keys = pygame.key.get_pressed() |
|
63 | if keys[pygame.K_UP]: |
|
64 | car.speed = 5 |
|
65 | elif keys[pygame.K_DOWN]: |
|
66 | car.speed = -5 |
|
67 | else: |
|
68 | car.speed = 0 |
|
69 | ||
70 | if keys[pygame.K_LEFT]: |
|
71 | car.angle += 5 |
|
72 | if keys[pygame.K_RIGHT]: |
|
73 | car.angle -= 5 |
|
74 | ||
75 | # Update and draw car |
|
76 | car.update() |
|
77 | car.draw() |
|
78 | ||
79 | # Draw loopty doops |
|
80 | for loopty_doop in loopty_doops: |
|
81 | loopty_doop.draw() |
|
82 | ||
83 | # Update the display |
|
84 | pygame.display.flip() |
|
85 | clock.tick(60) |
|
86 | ||
87 | pygame.quit() |
|
... | ... | \ No newline at end of file |