- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimatio.py
More file actions
Latest commit
47 lines (38 loc) · 1.01 KB
/
Copy pathanimatio.py
File metadata and controls
47 lines (38 loc) · 1.01 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
importpygame, sys
frompygame.localsimport*
pygame.init()
FPS=30# frames per second setting
fpsClock=pygame.time.Clock()
# set up the window
DISPLAYSURF=pygame.display.set_mode((400, 300), 0, 32)
pygame.display.set_caption('Animation')
WHITE= (255, 255, 255)
catImg=pygame.image.load('cat.png')
catx=10
caty=10
direction='right'
whileTrue: # the main game loop
DISPLAYSURF.fill(WHITE)
ifdirection=='right':
catx+=5
ifcatx==280:
direction='down'
elifdirection=='down':
caty+=5
ifcaty==220:
direction='left'
elifdirection=='left':
catx-=5
ifcatx==10:
direction='up'
elifdirection=='up':
caty-=5
ifcaty==10:
direction='right'
DISPLAYSURF.blit(catImg, (catx, caty))
foreventinpygame.event.get():
ifevent.type==QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
fpsClock.tick(FPS)