forked from MikhailSK/PyGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
111 lines (93 loc) · 3.84 KB
/
main.py
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
from Board import *
from unit import *
board = Board(BOARD_W, BOARD_H, screen)
screen.fill((0, 0, 0))
# новая иконка
pygame.display.set_icon(load_image('icon.png'))
running = True
FPS = 20
par = 0
turn = 0
par_animation = 0
start_game = StartGame(all_sprites)
par_start_game = 0
while running:
par_animation += 1
if par_start_game == 0:
pygame.mixer.music.play(-1)
par_start_game = 1
all_sprites.draw(screen)
unit_sprites.draw(screen)
if par == 0 and turn > 0:
board.render()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN and turn >= 0:
if turn != 0:
new_board_pos = ((event.pos[0] - 10) // 30,
(event.pos[1] - 10) // 30)
if event.button == 1:
board.get_click(event.pos)
if board.turn != turn:
print(turn)
turn = board.turn
par = 1
board.render()
if board.end == 1:
turn = -3
if board.end == 2:
turn = -4
elif event.button == 3:
try:
map_units[new_board_pos].get_info()
except KeyError:
unit = None
if warrior_select_b.rect.collidepoint(event.pos):
unit = WarriorBlue((0, 0), screen)
elif warrior_select_r.rect.collidepoint(event.pos):
unit = WarriorRed((0, 0), screen)
elif archer_select_b.rect.collidepoint(event.pos):
unit = ArcherBlue((0, 0), screen)
elif archer_select_r.rect.collidepoint(event.pos):
unit = ArcherRed((0, 0), screen)
elif priest_select_b.rect.collidepoint(event.pos):
unit = PriestBlue((0, 0), screen)
elif priest_select_r.rect.collidepoint(event.pos):
unit = PriestRed((0, 0), screen)
elif miner_select_b.rect.collidepoint(event.pos):
unit = MinerBlue((0, 0), screen)
elif miner_select_r.rect.collidepoint(event.pos):
unit = MinerRed((0, 0), screen)
else:
print("empty cell")
if unit is not None:
unit.get_info()
else:
turn = 1
click.play()
screen.fill((0, 0, 0))
all_sprites.remove(start_game)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_n:
pygame.mixer.music.set_volume(0)
elif event.key == pygame.K_m:
pygame.mixer.music.set_volume(1)
elif event.key == pygame.K_b:
pygame.mixer.music.set_volume(
pygame.mixer.music.get_volume() - 0.1)
elif event.key == pygame.K_v:
pygame.mixer.music.set_volume(
pygame.mixer.music.get_volume() + 0.1)
if turn == -3:
end_screen = EndGameBlue(all_sprites)
if turn == -4:
end_screen = EndGameRed(all_sprites)
pygame.display.flip()
if par_animation == 15 and board.end == 0:
for i in map_units.keys():
map_units[i].render()
map_units[i].all_sprites.draw(screen)
pygame.display.flip()
par_animation = 0
clock.tick(FPS)