-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCycleGame.py
More file actions
55 lines (44 loc) · 1.46 KB
/
CycleGame.py
File metadata and controls
55 lines (44 loc) · 1.46 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
import pygame
import math
# Initialize Pygame
pygame.init()
# Set up the display
screen = pygame.display.set_mode((1024, 600))
pygame.display.set_caption("cycling")
clock = pygame.time.Clock()
x = 0
speed = 5
# Set up colors
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLACK = (0,0,0)
def animate(x):
pygame.draw.circle(screen,RED,(100+x,500),50,0)
pygame.draw.circle(screen,RED,(300+x,500),50,0)
pygame.draw.line(screen,BLACK,(100+x,500),(200+x,500),5)
pygame.draw.line(screen,BLACK,(100+x,500),(150+x,400),5)
pygame.draw.line(screen,BLACK,(200+x,500),(250+x,400),5)
pygame.draw.line(screen,BLACK,(150+x,400),(250+x,400),5)
pygame.draw.line(screen,BLACK,(200+x,500),(140+x,380),5)
pygame.draw.line(screen,BLACK,(130+x,380),(150+x,380),5)
pygame.draw.line(screen,BLACK,(120+x,500),(160+x,500),5)
pygame.draw.line(screen,BLACK,(300+x,500),(230+x,350),5)
pygame.draw.line(screen,BLACK,(230+x,350),(250+x,330),5)
# Main game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Fill the screen with white
screen.fill(WHITE)
pygame.draw.line(screen,BLACK,(0,550),(1024,550),5)
animate(x)
x += speed
if x > 1024: # Reset position when it goes off-screen
x = -300
# Update the display
pygame.display.flip()
clock.tick(30)
# Quit Pygame
pygame.quit()