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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import random
import pygame
pygame.init()
window_size = [800, 600]
screen = pygame.display.set_mode(window_size)
screen.fill([255, 255, 255])
raw_airforce = pygame.image.load('./airforce.jpeg')
airforce = pygame.transform.scale(raw_airforce, (112, 112))
airforce_x = 0
airforce_y = 300
airforce_move_x = 0
airforce_move_y = 0
raw_ghost = pygame.image.load('./ghost.jpg')
ghost = pygame.transform.scale(raw_ghost, (120, 120))
ghost_x = 300
ghost_y = 300
head_font = pygame.font.SysFont(None, 60)
text_surface = head_font.render('airforce vs ghort', True, (0, 0, 0))
screen.blit(airforce, (airforce_x, airforce_y))
screen.blit(ghost, (ghost_x, ghost_y))
is_game_over = False
time_start = pygame.time.get_ticks()
point_font = pygame.font.SysFont(None, 30)
time_font = pygame.font.SysFont(None, 30)
points = 0
total_time = 30
while not is_game_over:
time_now = pygame.time.get_ticks()
during_time = (time_now - time_start) // 1000
if during_time >= 30:
print('over 30 secs\ngame over')
is_game_over = True
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_game_over = True
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
airforce_move_y = -10
airforce_y += airforce_move_y
elif keys[pygame.K_DOWN]:
airforce_move_y = +10
airforce_y += airforce_move_y
elif keys[pygame.K_RIGHT]:
airforce_move_x = +10
airforce_x += airforce_move_x
elif keys[pygame.K_LEFT]:
airforce_move_x = -10
airforce_x += airforce_move_x
ghost_rect = ghost.get_rect()
airforce_rect = airforce.get_rect()
ghost_width = ghost_rect.width
airforce_width = airforce_rect.width
ghost_height = ghost_rect.height
airforce_heigt = airforce_rect.height
if ghost_x + ghost_width > airforce_x and ghost_x < airforce_x + airforce_width and ghost_y + ghost_height > airforce_y and ghost_y < airforce_y + airforce_heigt:
points += 5
ghost_x = random.randint(0, 800 - ghost_width)
ghost_y = random.randint(0, 600 - ghost_height)
screen.blit(ghost, (ghost_x, ghost_y))
screen.fill([255, 255, 255])
remaining_time = total_time - during_time
point_font_surface = point_font.render('Points: {}'.format(points), True, (0, 0, 0))
screen.blit(point_font_surface, (10, 0))
time_font_surface = time_font.render('Time: {}'.format(remaining_time), True, (0, 0, 0))
screen.blit(time_font_surface, (10, 30))
screen.blit(airforce, (airforce_x, airforce_y))
screen.blit(ghost, (ghost_x, ghost_y))
pygame.display.flip()
pygame.quit()