forked from xccds/Python_AI_Game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch03_05.py
More file actions
54 lines (39 loc) · 1.33 KB
/
Copy pathch03_05.py
File metadata and controls
54 lines (39 loc) · 1.33 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
import pygame
from pygame import K_ESCAPE
pygame.init()
WINDOW_WIDTH = 600
WINDOW_HEIGHT = 300
display_surface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption("Blitting Images!")
WHITE = (255, 255, 255)
GRAY = (127, 127, 127)
dragon_image = pygame.image.load("dragon_right.png")
dragon_rect = dragon_image.get_rect()
dragon_rect.center = (WINDOW_WIDTH//2, WINDOW_HEIGHT//2)
font = pygame.font.Font('WenQuan.ttf', 32)
text = font.render("飞龙在天", True, GRAY, WHITE)
text_rect = text.get_rect()
text_rect.center = (WINDOW_WIDTH//2, text_rect.height//2)
sound_1 = pygame.mixer.Sound('sound_1.wav')
speed = [2,2]
fpsClock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT or event.type == pygame.KEYUP:
running = False
dragon_rect.x += speed[0]
dragon_rect.y += speed[1]
if dragon_rect.left < 0 or dragon_rect.right > WINDOW_WIDTH:
speed[0] = -speed[0]
sound_1.play()
if dragon_rect.top < 0 or dragon_rect.bottom > WINDOW_HEIGHT:
speed[1] = -speed[1]
sound_1.play()
display_surface.fill(WHITE)
display_surface.blit(dragon_image, dragon_rect)
display_surface.blit(text, text_rect)
pygame.display.update()
fpsClock.tick(60)
#End the game
pygame.quit()