-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
65 lines (57 loc) · 1.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
# -*- encoding: utf-8 -*-
'''Main module for the application.'''
# pylint: disable=invalid-name, wrong-import-position
# Hide pygame's support prompt.
from os import environ
environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
import sys
import pygame
from pygame.locals import KEYDOWN, QUIT, K_q, K_ESCAPE, MOUSEBUTTONDOWN # pylint: disable=no-name-in-module
from manager import Manager, TreeManager
from sounds import Sounds
# Initialize game
pygame.init() # pylint: disable=no-member
pygame.mixer.init()
pygame.display.set_caption('开心消消乐')
pygame.mouse.set_visible(False)
tree = TreeManager()
m = Manager(0, 0)
sound_sign = 0
world_bgm = pygame.mixer.Sound(Sounds.WORLD_BGM.value)
game_bgm = pygame.mixer.Sound(Sounds.GAME_BGM.value)
# This improves the performance of the game
get_events, update_window = pygame.event.get, pygame.display.flip
while True:
if m.level == 0:
if sound_sign == 0:
game_bgm.stop()
world_bgm.play(-1)
sound_sign = 1
else:
if sound_sign == 1:
world_bgm.stop()
game_bgm.play(-1)
sound_sign = 0
if m.level == 0:
tree.draw_tree(m.energy_num, m.money)
else:
m.set_level_mode(m.level)
sprite_group = m.draw()
if m.type == 0:
m.eliminate_animals()
m.death_map()
m.swap(sprite_group)
m.judge_level()
for event in get_events():
if event.type == KEYDOWN:
if event.key in (K_q, K_ESCAPE):
sys.exit()
elif event.type == QUIT:
sys.exit()
elif event.type == MOUSEBUTTONDOWN:
mousex, mousey = event.pos
if m.level == 0:
tree.mouse_select(m, mousex, mousey, m.level, m.energy_num, m.money)
m.mouse_select(mousex, mousey)
m.mouse_image()
update_window()